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.各ページの各行の長さ調整(); }