Exemple #1
0
        // Update is called once per frame
        public IEnumerator LoadMap(DataMap map)
        {
            yield return(GameMgmt.Get().load.ShowSubMessage($"Loading Map data"));

            //read data
            GameMapData gmap = GameMgmt.Get().data.map;
            IniData     data = map.Config();

            //add level
            foreach (SectionData section in data.Sections)
            {
                GameMapDataLevel n = new GameMapDataLevel();
                n.name = section.SectionName;
                yield return(GameMgmt.Get().load.ShowSubMessage($"Reading {n.name} map data"));

                if (data[section.SectionName].ContainsKey("standard"))
                {
                    gmap.standard = gmap.levels.Count();
                }

                //add layer
                int m = Int32.Parse(data[section.SectionName]["layer"]);
                for (int i = 0; i < m; i++)
                {
                    n.AddLayer(map.Layer(data[section.SectionName]["format"], i));
                    yield return(GameMgmt.Get().load.ShowSubMessage($"Reading {n.name} map data {i}/{m}"));
                }
                gmap.levels.Add(n);
            }

            //set size
            gmap.width  = gmap.levels.First().Width();
            gmap.height = gmap.levels.First().Height();

            Debug.Log($"Load Map {map.Name()} ({gmap.width}/{gmap.height})");

            yield return(CreateLayers());
        }
Exemple #2
0
        public IEnumerator CreateMap()
        {
            //can load?
            if (GameMgmt.Get().data.map.id == null)
            {
                //TODO show error
                yield return(GameMgmt.Get().load.ShowSubMessage($"Map is missing for creation. Please restart 9 Nations"));

                yield break;
            }
            //load Map
            yield return(GameMgmt.Get().load.ShowSubMessage($"Create Map data"));

            //read data
            DataMap     map  = LSys.tem.maps[GameMgmt.Get().data.map.id];
            GameMapData gmap = GameMgmt.Get().data.map;
            IniData     data = map.Config();

            //set size
            gmap.width  = map.width;
            gmap.height = map.height;

            //add level
            foreach (SectionData section in data.Sections)
            {
                GameMapDataLevel n = new GameMapDataLevel();
                n.Init(gmap.levels.Count, section.SectionName);
                gmap.levels.Add(n);
                yield return(GameMgmt.Get().load.ShowSubMessage($"Reading {n.name} map data"));

                if (data[section.SectionName].ContainsKey("generate"))
                {
                    n.generate = data[section.SectionName]["generate"];
                    continue;
                }

                if (data[section.SectionName].ContainsKey("standard"))
                {
                    gmap.standard = gmap.levels.Count() - 1;
                }

                //add layer
                int m = Int32.Parse(data[section.SectionName]["layer"]);
                for (int i = 0; i < m; i++)
                {
                    yield return(GameMgmt.Get().load.ShowSubMessage($"Reading {n.name} map data {i}/{m}"));

                    n.AddLayer(map.Layer(data[section.SectionName]["format"], i));
                }
            }

            //check generate
            foreach (GameMapDataLevel gmdl in gmap.levels)
            {
                yield return(GameMgmt.Get().load.ShowSubMessage($"Finishing layer {gmdl.name}"));

                gmdl.FinishBuild();
            }

            Debug.Log($"Load Map {map.Name()} ({gmap.levels.Count}:{gmap.width}/{gmap.height})");

            yield return(CreateLayers());
        }