5dplomacy/MultiversalDiplomacy/Script/AdjudicationQueryScriptHand...

68 lines
1.7 KiB
C#
Raw Normal View History

using System.Text.RegularExpressions;
using MultiversalDiplomacy.Model;
namespace MultiversalDiplomacy.Script;
public class AdjudicationQueryScriptHandler(World world, bool strict = false) : IScriptHandler
{
public string Prompt => "valid> ";
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)
{
2024-08-28 15:01:27 +00:00
var args = input.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
2024-08-21 16:47:13 +00:00
if (args.Length == 0 || input.StartsWith('#'))
{
return this;
}
var command = args[0];
switch (command)
{
case "---":
Console.WriteLine("Ready for orders");
return new GameScriptHandler(World, Strict);
case "assert" when args.Length == 1:
Console.WriteLine("Usage:");
break;
case "assert":
2024-08-28 15:01:27 +00:00
return HandleAssertion(args[1]);
case "status":
throw new NotImplementedException();
default:
Console.WriteLine($"Unrecognized command: \"{command}\"");
if (Strict) return null;
break;
}
return this;
}
2024-08-28 15:01:27 +00:00
private AdjudicationQueryScriptHandler? HandleAssertion(string assertion)
{
// Simple assertions
switch (assertion)
{
case "true":
return this;
case "false":
return null;
}
Console.WriteLine("Order lookup not implemented yet");
return this;
}
}