5dplomacy/MultiversalDiplomacy/Script/GameScriptHandler.cs

44 lines
1.2 KiB
C#
Raw Normal View History

2024-08-18 04:24:59 +00:00
using MultiversalDiplomacy.Model;
namespace MultiversalDiplomacy.Script;
public class GameScriptHandler(World world, bool strict = false) : IScriptHandler
{
public string Prompt => "game> ";
public World World { get; private set; } = world;
/// <summary>
/// Whether unsuccessful commands should terminate the script.
/// </summary>
public bool Strict { get; } = strict;
private string? CurrentPower = null;
public IScriptHandler? HandleInput(string input)
{
if (input == "") {
CurrentPower = null;
return this;
}
// --- submits the orders for validation to allow for assertions about it
if (input == "---") {
// TODO submit orders
// TODO return a new handler that handles asserts
}
// A block of orders for a single power beginning with "{name}:"
if (World.Powers.FirstOrDefault(p => input.EqualsAnyCase($"{p}:"), null) is string power) {
CurrentPower = power;
return this;
}
// TODO parse order, including "{power} {order}" for one-offs
Console.WriteLine($"{CurrentPower}: {input}");
return this;
}
}