/// <summary> /// ルール設定を書き出す /// </summary> /// <param name="rules">ルール設定</param> /// <param name="writer">ファイル書き込み用</param> private static void WriteRules(ScenarioRules rules, TextWriter writer) { // 禁止項目がなければセクションを書き出さない if (rules.AllowDiplomacy && rules.AllowProduction && rules.AllowTechnology) { return; } writer.WriteLine(" rules = {"); if (!rules.AllowDiplomacy) { writer.WriteLine(" diplomacy = no"); } if (!rules.AllowProduction) { writer.WriteLine(" production = no"); } if (!rules.AllowTechnology) { writer.WriteLine(" technology = no"); } writer.WriteLine(" }"); }
/// <summary> /// ルール設定を構文解析する /// </summary> /// <param name="lexer">字句解析器</param> /// <returns>ルール設定</returns> private static ScenarioRules ParseRules(TextLexer lexer) { // = Token token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); return null; } // { token = lexer.GetToken(); if (token.Type != TokenType.OpenBrace) { Log.InvalidToken(LogCategory, token, lexer); return null; } ScenarioRules rules = new ScenarioRules(); while (true) { token = lexer.GetToken(); // ファイルの終端 if (token == null) { break; } // } (セクション終端) if (token.Type == TokenType.CloseBrace) { break; } // 無効なトークン if (token.Type != TokenType.Identifier) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } string keyword = token.Value as string; if (string.IsNullOrEmpty(keyword)) { continue; } keyword = keyword.ToLower(); // diplomacy if (keyword.Equals("diplomacy")) { bool? b = ParseBool(lexer); if (!b.HasValue) { Log.InvalidClause(LogCategory, "diplomacy", lexer); continue; } // 外交 rules.AllowDiplomacy = (bool) b; continue; } // production if (keyword.Equals("production")) { bool? b = ParseBool(lexer); if (!b.HasValue) { Log.InvalidClause(LogCategory, "production", lexer); continue; } // 生産 rules.AllowProduction = (bool) b; continue; } // technology if (keyword.Equals("technology")) { bool? b = ParseBool(lexer); if (!b.HasValue) { Log.InvalidClause(LogCategory, "technology", lexer); continue; } // 技術 rules.AllowTechnology = (bool) b; continue; } // 無効なトークン Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); } return rules; }
/// <summary> /// コンストラクタ /// </summary> public ScenarioGlobalData() { // null動作が保証できれば削除 Rules = new ScenarioRules(); Axis = new Alliance(); Allies = new Alliance(); Comintern = new Alliance(); }