Skip to content

Commit

Permalink
fix: change renderChatMessage hook to obfuscate hidden rolls properly
Browse files Browse the repository at this point in the history
Currently private dice rolls show the effect to everyone instead of obfuscating it. This change
hides the effect and does not colorize the result if the user is not allowed to view it. There was
also a bug ignoring the user's choice of roll mode in the roll dialog, which this commit fixes.

Fix xdy#321
  • Loading branch information
jonepatr authored and xdy committed Jan 29, 2021
1 parent 0d77caa commit e639e01
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/module/hooks/renderChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ Hooks.on('renderChatMessage', (app, html) => {
});
}

if (!damageMessage) {
const diceTotal = html.find(".dice-total");

// Add effect
diceTotal.text(`${game.i18n.localize('TWODSIX.Rolls.sum').capitalize()}: ${diceTotal.text()} ${game.i18n.localize('TWODSIX.Rolls.Effect')}: ${app.getFlag("twodsix", "effect")}`);
const diceTotal = html.find(".dice-total");
if (!damageMessage && diceTotal.length > 0 && app.isContentVisible) {
const effect = app.getFlag("twodsix", "effect");
if (!isNaN(effect)) {
const sumString = game.i18n.localize('TWODSIX.Rolls.sum').capitalize();
const effectString = game.i18n.localize('TWODSIX.Rolls.Effect');
diceTotal.text(`${sumString}: ${diceTotal.text()} ${effectString}: ${effect}`);
}

// Color crits
if (diceTotal.length > 0) {
const crit = app.getFlag("twodsix", "crit");
if (crit && crit == Crit.success) {
diceTotal.addClass("crit-success-roll");
} else if (crit && crit == Crit.fail) {
diceTotal.addClass("crit-fail-roll");
}
const crit = app.getFlag("twodsix", "crit");
if (crit && crit == Crit.success) {
diceTotal.addClass("crit-success-roll");
} else if (crit && crit == Crit.fail) {
diceTotal.addClass("crit-fail-roll");
}
}
});
2 changes: 1 addition & 1 deletion src/module/utils/TwodsixDiceRoll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class TwodsixDiceRoll {
{
speaker: ChatMessage.getSpeaker({actor: this.actor}),
flavor: flavor,
rollType: this.settings.rollType,
rollMode: this.settings.rollMode,
flags: {
"core.canPopout": true,
"twodsix.crit": this.getCrit(),
Expand Down

0 comments on commit e639e01

Please sign in to comment.