62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
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)
|
|
{
|
|
var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
|
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":
|
|
string assertion = input["assert ".Length..];
|
|
OrderRegex re = new(World);
|
|
Regex prov = new($"{re.Province} (.*)");
|
|
Match match = prov.Match(assertion);
|
|
if (!match.Success) {
|
|
Console.WriteLine($"Could not parse province from \"{assertion}\"");
|
|
return Strict ? null : this;
|
|
}
|
|
// TODO look up order once orders are validated and adjudicated
|
|
Console.WriteLine("Order lookup not implemented yet");
|
|
return null;
|
|
|
|
case "status":
|
|
throw new NotImplementedException();
|
|
|
|
default:
|
|
Console.WriteLine($"Unrecognized command: \"{command}\"");
|
|
if (Strict) return null;
|
|
break;
|
|
}
|
|
|
|
return this;
|
|
}
|
|
}
|