From a82804c1d64e463d5408a60ea25f6109851e8948 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Tue, 8 Dec 2020 18:36:38 +0100 Subject: [PATCH] shrink logic for same result :p --- system/scripts/dice/roll.js | 73 ++++++++++++------------------ system/templates/dice/tooltip.html | 2 + 2 files changed, 31 insertions(+), 44 deletions(-) diff --git a/system/scripts/dice/roll.js b/system/scripts/dice/roll.js index 9128e47..f8fcbae 100644 --- a/system/scripts/dice/roll.js +++ b/system/scripts/dice/roll.js @@ -45,61 +45,30 @@ export class RollL5r5e extends Roll { if (this._rolled) { throw new Error("This Roll object has already been rolled."); } + if (this.terms.length < 1) { + throw new Error("This Roll object need dice to be rolled."); + } console.log("RollL5r5e.evaluate.in", this); // TODO tmp - // Split L5R dices / regulars for non inners - let l5rDices = this.terms.filter((term) => term instanceof L5rBaseDie); - this.terms = this.terms.filter((t) => !(t instanceof L5rBaseDie)); + // Clean terms (trim symbols) this.terms = this._identifyTerms(this.constructor.cleanFormula(this.terms)); - // Roll regular dices / inner dices + // Roll dices and inner dices this._total = 0; - if (this.terms.length > 0) { - // clean terms (trim symbols) - this.terms = this._identifyTerms(this.constructor.cleanFormula(this.terms)); - // Roll - super.evaluate({ minimize, maximize }); - } + // Roll + super.evaluate({ minimize, maximize }); - // Check inner L5R rolls - this._dice.forEach((term) => { - if (term instanceof L5rBaseDie) { - // Add results to total - ["success", "explosive", "opportunity", "strife"].forEach((props) => { - this.l5r5e.summary[props] += parseInt(term.l5r5e[props]); - }); - } - }); + // Current terms - L5R Summary + this.terms.forEach((term) => this._l5rSummary(term)); - // Roll non inner L5R dices - if (l5rDices.length > 0) { - l5rDices.forEach((term) => { - // Roll - term.evaluate({ minimize, maximize }); - - // Total - ["success", "explosive", "opportunity", "strife"].forEach((props) => { - this.l5r5e.summary[props] += parseInt(term.l5r5e[props]); - }); - - // re-inject L5R dices - this.terms.push("+"); - this.terms.push(term); - }); - - // Clean - if (this.terms[0] === "+") { - this.terms.shift(); - } - - // TODO Others advantage/disadvantage - } + // Check inner L5R rolls - L5R Summary + this._dice.forEach((term) => this._l5rSummary(term)); // Store final outputs this._rolled = true; - this.l5r5e.dicesTypes.std = this.dice.some((term) => term instanceof DiceTerm && !(term instanceof L5rBaseDie)); + this.l5r5e.dicesTypes.std = this.dice.some((term) => term instanceof DiceTerm && !(term instanceof L5rBaseDie)); // ignore math symbols this.l5r5e.dicesTypes.l5r = this.dice.some((term) => term instanceof L5rBaseDie); console.log("RollL5r5e.evaluate.out", this); // TODO tmp @@ -107,6 +76,21 @@ export class RollL5r5e extends Roll { return this; } + /** + * Summarise the total of success, strife... for L5R dices for the current roll + * + * @param term + * @private + */ + _l5rSummary(term) { + if (term instanceof L5rBaseDie) { + ["success", "explosive", "opportunity", "strife"].forEach((props) => { + this.l5r5e.summary[props] += parseInt(term.l5r5e[props]); + }); + // TODO Others advantage/disadvantage + } + } + /** * Return the total result of the Roll expression if it has been evaluated, otherwise null * @override @@ -133,7 +117,7 @@ export class RollL5r5e extends Roll { ["success", "explosive", "opportunity", "strife"] .map((props) => (summary[props] > 0 ? props + ": " + summary[props] : null)) .filter((c) => !!c) - .join(", "); + .join(" | "); } return total; @@ -180,6 +164,7 @@ export class RollL5r5e extends Roll { const chatData = { parts: parts, l5r5e: this.l5r5e, + displaySummary: contexte?.from !== "render", }; return renderTemplate(this.constructor.TOOLTIP_TEMPLATE, { chatData }); diff --git a/system/templates/dice/tooltip.html b/system/templates/dice/tooltip.html index dde23a4..f68e416 100644 --- a/system/templates/dice/tooltip.html +++ b/system/templates/dice/tooltip.html @@ -22,6 +22,7 @@ {{/each}} {{#if chatData.l5r5e.dicesTypes.l5r}} + {{#if chatData.displaySummary}} {{#chatData.l5r5e.summary}} {{/chatData.l5r5e.summary}} {{/if}} + {{/if}}