5dplomacy/MultiversalDiplomacy/Script/ReplScriptHandler.cs

58 lines
1.8 KiB
C#

namespace MultiversalDiplomacy.Script;
/// <summary>
/// A script handler for the interactive repl.
/// </summary>
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 custom: standard map, declare units");
Console.WriteLine(" new standard: standard map, standard units");
break;
case "new" when args[1] == "custom":
var world = MultiversalDiplomacy.Model.World.WithStandardMap();
var setupHandler = new SetupScriptHandler(world);
Console.WriteLine("Created an empty game");
return setupHandler;
case "new" when args[1] == "standard":
world = GameController.InitializeWorld();
var gameHandler = new GameScriptHandler(world);
Console.WriteLine("Created a standard game");
return gameHandler;
default:
Console.WriteLine("Unrecognized command");
break;
}
return this;
}
}