5dplomacy/MultiversalDiplomacy/Script/ReplScriptHandler.cs

58 lines
1.8 KiB
C#
Raw Normal View History

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;
2022-12-31 21:53:07 +00:00
case "new" when args.Length == 1:
Console.WriteLine("usage:");
Console.WriteLine(" new custom: standard map, declare units");
2022-12-31 21:53:07 +00:00
Console.WriteLine(" new standard: standard map, standard units");
break;
case "new" when args[1] == "custom":
2022-12-31 21:53:07 +00:00
var world = MultiversalDiplomacy.Model.World.WithStandardMap();
var setupHandler = new SetupScriptHandler(world);
2022-12-31 21:53:07 +00:00
Console.WriteLine("Created an empty game");
return setupHandler;
2022-12-31 21:53:07 +00:00
case "new" when args[1] == "standard":
world = GameController.InitializeWorld();
var gameHandler = new GameScriptHandler(world);
2022-12-31 21:53:07 +00:00
Console.WriteLine("Created a standard game");
return gameHandler;
default:
Console.WriteLine("Unrecognized command");
break;
}
return this;
}
}