Compare commits

..

No commits in common. "20b7269e4ba484fb064823e129128f6301f86893" and "135997a7cd922c2f4fe84445bf95bd995265bc6f" have entirely different histories.

6 changed files with 3 additions and 134 deletions

View File

@ -1,9 +1,5 @@
using System.Text.Json;
using CommandLine;
using MultiversalDiplomacy.Model;
namespace MultiversalDiplomacy.CommandLine;
[Verb("adjudicate", HelpText = "Adjudicate a Multiversal Diplomacy game state.")]
@ -14,13 +10,6 @@ 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();
}
}

View File

@ -1,15 +0,0 @@
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();
}
}

View File

@ -1,18 +0,0 @@
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();
}
}

View File

@ -9,15 +9,9 @@ internal class Program
static void Main(string[] args)
{
var parser = Parser.Default;
var parseResult = parser.ParseArguments(
args,
typeof(AdjudicateOptions),
typeof(ImageOptions),
typeof(ReplOptions));
var parseResult = parser.ParseArguments<AdjudicateOptions>(args);
parseResult
.WithParsed<AdjudicateOptions>(AdjudicateOptions.Execute)
.WithParsed<ImageOptions>(ImageOptions.Execute)
.WithParsed<ReplOptions>(ReplOptions.Execute);
.WithParsed(AdjudicateOptions.Execute);
}
}
}

View File

@ -1,21 +0,0 @@
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);
}

View File

@ -1,60 +0,0 @@
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;
}
}