Esempio n. 1
0
        public static string LastLoadedFile = null;         // null == 未読み込み

        public static Map Load(string file)
        {
            LastLoadedFile = file;

            string[] lines = FileTools.TextToLines(Encoding.UTF8.GetString(DDResource.Load(file)));
            int      c     = 0;

            int w = int.Parse(lines[c++]);
            int h = int.Parse(lines[c++]);

            Map map = new Map(w, h);

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    if (lines.Length <= c)
                    {
                        goto endLoad;
                    }

                    MapCell cell   = map.GetCell(x, y);
                    var     tokens = new BluffList <string>(lines[c++].Split('\t')).FreeRange("");                // 項目が増えても良いように -> FreeRange("")
                    int     d      = 0;

                    cell.Kind           = (MapCell.Kind_e) int.Parse(tokens[d++]);
                    cell.SurfacePicture = MapTileManager.GetTile(tokens[d++]);
                    cell.TilePicture    = MapTileManager.GetTile(tokens[d++]);

                    // 新しい項目をここへ追加...
                }
            }
            while (c < lines.Length)
            {
                // memo: Save()時にプロパティ部分も上書きされるので注意してね。

                var tokens = lines[c++].Split("=".ToArray(), 2);

                string name  = tokens[0];
                string value = tokens[1];

                map.AddProperty(name, value);
            }
endLoad:
            return(map);
        }
Esempio n. 2
0
        public static Map Load(string file)
        {
            file = Path.Combine(@"Etoile\G4Dungeon\Map", file);

            string[] lines = FileTools.TextToLines(StringTools.ENCODING_SJIS.GetString(DDResource.Load(file)));
            int      c     = 0;

            string[] mapLines;

            {
                List <string> dest = new List <string>();

                while (c < lines.Length)
                {
                    string line = lines[c++];

                    if (line == "")
                    {
                        break;
                    }

                    dest.Add(line);
                }
                mapLines = dest.ToArray();
            }

            Dictionary <string, string> mapScripts = DictionaryTools.Create <string>();

            while (c < lines.Length)
            {
                string line = lines[c++];

                if (line.StartsWith(";"))                 // ? コメント
                {
                    continue;
                }

                if (line == "")
                {
                    break;
                }

                var tokens = line.Split("=".ToArray(), 2);

                string name  = tokens[0].Trim();
                string value = tokens[1].Trim();

                if (Regex.IsMatch(name, @"^[0-9A-Za-z]{2}(:[2468])?$") == false)
                {
                    throw new DDError();
                }

                if (value == "")
                {
                    throw new DDError();
                }

                mapScripts.Add(name, value);
            }

            Map map = LoadMap(mapLines, mapScripts);

            while (c < lines.Length)
            {
                string line = lines[c++];

                if (line.StartsWith(";"))                 // ? コメント
                {
                    continue;
                }

                var tokens = line.Split("=".ToArray(), 2);

                string name  = tokens[0].Trim();
                string value = tokens[1].Trim();

                if (name == "")
                {
                    throw new DDError();
                }
                if (value == "")
                {
                    throw new DDError();
                }

                map.AddProperty(name, value);
            }
            return(map);
        }