Added the ability to double all number of dice to roll using context
This commit is contained in:
@@ -16,13 +16,9 @@ export default class IfNode extends ParseNode {
|
|||||||
let condition = this.condition[fn](scope, context);
|
let condition = this.condition[fn](scope, context);
|
||||||
if (condition instanceof ConstantNode){
|
if (condition instanceof ConstantNode){
|
||||||
if (condition.value){
|
if (condition.value){
|
||||||
let consequent = this.consequent[fn](scope, context);
|
return this.consequent[fn](scope, context);
|
||||||
consequent.inheritDetails([condition, this]);
|
|
||||||
return this.consequent[fn](scope);
|
|
||||||
} else {
|
} else {
|
||||||
let alternative = this.alternative[fn](scope, context);
|
return this.alternative[fn](scope, context);
|
||||||
alternative.inheritDetails([condition, this]);
|
|
||||||
return alternative;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return new IfNode({
|
return new IfNode({
|
||||||
|
|||||||
@@ -40,9 +40,13 @@ export default class RollNode extends ParseNode {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
let number = left.value;
|
let number = left.value;
|
||||||
|
if (context.doubleRolls){
|
||||||
|
number *= 2;
|
||||||
|
}
|
||||||
if (number > 100) return new ErrorNode({
|
if (number > 100) return new ErrorNode({
|
||||||
node: this,
|
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 diceSize = right.value;
|
||||||
let randomSrc = DDP.randomStream('diceRoller');
|
let randomSrc = DDP.randomStream('diceRoller');
|
||||||
|
|||||||
@@ -8,9 +8,10 @@ export default function parser(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class CompilationContext {
|
export class CompilationContext {
|
||||||
constructor(){
|
constructor({doubleRolls}){
|
||||||
this.errors = [];
|
this.errors = [];
|
||||||
this.rolls = [];
|
this.rolls = [];
|
||||||
|
this.doubleRolls = doubleRolls;
|
||||||
}
|
}
|
||||||
storeError(e){
|
storeError(e){
|
||||||
this.errors.push(e);
|
this.errors.push(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user