From b2461b3736ac0bae8a12b3e8667f4b2619307885 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Sun, 18 Aug 2024 03:01:50 +0000 Subject: [PATCH] Add strict mode to setup handler --- MultiversalDiplomacy/Script/SetupScriptHandler.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/MultiversalDiplomacy/Script/SetupScriptHandler.cs b/MultiversalDiplomacy/Script/SetupScriptHandler.cs index 45f5b0f..19ae3ed 100644 --- a/MultiversalDiplomacy/Script/SetupScriptHandler.cs +++ b/MultiversalDiplomacy/Script/SetupScriptHandler.cs @@ -7,12 +7,17 @@ namespace MultiversalDiplomacy.Script; /// /// A script handler for modifying a game before it begins. /// -public class SetupScriptHandler(World world) : IScriptHandler +public class SetupScriptHandler(World world, bool strict = false) : IScriptHandler { public string Prompt => "5dp> "; public World World { get; private set; } = world; + /// + /// Whether unsuccessful commands should terminate the script. + /// + public bool Strict { get; } = strict; + public IScriptHandler? HandleInput(string input) { var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); @@ -74,14 +79,16 @@ public class SetupScriptHandler(World world) : IScriptHandler if (ParseUnit(power, type, province, location, out Unit? newUnit)) { World = World.Update(units: World.Units.Append(newUnit)); Console.WriteLine($"Created {newUnit}"); + } else if (Strict) { + return null; } break; default: // noop on comments that begin with # - if (!command.StartsWith('#')) { - Console.WriteLine($"Unrecognized command: {command}"); - } + if (command.StartsWith('#')) break; + Console.WriteLine($"Unrecognized command: {command}"); + if (Strict) return null; break; }