Re-spec validation handler for all adjudication steps
This commit is contained in:
parent
32a7ddd3b5
commit
e9c4d3d2d3
@ -4,7 +4,7 @@ using MultiversalDiplomacy.Model;
|
||||
|
||||
namespace MultiversalDiplomacy.Script;
|
||||
|
||||
public class ValidatedOrdersScriptHandler(World world, bool strict = false) : IScriptHandler
|
||||
public class AdjudicationQueryScriptHandler(World world, bool strict = false) : IScriptHandler
|
||||
{
|
||||
public string Prompt => "valid> ";
|
||||
|
||||
@ -26,6 +26,10 @@ public class ValidatedOrdersScriptHandler(World world, bool strict = false) : IS
|
||||
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;
|
||||
@ -36,17 +40,20 @@ public class ValidatedOrdersScriptHandler(World world, bool strict = false) : IS
|
||||
Regex prov = new($"{re.Province} (.*)");
|
||||
Match match = prov.Match(assertion);
|
||||
if (!match.Success) {
|
||||
Console.WriteLine($"Could not parse province from {assertion}");
|
||||
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:
|
||||
// noop on comments that begin with #
|
||||
if (command.StartsWith('#')) break;
|
||||
Console.WriteLine($"Unrecognized command: {command}");
|
||||
Console.WriteLine($"Unrecognized command: \"{command}\"");
|
||||
if (Strict) return null;
|
||||
break;
|
||||
}
|
@ -25,11 +25,22 @@ public class GameScriptHandler(World world, bool strict = false) : IScriptHandle
|
||||
return this;
|
||||
}
|
||||
|
||||
// "---" submits the orders for validation to allow for assertions about it
|
||||
// "---" submits the orders and allows queries about the outcome
|
||||
if (input == "---") {
|
||||
Console.WriteLine("Submitting orders for validation");
|
||||
// TODO submit orders
|
||||
return new ValidatedOrdersScriptHandler(World, Strict);
|
||||
Console.WriteLine("Submitting orders for adjudication");
|
||||
// TODO submit, validate, and adjudicate orders
|
||||
// TODO pass validation, adjudication, and prev/next World to next handler
|
||||
return new AdjudicationQueryScriptHandler(World, Strict);
|
||||
}
|
||||
|
||||
// "===" submits the orders and moves immediately to taking the next set of orders
|
||||
// i.e. it's "---" twice
|
||||
if (input == "===") {
|
||||
Console.WriteLine("Submitting orders for adjudication");
|
||||
// TODO submit, validate, and adjudicate orders
|
||||
// TODO replace World with updated world and return a new handler
|
||||
Console.WriteLine("Ready for orders");
|
||||
return new GameScriptHandler(World, Strict);
|
||||
}
|
||||
|
||||
// A block of orders for a single power beginning with "{name}:"
|
||||
|
@ -42,7 +42,7 @@ public class ReplScriptHandler : IScriptHandler
|
||||
case "map" when args.Length > 1:
|
||||
string mapType = args[1].Trim();
|
||||
if (!Enum.TryParse(mapType, ignoreCase: true, out MapType map)) {
|
||||
Console.WriteLine($"Unknown variant {mapType}");
|
||||
Console.WriteLine($"Unknown variant \"{mapType}\"");
|
||||
Console.WriteLine("Available variants:");
|
||||
Console.WriteLine($" {string.Join(", ", Enum.GetNames<MapType>().Select(s => s.ToLowerInvariant()))}");
|
||||
break;
|
||||
@ -54,7 +54,7 @@ public class ReplScriptHandler : IScriptHandler
|
||||
default:
|
||||
// noop on comments that begin with #
|
||||
if (!command.StartsWith('#')) {
|
||||
Console.WriteLine($"Unrecognized command: {command}");
|
||||
Console.WriteLine($"Unrecognized command: \"{command}\"");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl
|
||||
case "begin":
|
||||
case "---":
|
||||
Console.WriteLine("Starting game");
|
||||
Console.WriteLine("Ready for orders");
|
||||
return new GameScriptHandler(World, Strict);
|
||||
|
||||
case "list" when args.Length == 1:
|
||||
@ -89,7 +90,7 @@ public class SetupScriptHandler(World world, bool strict = false) : IScriptHandl
|
||||
default:
|
||||
// noop on comments that begin with #
|
||||
if (command.StartsWith('#')) break;
|
||||
Console.WriteLine($"Unrecognized command: {command}");
|
||||
Console.WriteLine($"Unrecognized command: \"{command}\"");
|
||||
if (Strict) return null;
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user