update for inline roll [2ds+1d8]

This commit is contained in:
Vlyan
2020-12-08 14:38:55 +01:00
parent 7717ec3bcc
commit 4b7f30035c
3 changed files with 109 additions and 52 deletions

View File

@@ -25,7 +25,6 @@ export class RollL5r5e extends Roll {
}, },
summary: { summary: {
difficulty: 0, difficulty: 0,
success_total: 0,
success: 0, success: 0,
explosive: 0, explosive: 0,
opportunity: 0, opportunity: 0,
@@ -71,7 +70,6 @@ export class RollL5r5e extends Roll {
["success", "explosive", "opportunity", "strife"].forEach((props) => { ["success", "explosive", "opportunity", "strife"].forEach((props) => {
this.l5r5e.summary[props] += parseInt(term.l5r5e[props]); this.l5r5e.summary[props] += parseInt(term.l5r5e[props]);
}); });
this.l5r5e.summary.success_total += parseInt(term.l5r5e.success);
} }
}); });
@@ -85,7 +83,6 @@ export class RollL5r5e extends Roll {
["success", "explosive", "opportunity", "strife"].forEach((props) => { ["success", "explosive", "opportunity", "strife"].forEach((props) => {
this.l5r5e.summary[props] += parseInt(term.l5r5e[props]); this.l5r5e.summary[props] += parseInt(term.l5r5e[props]);
}); });
this.l5r5e.summary.success_total += parseInt(term.l5r5e.success);
// re-inject L5R dices // re-inject L5R dices
this.terms.push("+"); this.terms.push("+");
@@ -111,40 +108,79 @@ export class RollL5r5e extends Roll {
} }
/** /**
* Render the tooltip HTML for a Roll instance * Return the total result of the Roll expression if it has been evaluated, otherwise null
* @override
*/
get total() {
if (!this._rolled) {
return null;
}
let total = "";
// Regular dices total (eg 6)
if (this.l5r5e.dicesTypes.std) {
total = this._total;
}
// Add L5R summary
if (this.l5r5e.dicesTypes.l5r) {
const summary = this.l5r5e.summary;
// TODO i18n lang trad or symbols
total +=
(this.l5r5e.dicesTypes.std ? " | " : "") +
["success", "explosive", "opportunity", "strife"]
.map((props) => (summary[props] > 0 ? props + ": " + summary[props] : null))
.filter((c) => !!c)
.join(", ");
}
return total;
}
/**
* Render the tooltip HTML for a Roll instance and inner rolls (eg [[2ds]])
* @override * @override
*/ */
getTooltip() { getTooltip() {
const parts = this.dice const parts = this.dice.map((term) => {
.filter((t) => !(t instanceof L5rBaseDie)) const cls = term.constructor;
.map((d) => { const isL5rDie = term instanceof L5rBaseDie;
const cls = d.constructor;
return { return {
formula: d.formula, formula: term.formula,
total: d.total, total: term.total,
faces: d.faces, faces: term.faces,
flavor: d.options.flavor, flavor: term.options.flavor,
isL5rDices: d.constructor instanceof L5rBaseDie, isDieL5r: isL5rDie,
rolls: d.results.map((r) => { isDieStd: !isL5rDie,
return { rolls: term.results.map((r) => {
result: cls.getResultLabel(r.result), return {
classes: [ result: cls.getResultLabel(r.result),
cls.name.toLowerCase(), classes: [
"d" + d.faces, cls.name.toLowerCase(),
r.rerolled ? "rerolled" : null, "d" + term.faces,
r.exploded ? "exploded" : null, !isL5rDie && r.rerolled ? "rerolled" : null,
r.discarded ? "discarded" : null, !isL5rDie && r.exploded ? "exploded" : null,
r.result === 1 ? "min" : null, !isL5rDie && r.discarded ? "discarded" : null,
r.result === d.faces ? "max" : null, !isL5rDie && r.result === 1 ? "min" : null,
] !isL5rDie && r.result === term.faces ? "max" : null,
.filter((c) => !!c) ]
.join(" "), .filter((c) => !!c)
}; .join(" "),
}), };
}; }),
}); };
});
parts.addedResults = this.addedResults; parts.addedResults = this.addedResults;
return renderTemplate(this.constructor.TOOLTIP_TEMPLATE, { parts });
const chatData = {
parts: parts,
l5r5e: this.l5r5e,
};
return renderTemplate(this.constructor.TOOLTIP_TEMPLATE, { chatData });
} }
/** /**

View File

@@ -23,7 +23,7 @@
{{#l5r5e.summary}} {{#l5r5e.summary}}
<ul> <ul>
<li>Successes: {{this.success_total}}</li> <li>Successes: {{this.success}}</li>
{{#if opportunity}} {{#if opportunity}}
<li>Opportunities: {{this.opportunity}}</li> <li>Opportunities: {{this.opportunity}}</li>

View File

@@ -1,20 +1,41 @@
<div class="dice-tooltip"> <div class="dice-tooltip">
{{#each parts}} {{#each chatData.parts}}
<section class="tooltip-part"> <section class="tooltip-part">
<div class="dice"> <div class="dice">
<header class="part-header flexrow"> <header class="part-header flexrow">
<span class="part-formula">{{this.formula}}</span> <span class="part-formula">{{this.formula}}</span>
{{#if this.flavor}}<span class="part-flavor">{{this.flavor}}</span>{{/if}} <span class="part-total">{{this.total}}</span> {{#if this.flavor}}<span class="part-flavor">{{this.flavor}}</span>{{/if}}
</header> {{#if this.isDieStd}}<span class="part-total">{{this.total}}</span>{{/if}}
<ol class="dice-rolls"> </header>
{{#each this.rolls}} <ol class="dice-rolls">
<li class="roll {{this.classes}}">{{{this.result}}}</li> {{#each this.rolls}}
{{/each}} <li class="roll {{this.classes}}">{{{this.result}}}</li>
</ol> {{/each}}
<ol class="dice-rolls"> </ol>
<li class="roll">{{{addedResults.success}}}</li> <ol class="dice-rolls">
</ol> <li class="roll">{{{addedResults.success}}}</li>
</div> </ol>
</section> </div>
{{/each}} </section>
{{/each}}
{{#if chatData.l5r5e.dicesTypes.l5r}}
{{#chatData.l5r5e.summary}}
<ul>
<li>Successes: {{this.success}}</li>
{{#if opportunity}}
<li>Opportunities: {{this.opportunity}}</li>
{{/if}}
{{#if strife}}
<li>Strife: {{this.strife}}</li>
{{/if}}
{{#if difficulty}}
<li>Difficulty: {{this.difficulty}}</li>
{{/if}}
</ul>
{{/chatData.l5r5e.summary}}
{{/if}}
</div> </div>