Skip to content

Commit

Permalink
Merge pull request #954 from Muttley/953-dice-so-nice-not-honouring-r…
Browse files Browse the repository at this point in the history
…oll-modes-in-shadowdark

953 dice so nice not honouring roll modes in shadowdark
  • Loading branch information
Muttley authored Nov 18, 2024
2 parents 8f26207 + dcdf8c8 commit 2ec114f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 29 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* [#930] Class Abilities can't be used if they have no associated skill roll
* [#936] Character Generator: Don't display empty alignment for Deities that don't have one
* [#938] Unecessary line breaks in Farsight talent descriptions
* [#953] Dice So Nice not honouring roll modes in Shadowdark

## Chores
* [#911] Replaced compendium art mapping with default Foundry method. *(Settings for compendium art mapping are now found in *Settings > Core > Compendium Art*)*
Expand Down
45 changes: 41 additions & 4 deletions system/src/dice/RollSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -715,20 +715,57 @@ export default class RollSD extends Roll {
rollsToShow.push(rolls.secondaryDamage.roll);
}

// TODO Make sure we honor the whisper and/or blind settings of the roll
//
const { whisper, blind } = this.getRollModeSettings();

// Only await on the final dice roll of the sequence as it looks nicer
// if all the dice roll before the chat message appears
//
const numRolls = rollsToShow.length;
let currentRoll = 1;
for (const roll of rollsToShow) {
if (currentRoll === numRolls) {
await game.dice3d.showForRoll(roll, game.user, true);
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
}
else {
game.dice3d.showForRoll(roll, game.user, true);
game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
}
currentRoll++;
}
}


static getRollModeSettings() {
const rollMode = game.settings.get("core", "rollMode");

let blind = false;
let whisper = null;

switch (rollMode) {
case "blindroll": {
blind = true;
}
case "gmroll": {
const gmList = game.users.filter(user => user.isGM);
const gmIDList = [];
gmList.forEach(gm => gmIDList.push(gm.id));
whisper = gmIDList;
break;
}
case "roll": {
const userList = game.users.filter(user => user.active);
const userIDList = [];
userList.forEach(user => userIDList.push(user.id));
whisper = userIDList;
break;
}
case "selfroll": {
whisper = [game.user.id];
break;
}
default: {
break;
}
}
return { whisper, blind };
}
}
8 changes: 2 additions & 6 deletions system/src/documents/ActorSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ export default class ActorSD extends Actor {

const title = game.i18n.localize("SHADOWDARK.chat.spell_learn.title");

const messageStyles = shadowdark.utils.getMessageStyles();

await ChatMessage.create({
title,
content,
flags: { "core.canPopout": true },
flavor: title,
speaker: ChatMessage.getSpeaker({ actor: this, token: this.token }),
type: messageStyles.OTHER,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
user: game.user.id,
});

Expand Down Expand Up @@ -1489,15 +1487,13 @@ export default class ActorSD extends Actor {

const content = await renderTemplate(template, cardData);

const messageStyles = shadowdark.utils.getMessageStyles();

await ChatMessage.create({
title,
content,
flags: { "core.canPopout": true },
flavor: title,
speaker: ChatMessage.getSpeaker({actor: this, token: this.token}),
type: messageStyles.OTHER,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
user: game.user.id,
});

Expand Down
6 changes: 2 additions & 4 deletions system/src/documents/ItemSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ export default class ItemSD extends Item {

const html = await renderTemplate(template, templateData);

const messageStyles = shadowdark.utils.getMessageStyles();

const chatData = {
user: game.user.id,
type: messageStyles.OTHER,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
content: html,
flavor: this.system.chatFlavor || this.name,
flavor: this.name,
speaker: ChatMessage.getSpeaker({actor: this.actor, token}),
flags: { "core.canPopout": true },
};
Expand Down
11 changes: 5 additions & 6 deletions system/src/system/ChatSD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ export default class ChatSD {
mode = game.settings.get("core", "rollMode");
}

const messageStyles = shadowdark.utils.getMessageStyles();

const chatData = {
user: game.user.id,
content: html,
flags: { "core.canPopout": true },
rollMode: mode,
speaker: ChatMessage.getSpeaker({
actor: actor,
}),
rollMode: mode,
content: html,
type: messageStyles.OTHER,
type: CONST.CHAT_MESSAGE_STYLES.OTHER,
user: game.user.id,
};

ChatMessage.applyRollMode(chatData, mode);
Expand Down
9 changes: 0 additions & 9 deletions system/src/utils/UtilitySD.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,6 @@ export default class UtilitySD {
}


static getMessageStyles() {
const messageStyles = this.foundryMinVersion(12)
? CONST.CHAT_MESSAGE_STYLES
: CONST.CHAT_MESSAGE_TYPES;

return messageStyles;
}


static getNextDieInList(die, allDice) {
if (die === false) return die;

Expand Down

0 comments on commit 2ec114f

Please sign in to comment.