using MultiversalDiplomacy.Adjudicate; using MultiversalDiplomacy.Model; namespace MultiversalDiplomacy.Script; /// /// A script handler for the interactive repl. /// public class ReplScriptHandler(Action WriteLine) : IScriptHandler { public string Prompt => "5dp> "; public ScriptResult HandleInput(string input) { var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (args.Length == 0 || input.StartsWith('#')) { return ScriptResult.Succeed(this); } var command = args[0]; switch (command) { case "help": case "?": WriteLine("Commands:"); WriteLine(" help, ?: print this message"); WriteLine(" map : start a new game of the given variant"); WriteLine(" stab: stab"); break; case "stab": WriteLine("stab"); break; case "map" when args.Length == 1: WriteLine("Usage:"); WriteLine(" map "); WriteLine("Available variants:"); WriteLine($" {string.Join(", ", Enum.GetNames().Select(s => s.ToLowerInvariant()))}"); break; case "map" when args.Length > 1: string mapType = args[1].Trim(); if (!Enum.TryParse(mapType, ignoreCase: true, out MapType map)) { WriteLine($"Unknown variant \"{mapType}\""); WriteLine("Available variants:"); WriteLine($" {string.Join(", ", Enum.GetNames().Select(s => s.ToLowerInvariant()))}"); break; } World world = World.WithMap(Map.FromType(map)); WriteLine($"Created a new {map} game"); return ScriptResult.Succeed(new SetupScriptHandler( WriteLine, world, MovementPhaseAdjudicator.Instance)); default: return ScriptResult.Fail($"Unrecognized command: \"{command}\"", this); } return ScriptResult.Succeed(this); } }