added roll macros

This commit is contained in:
Valerie Wolfe 2024-03-31 01:25:32 -04:00
parent 48799dc0a7
commit 7af123f5d4
4 changed files with 19 additions and 3 deletions

View file

@ -9,6 +9,13 @@ namespace Dungeoneer {
if(args.Count == 0)
return;
// 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;

View file

@ -6,7 +6,14 @@ namespace Dungeoneer {
public delegate void Command(IList<string> args);
public static Dictionary<string, Command> ReplCommands = new Dictionary<string, Command> {
{ "new", (Command)Dungeoneer.Command.New },
{ "roll", (Command)Dungeoneer.Command.Roll }
// TODO: "with"?
};
public static Dictionary<string, Command> RollMacros = new Dictionary<string, Command> {
// TODO: disadvantage ( roll twice and take lowest )
// TODO: pool ( any of NdX > D => success )
};
public static void Main() {

View file

@ -22,7 +22,9 @@ namespace Dungeoneer {
builtin.SetVariable("input", (Func<string, string>)Input);
builtin.RemoveVariable("open");
Scope.repl = Program.ReplCommands;
// helper vars
Scope.repl_commands = Program.ReplCommands;
Scope.roll_macros = Program.RollMacros;
// helper functions
Scope.roll = (Func<int, int>)Dungeoneer.Util.Roll;

View file

@ -7,8 +7,8 @@ def repl_loop():
parts = raw.split(" ")
command = parts[0]
del parts[0]
if command in repl:
repl[command](parts)
if command in repl_commands:
repl_commands[command](parts)
repl_loop()