using MultiversalDiplomacy.Model; namespace MultiversalDiplomacy.Script; /// /// A script handler for the interactive repl. /// public class ReplScriptHandler : IScriptHandler { public string Prompt => "5dp> "; public IScriptHandler? HandleInput(string input) { var args = input.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (args.Length == 0) { return this; } var command = args[0]; switch (command) { case "help": case "?": Console.WriteLine("Commands:"); Console.WriteLine(" help, ?: print this message"); Console.WriteLine(" stab: stab"); Console.WriteLine(" new: start a new game"); break; case "stab": Console.WriteLine("stab"); break; case "new" when args.Length == 1: Console.WriteLine("Usage:"); Console.WriteLine(" new [map]"); Console.WriteLine("Available maps:"); Console.WriteLine(string.Join(", ", Enum.GetNames().Select(s => s.ToLowerInvariant()))); break; case "new" when args.Length > 1: if (!Enum.TryParse(args[1], out MapType map)) { Console.WriteLine($"Unknown map {args[1]}"); Console.WriteLine("Available maps:"); Console.WriteLine(string.Join(", ", Enum.GetNames().Select(s => s.ToLowerInvariant()))); break; } World world = World.WithMap(Map.FromType(map)); Console.WriteLine($"Created a new {map} game"); return this; default: Console.WriteLine($"Unrecognized command: {command}"); break; } return this; } }