diff options
Diffstat (limited to 'dice/src/example/java/bjc/dicelang/neodice/commands')
6 files changed, 56 insertions, 3 deletions
diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java index 5091c4b..8664379 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/BindCommand.java @@ -7,6 +7,11 @@ import java.util.*; import bjc.dicelang.neodice.*; import bjc.dicelang.neodice.statements.*; +/** + * This command binds a name to a variable slot. + * @author Ben Culkin + * + */ public class BindCommand implements Command { @Override public StatementValue execute(Iterator<String> words, DieBoxCLI state) { diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java index 705745e..c10db4e 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/HelpCommand.java @@ -7,6 +7,11 @@ import java.util.*; import bjc.dicelang.neodice.*; import bjc.dicelang.neodice.statements.*; +/** + * Diebox help command. Unimplemented as of yet. + * @author Ben Culkin + * + */ public class HelpCommand implements Command { @Override public StatementValue execute(Iterator<String> words, DieBoxCLI state) { diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java index 9b42b42..b781ae9 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/LiteralCommand.java @@ -5,12 +5,28 @@ import java.util.*; import bjc.dicelang.neodice.*; import bjc.dicelang.neodice.statements.*; +/** + * A command that produces a literal statement value. + * + * This command will always produce the same statement value, so passing any sort + * of mutable statement value to it is asking to be hurt. + * + * @author Ben Culkin + * + */ public class LiteralCommand implements Command { private final StatementValue value; private final String shortHelp; private final String longHelp; + /** + * Create a new command producing a literal statement value. + * + * @param value The value this command returns. + * @param shortHelp The short-help (summary) for this command. + * @param longHelp The long-help (description) for this command. + */ public LiteralCommand(StatementValue value, String shortHelp, String longHelp) { this.value = value; diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java index 02fc9cf..e0f66b1 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java @@ -7,6 +7,12 @@ import java.util.*; import bjc.dicelang.neodice.*; import bjc.dicelang.neodice.statements.*; +/** + * A command that produces a polyhedral die. + * + * @author Ben Culkin + * + */ public class PolyhedralDieCommand implements Command { @Override public StatementValue execute(Iterator<String> words, DieBoxCLI state) { @@ -20,7 +26,11 @@ public class PolyhedralDieCommand implements Command { if (numSides < 0) throw new DieBoxException("Number of sides to polyhedral-die was not valid (must be less than 0, was %d)", numSides); - return new DieStatementValue(DieFactory.polyhedral(numSides)); + Die<StatementValue> die = Die + .polyhedral(numSides) + .transform(IntegerStatementValue::new); + + return new DieStatementValue(INTEGER, die); } else { throw new DieBoxException("Number of sides to polyhedral-die wasn't an integer (was %s, of type %s)", sideValue, sideValue.type); diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java index eb7b597..cec7c48 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java @@ -7,6 +7,12 @@ import java.util.*; import bjc.dicelang.neodice.*; import bjc.dicelang.neodice.statements.*; +/** + * A command that rolls a die or die-pool. + * + * @author Ben Culkin + * + */ public class RollCommand implements Command { @Override public StatementValue execute(Iterator<String> words, DieBoxCLI state) { @@ -18,11 +24,16 @@ public class RollCommand implements Command { if (toRoll.type == DIE) { DieStatementValue die = (DieStatementValue) toRoll; - return new IntegerStatementValue(die.value.roll(state.rng)); + return die.value.roll(state.rng); } else if (toRoll.type == DIEPOOL) { DiePoolStatementValue pool = (DiePoolStatementValue) toRoll; - return new IntArrayStatementValue(pool.value.roll(state.rng)); + StatementValue[] values = pool.value + .roll(state.rng) + .toArray((sz) -> new StatementValue[sz]); + + return new ArrayStatementValue<>(pool.elementType, + values); } else { throw new DieBoxException("Roll was provided something that wasn't rollable (only DIE and DIEPOOL objects are rollable) (was %s, of type %s)", toRoll, toRoll.type); diff --git a/dice/src/example/java/bjc/dicelang/neodice/commands/ShowBindingsCommand.java b/dice/src/example/java/bjc/dicelang/neodice/commands/ShowBindingsCommand.java index fe2ac89..75811b6 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/ShowBindingsCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/ShowBindingsCommand.java @@ -7,6 +7,12 @@ import java.util.*; import bjc.dicelang.neodice.*; import bjc.dicelang.neodice.statements.*; +/** + * A command that shows all of the currently bound variables. + * + * @author Ben Culkin + * + */ public class ShowBindingsCommand implements Command { @Override public StatementValue execute(Iterator<String> words, DieBoxCLI state) { |
