dungeoneer-cs/Command.cs

34 lines
649 B
C#
Raw Normal View History

2024-03-30 01:51:02 -04:00
using System.Text.RegularExpressions;
namespace Dungeoneer {
public sealed class Command {
public static void Roll(IList<string> args) {
// don't do anything with empty expressions
2024-03-30 01:51:02 -04:00
if(args.Count == 0)
return;
2024-03-31 01:25:32 -04:00
// pass to subcommands
var first = args[0];
if(Program.RollMacros.ContainsKey(first)) {
Program.RollMacros[first](args);
return;
}
// create new parsed expression object and pretty-print
var roll = new RollExpression(args);
var result = roll.Result;
if(result == null)
Console.WriteLine("invalid expression");
else
Console.WriteLine($"{roll.Print}\n => {result}");
}
}
}