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, }); } }
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; }
private Dictionary <string, string> ParseArguments(string[] arguments) { Dictionary <string, string> dest = new Dictionary <string, string>(); foreach (string argument in arguments) { string[] tokens = SCommon.Tokenize(argument, "=", false, true, 2); string key = tokens[0]; string value = tokens[1]; dest[key] = value; } return(dest); }
public Scenario(string name) { if (string.IsNullOrEmpty(name)) { throw new DDError(); } this.Name = name; this.Pages.Clear(); string[] lines = ReadScenarioLines(name); ScenarioPage page = null; // memo: lines タブスペース除去済み for (int index = 0; index < lines.Length; index++) { string line = lines[index].Trim(); if (line == "") { continue; } if (line[0] == '#') // ? 外部ファイル参照 { line = line.Substring(1); // # 除去 string[] tokens = SCommon.Tokenize(line, " ", false, true); string subName = tokens[0]; string[] arguments = tokens.Skip(1).ToArray(); string[] subLines = ReadScenarioLines(subName); subLines = SolveArguments(subLines, ParseArguments(arguments)); lines = lines.Take(index).Concat(subLines).Concat(lines.Skip(index + 1)).ToArray(); } } { Dictionary <string, string> def_dic = SCommon.CreateDictionary <string>(); for (int index = 0; index < lines.Length; index++) { string line = lines[index].Trim(); if (line == "") { continue; } if (line[0] == '^') // ? 定義 { line = line.Substring(1); // ^ 除去 string[] tokens = SCommon.Tokenize(line, " ", false, true, 2); string def_name = tokens[0]; string def_value = tokens[1]; def_dic.Add(def_name, def_value); lines[index] = ""; } } for (int index = 0; index < lines.Length; index++) { string line = lines[index]; foreach (KeyValuePair <string, string> pair in def_dic) { line = line.Replace(pair.Key, pair.Value); } lines[index] = line; } } bool 読み込み抑止中 = false; foreach (string f_line in lines) { string line = f_line.Trim(); if (line == "") { continue; } if (line[0] == ';') // ? コメント行 { continue; } if (line[0] == '/') { page = new ScenarioPage() { Subtitle = line.Substring(1) }; this.Pages.Add(page); } else if (page == null) { throw new DDError("シナリオの先頭は /xxx でなければなりません。"); } else if (line[0] == '!') // ? コマンド { string[] tokens = line.Substring(1).Split(' ').Where(v => v != "").ToArray(); if (tokens[0] == "_ifndef") { 読み込み抑止中 = Novel.I != null && Novel.I.Status.Surfaces.Any(surface => surface.InstanceName == tokens[1]); } else if (tokens[0] == "_endif") { 読み込み抑止中 = false; } else if (読み込み抑止中) { } else { page.Commands.Add(new ScenarioCommand(tokens)); } } else if (読み込み抑止中) { } else { page.Lines.Add(line); } } }
public Scenario(string name) { if (string.IsNullOrEmpty(name)) { throw new DDError(); } this.Name = name; this.Pages.Clear(); string[] lines = this.ReadScenarioLines(name); ScenarioPage page = null; for (int index = 0; index < lines.Length; index++) { string line = lines[index].Trim(); if (line == "") { continue; } if (line[0] == '#') // ? 外部ファイル参照 { string subName = line.Substring(1); string[] subLines = this.ReadScenarioLines(subName); lines = lines.Take(index).Concat(subLines).Concat(lines.Skip(index + 1)).ToArray(); // HACK: このへん要調整, 問題ないか要チェック } } { Dictionary <string, string> def_dic = SCommon.CreateDictionary <string>(); for (int index = 0; index < lines.Length; index++) { string line = lines[index].Trim(); if (line == "") { continue; } if (line[0] == '^') // ? 定義 { line = line.Substring(1); // ^ 除去 string[] tokens = SCommon.Tokenize(line, " ", false, true, 2); string def_name = tokens[0]; string def_value = tokens[1]; def_dic.Add(def_name, def_value); lines[index] = ""; } } for (int index = 0; index < lines.Length; index++) { string line = lines[index]; foreach (KeyValuePair <string, string> pair in def_dic) { line = line.Replace(pair.Key, pair.Value); } lines[index] = line; } } foreach (string f_line in lines) { string line = f_line.Trim(); if (line == "") { continue; } if (line[0] == ';') // ? コメント行 { continue; } if (line[0] == '/') { page = new ScenarioPage() { Subtitle = line.Substring(1) }; this.Pages.Add(page); } else if (page == null) { throw new DDError("シナリオの先頭は /xxx でなければなりません。"); } else if (line[0] == '!') // ? コマンド { string[] tokens = line.Substring(1).Split(' ').Where(v => v != "").ToArray(); page.Commands.Add(new ScenarioCommand(tokens)); } else { page.Lines.Add(line); } } this.各ページの各行の長さ調整(); }