From e151e8490ed40231399618bf2dc4204c2ce99a82 Mon Sep 17 00:00:00 2001 From: bjcul Date: Tue, 27 Sep 2022 19:15:16 -0400 Subject: Merge branch 'master' of git@github.com:bculkin2442/dice-lang.git --- .../neodice/commands/PolyhedralDieCommand.java | 32 +++++++++--------- .../bjc/dicelang/neodice/commands/RollCommand.java | 38 +++++++++++----------- 2 files changed, 35 insertions(+), 35 deletions(-) (limited to 'dice/src/example/java/bjc/dicelang/neodice/commands') 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 e0f66b1..ed74507 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/PolyhedralDieCommand.java @@ -18,24 +18,24 @@ public class PolyhedralDieCommand implements Command { public StatementValue execute(Iterator words, DieBoxCLI state) { if (!words.hasNext()) { throw new DieBoxException("Number of sides to polyhedral-die must be provided"); - } else { - StatementValue sideValue = state.runStatement(words); + } + + StatementValue sideValue = state.runStatement(words); + + if (sideValue.type == INTEGER) { + int numSides = ((IntegerStatementValue)sideValue).value; + + if (numSides < 0) throw new DieBoxException("Number of sides to polyhedral-die was not valid (must be less than 0, was %d)", numSides); + + Die die = Die + .polyhedral(numSides) + .transform(IntegerStatementValue::new); - if (sideValue.type == INTEGER) { - int numSides = ((IntegerStatementValue)sideValue).value; - - if (numSides < 0) throw new DieBoxException("Number of sides to polyhedral-die was not valid (must be less than 0, was %d)", numSides); - - Die 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); - } + return new DieStatementValue(INTEGER, die); } + + throw new DieBoxException("Number of sides to polyhedral-die wasn't an integer (was %s, of type %s)", + sideValue, sideValue.type); } @Override 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 cec7c48..275c53e 100644 --- a/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java +++ b/dice/src/example/java/bjc/dicelang/neodice/commands/RollCommand.java @@ -18,26 +18,26 @@ public class RollCommand implements Command { public StatementValue execute(Iterator words, DieBoxCLI state) { if (!words.hasNext()) { throw new DieBoxException("Roll must be provided an argument to roll"); - } else { - StatementValue toRoll = state.runStatement(words); + } + + StatementValue toRoll = state.runStatement(words); + + if (toRoll.type == DIE) { + DieStatementValue die = (DieStatementValue) toRoll; + + return die.value.roll(state.rng); + } else if (toRoll.type == DIEPOOL) { + DiePoolStatementValue pool = (DiePoolStatementValue) toRoll; - if (toRoll.type == DIE) { - DieStatementValue die = (DieStatementValue) toRoll; - - return die.value.roll(state.rng); - } else if (toRoll.type == DIEPOOL) { - DiePoolStatementValue pool = (DiePoolStatementValue) toRoll; - - 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); - } + 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); } } -- cgit v1.2.3