Beispiel #1
0
        private static string[] ReadScenarioLines(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new DDError();
            }

            byte[] fileData;

            {
                const string DEVENV_SCENARIO_DIR    = "シナリオデータ";
                const string DEVENV_SCENARIO_SUFFIX = ".txt";

                if (Directory.Exists(DEVENV_SCENARIO_DIR))
                {
                    string file = Path.Combine(DEVENV_SCENARIO_DIR, name + DEVENV_SCENARIO_SUFFIX);

                    fileData = File.ReadAllBytes(file);
                }
                else
                {
                    string file = SCENARIO_FILE_PREFIX + name + SCENARIO_FILE_SUFFIX;

                    fileData = DDResource.Load(file);
                }
            }

            string text = SCommon.ToJString(fileData, true, true, true, true);

            text = text.Replace('\t', ' ');             // タブスペースと空白 -> 空白に統一

            string[] lines = SCommon.TextToLines(text);
            return(lines);
        }
Beispiel #2
0
        public static void INIT()
        {
            if (File.Exists(DDConsts.ResourceFile))             // ? 外部リリース
            {
                ReleaseMode = true;
            }
            else if (Directory.Exists(DDConsts.ResourceDir_InternalRelease))             // ? 内部リリース
            {
                ResourceDir = DDConsts.ResourceDir_InternalRelease;
            }
            else             // ? 開発環境
            {
                ResourceDir = DDConsts.ResourceDir_DevEnv;
            }

            if (ReleaseMode)
            {
                List <ResInfo> resInfos = new List <ResInfo>();

                using (FileStream reader = new FileStream(DDConsts.ResourceFile, FileMode.Open, FileAccess.Read))
                {
                    while (reader.Position < reader.Length)
                    {
                        int size = SCommon.ToInt(SCommon.Read(reader, 4));

                        if (size < 0)
                        {
                            throw new DDError();
                        }

                        resInfos.Add(new ResInfo()
                        {
                            ResFile = DDConsts.ResourceFile,
                            Offset  = reader.Position,
                            Size    = size,
                        });

                        reader.Seek((long)size, SeekOrigin.Current);
                    }
                }
                string[] files = SCommon.TextToLines(SCommon.ENCODING_SJIS.GetString(LoadFile(resInfos[0])));

                if (files.Length != resInfos.Count)
                {
                    throw new DDError(files.Length + ", " + resInfos.Count);
                }

                for (int index = 1; index < files.Length; index++)
                {
                    string file = files[index];

                    if (File2ResInfo.ContainsKey(file))
                    {
                        throw new DDError(file);
                    }

                    File2ResInfo.Add(file, resInfos[index]);
                }
            }
        }
Beispiel #3
0
        public Scenario(string file)
        {
            byte[] fileData = DDResource.Load(file);
            string text     = SCommon.ToJString(fileData, true, true, true, true);

            string[] lines = SCommon.TextToLines(text);

            foreach (string line in lines)
            {
                if (line == "")                 // ? 空行
                {
                    continue;
                }

                if (line[0] == ';')                 // ? コメント行
                {
                    continue;
                }

                string[] tokens = SCommon.Tokenize(line, " ", false, true);

                this.Commands.Add(new ScenarioCommand()
                {
                    Tokens = tokens,
                });
            }
        }
Beispiel #4
0
        public void Load()
        {
            string[] lines = SCommon.TextToLines(SCommon.ENCODING_SJIS.GetString(DDResource.Load(this.MapFile)));
            int      c     = 0;

            lines = lines.Where(line => line != "" && line[0] != ';').ToArray();             // 空行とコメント行を除去

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

            if (w < 1 || SCommon.IMAX < w)
            {
                throw new DDError();
            }
            if (h < 1 || SCommon.IMAX < h)
            {
                throw new DDError();
            }

            this.Table = new MapCell[w, h];

            for (int x = 0; x < w; x++)
            {
                for (int y = 0; y < h; y++)
                {
                    MapCell cell = new MapCell();

                    if (c < lines.Length)
                    {
                        string[] tokens = SCommon.Tokenize(lines[c++], "\t");
                        int      d      = 0;

                        d++;                         // Skip

                        cell.TileName  = Common.GetElement(tokens, d++, GameConsts.TILE_NONE);
                        cell.Tile      = TileCatalog.Create(cell.TileName);
                        cell.EnemyName = Common.GetElement(tokens, d++, GameConsts.ENEMY_NONE);

                        // 新しい項目をここへ追加..

                        this.Table[x, y] = cell;
                    }
                    else
                    {
                        cell.TileName  = GameConsts.TILE_NONE;
                        cell.Tile      = new Tile_None();
                        cell.EnemyName = GameConsts.ENEMY_NONE;
                    }
                    this.Table[x, y] = cell;
                }
            }
            this.W         = w;
            this.H         = h;
            this.WallName  = Common.GetElement(lines, c++, GameConsts.NAME_DEFAULT);
            this.MusicName = Common.GetElement(lines, c++, GameConsts.NAME_DEFAULT);
            this.穴に落ちたら死亡  = int.Parse(Common.GetElement(lines, c++, "1")) != 0;
        }
Beispiel #5
0
        private static string[] SolveArguments(string[] lines, Dictionary <string, string> arguments)
        {
            string text = SCommon.LinesToText(lines);

            foreach (var pair in arguments)
            {
                text = text.Replace(pair.Key, pair.Value);
            }

            return(SCommon.TextToLines(text));
        }
Beispiel #6
0
        public static void INIT()
        {
            string[] lines = SCommon.TextToLines(SCommon.ENCODING_SJIS.GetString(DDResource.Load(DatStringsFile)));

            foreach (string line in lines)
            {
                int p = line.IndexOf('=');

                if (p == -1)
                {
                    throw new DDError();
                }

                string name  = line.Substring(0, p);
                string value = line.Substring(p + 1);

                Name2Value.Add(name, value);
            }
        }