Skip to content

Commit

Permalink
fix #50
Browse files Browse the repository at this point in the history
  • Loading branch information
Grégory Soupé committed Nov 6, 2023
1 parent 6a97e3a commit de63329
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
30 changes: 15 additions & 15 deletions modules/WFRP3eRoll.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class WFRP3eRoll extends Roll

this.symbols = {
...Object.values(CONFIG.WFRP3e.symbols).reduce((object, symbol) => {
object[symbol.plural] = +dicePool[symbol.plural] ?? 0;
object[symbol.plural] = isNaN(dicePool[symbol.plural]) ? 0 : +dicePool[symbol.plural];
return object;
}, {})
};
Expand Down Expand Up @@ -57,7 +57,8 @@ export default class WFRP3eRoll extends Roll
/** @inheritDoc */
evaluate({minimize = false, maximize = false} = {})
{
if(this._evaluated) throw new Error("This Roll object has already been rolled.");
if(this._evaluated)
throw new Error("This Roll object has already been rolled.");

// Step 1 - evaluate any inner Rolls and recompile the formula
let hasInner = false;
Expand All @@ -79,9 +80,17 @@ export default class WFRP3eRoll extends Roll
this.terms = this._identifyTerms(formula);
}

// Step 3 - evaluate any remaining terms and return any non-FFG dialogs to the total.
// Step 3 - evaluate any remaining terms and return any non-special dialogs to the total.
this.results = this.terms.map((term) => {
if(!game.symbols.diceterms.includes(term.constructor)) {
if(game.symbols.diceterms.includes(term.constructor)) {
if(term.evaluate)
term.evaluate({minimize, maximize});

this.hasSpecialDice = true;

return 0;
}
else {
if(term.evaluate) {
if(!(term instanceof OperatorTerm))
this.hasStandardDice = true;
Expand All @@ -91,14 +100,6 @@ export default class WFRP3eRoll extends Roll
else
return term;
}
else {
if(term.evaluate)
term.evaluate({minimize, maximize});

this.hasSpecialDice = true;

return 0;
}
});

// Step 4 - safely evaluate the final total
Expand Down Expand Up @@ -239,7 +240,7 @@ export default class WFRP3eRoll extends Roll
};
}),
hasSpecialDice: this.hasSpecialDice,
hasStandard: this.hasStandardDice,
hasStandardDice: this.hasStandardDice,
hasSuccess: this.dice.length > 0,
data: this.data,
addedResults: this.addedResults,
Expand All @@ -262,7 +263,6 @@ export default class WFRP3eRoll extends Roll

if(["gmroll", "blindroll"].includes(rMode))
messageData.whisper = ChatMessage.getWhisperRecipients("GM");

if(rMode === "blindroll")
messageData.blind = true;
if(rMode === "selfroll")
Expand Down Expand Up @@ -295,7 +295,7 @@ export default class WFRP3eRoll extends Roll

json.symbols = this.symbols;
json.hasSpecialDice = this.hasSpecialDice;
json.hasStandard = this.hasStandardDice;
json.hasStandardDice = this.hasStandardDice;
json.data = this.data;
json.addedResults = this.addedResults;
json.flavor = this.flavor;
Expand Down
4 changes: 4 additions & 0 deletions styles/less/components/roll_message.less
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
}
}

.dice-total:not(:last-child) {
margin-bottom: 0.25rem;
}

.roll-effects {
& > h5 {
margin: 0;
Expand Down
3 changes: 3 additions & 0 deletions styles/wfrp3e.css
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,9 @@
.dice-tooltip .dice-rolls .roll > .special-die {
width: 44px;
}
.dice-total:not(:last-child) {
margin-bottom: 0.25rem;
}
.roll-effects > h5 {
margin: 0;
}
Expand Down
12 changes: 6 additions & 6 deletions templates/chatmessages/roll.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
<div class="dice-additional-flavor">{{data.additionalFlavourText}}</div>
{{/if}}

{{#if publicRoll }}
{{#if publicRoll}}
<div class="dice-result">
{{#if hasStandard}}
{{#if hasStandardDice}}
<div class="dice-formula">{{formula}}</div>
{{/if}}

{{#if hasStandardDice}}
<h4 class="dice-total">{{total}}</h4>
{{/if}}

{{#if hasSpecialDice}}
<div class="dice-array">
<ol class="dice-rolls">
Expand All @@ -33,10 +37,6 @@

{{{tooltip}}}

{{#if hasStandard}}
<h4 class="dice-total">{{total}}</h4>
{{/if}}

{{#if hasSpecialDice}}
<ul>
{{#if hasSuccess}}
Expand Down

0 comments on commit de63329

Please sign in to comment.