Add strict mode to setup handler

This commit is contained in:
Tim Van Baak 2024-08-18 03:01:50 +00:00
parent 92506ac6ed
commit b2461b3736
1 changed files with 11 additions and 4 deletions

View File

@ -7,12 +7,17 @@ namespace MultiversalDiplomacy.Script;
/// <summary>
/// A script handler for modifying a game before it begins.
/// </summary>
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;
/// <summary>
/// Whether unsuccessful commands should terminate the script.
/// </summary>
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('#')) {
if (command.StartsWith('#')) break;
Console.WriteLine($"Unrecognized command: {command}");
}
if (Strict) return null;
break;
}