Compare commits
2 Commits
135997a7cd
...
20b7269e4b
Author | SHA1 | Date |
---|---|---|
Tim Van Baak | 20b7269e4b | |
Tim Van Baak | 0ee31a9629 |
|
@ -1,5 +1,9 @@
|
|||
using System.Text.Json;
|
||||
|
||||
using CommandLine;
|
||||
|
||||
using MultiversalDiplomacy.Model;
|
||||
|
||||
namespace MultiversalDiplomacy.CommandLine;
|
||||
|
||||
[Verb("adjudicate", HelpText = "Adjudicate a Multiversal Diplomacy game state.")]
|
||||
|
@ -10,6 +14,13 @@ public class AdjudicateOptions
|
|||
|
||||
public static void Execute(AdjudicateOptions args)
|
||||
{
|
||||
Stream input = args.InputFile switch {
|
||||
null => Console.OpenStandardInput(),
|
||||
"-" => Console.OpenStandardInput(),
|
||||
_ => new FileStream(args.InputFile!, FileMode.Open, FileAccess.Read),
|
||||
};
|
||||
var state = JsonSerializer.Deserialize<World>(input);
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
using CommandLine;
|
||||
|
||||
namespace MultiversalDiplomacy.CommandLine;
|
||||
|
||||
[Verb("image", HelpText = "Generate an image of a game state.")]
|
||||
public class ImageOptions
|
||||
{
|
||||
[Value(0, HelpText = "Input file describing the game state to visualize, or - to read from stdin.")]
|
||||
public string? InputFile { get; set; }
|
||||
|
||||
public static void Execute(ImageOptions args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using CommandLine;
|
||||
|
||||
namespace MultiversalDiplomacy.CommandLine;
|
||||
|
||||
[Verb("repl", HelpText = "Begin an interactive 5dplomacy session.")]
|
||||
public class ReplOptions
|
||||
{
|
||||
[Option('i', "input", HelpText = "Begin the repl session by executing the commands in this file.")]
|
||||
public string? InputFile { get; set; }
|
||||
|
||||
[Option('o', "output", HelpText = "Echo the repl session to this file. Specify a directory to autogenerate a filename.")]
|
||||
public string? OutputFile { get; set; }
|
||||
|
||||
public static void Execute(ReplOptions args)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
|
@ -9,9 +9,15 @@ internal class Program
|
|||
static void Main(string[] args)
|
||||
{
|
||||
var parser = Parser.Default;
|
||||
var parseResult = parser.ParseArguments<AdjudicateOptions>(args);
|
||||
var parseResult = parser.ParseArguments(
|
||||
args,
|
||||
typeof(AdjudicateOptions),
|
||||
typeof(ImageOptions),
|
||||
typeof(ReplOptions));
|
||||
|
||||
parseResult
|
||||
.WithParsed(AdjudicateOptions.Execute);
|
||||
.WithParsed<AdjudicateOptions>(AdjudicateOptions.Execute)
|
||||
.WithParsed<ImageOptions>(ImageOptions.Execute)
|
||||
.WithParsed<ReplOptions>(ReplOptions.Execute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
namespace MultiversalDiplomacy.Script;
|
||||
|
||||
/// <summary>
|
||||
/// A handler that interprets and executes 5dp script commands. Script handlers may create additional script handlers
|
||||
/// and delegate handling to them, allowing a sort of recursive parsing of script commands.
|
||||
/// </summary>
|
||||
public interface IScriptHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// When used interactively, the prompt that should be displayed.
|
||||
/// </summary>
|
||||
public string Prompt { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Process a line of input.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// The handler that should handle the next line of input, or null if script handling should end.
|
||||
/// </returns>
|
||||
public IScriptHandler? HandleInput(string input);
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
using MultiversalDiplomacy.Model;
|
||||
|
||||
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 [map]");
|
||||
Console.WriteLine("Available maps:");
|
||||
Console.WriteLine(string.Join(", ", Enum.GetNames<MapType>().Select(s => s.ToLowerInvariant())));
|
||||
break;
|
||||
|
||||
case "new" when args.Length > 1:
|
||||
if (!Enum.TryParse<MapType>(args[1], out MapType map)) {
|
||||
Console.WriteLine($"Unknown map {args[1]}");
|
||||
Console.WriteLine("Available maps:");
|
||||
Console.WriteLine(string.Join(", ", Enum.GetNames<MapType>().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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue