Add strict mode to setup handler
This commit is contained in:
parent
92506ac6ed
commit
b2461b3736
@ -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('#')) {
|
||||
Console.WriteLine($"Unrecognized command: {command}");
|
||||
}
|
||||
if (command.StartsWith('#')) break;
|
||||
Console.WriteLine($"Unrecognized command: {command}");
|
||||
if (Strict) return null;
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user