From c8ddf9d547250257e4580547bbcbefedc8049577 Mon Sep 17 00:00:00 2001 From: Stefan Zermatten Date: Fri, 18 Sep 2020 12:24:08 +0200 Subject: [PATCH] Added the ability to double all number of dice to roll using context --- app/imports/parser/parseTree/IfNode.js | 8 ++------ app/imports/parser/parseTree/RollNode.js | 6 +++++- app/imports/parser/parser.js | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/imports/parser/parseTree/IfNode.js b/app/imports/parser/parseTree/IfNode.js index 0224fd0f..2505fe57 100644 --- a/app/imports/parser/parseTree/IfNode.js +++ b/app/imports/parser/parseTree/IfNode.js @@ -16,13 +16,9 @@ export default class IfNode extends ParseNode { let condition = this.condition[fn](scope, context); if (condition instanceof ConstantNode){ if (condition.value){ - let consequent = this.consequent[fn](scope, context); - consequent.inheritDetails([condition, this]); - return this.consequent[fn](scope); + return this.consequent[fn](scope, context); } else { - let alternative = this.alternative[fn](scope, context); - alternative.inheritDetails([condition, this]); - return alternative; + return this.alternative[fn](scope, context); } } else { return new IfNode({ diff --git a/app/imports/parser/parseTree/RollNode.js b/app/imports/parser/parseTree/RollNode.js index d57bd734..ab3f62e8 100644 --- a/app/imports/parser/parseTree/RollNode.js +++ b/app/imports/parser/parseTree/RollNode.js @@ -40,9 +40,13 @@ export default class RollNode extends ParseNode { }); } let number = left.value; + if (context.doubleRolls){ + number *= 2; + } if (number > 100) return new ErrorNode({ node: this, - error: 'Can\'t roll more than 100 dice at once' + error: 'Can\'t roll more than 100 dice at once', + context, }); let diceSize = right.value; let randomSrc = DDP.randomStream('diceRoller'); diff --git a/app/imports/parser/parser.js b/app/imports/parser/parser.js index d51b2733..bf174759 100644 --- a/app/imports/parser/parser.js +++ b/app/imports/parser/parser.js @@ -8,9 +8,10 @@ export default function parser(){ } export class CompilationContext { - constructor(){ + constructor({doubleRolls}){ this.errors = []; this.rolls = []; + this.doubleRolls = doubleRolls; } storeError(e){ this.errors.push(e);