diff --git a/daggerheart.mjs b/daggerheart.mjs index 21c62365..e223865d 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -13,6 +13,7 @@ import { dualityRollEnricher } from './module/enrichers/DualityRollEnricher.mjs' import { getCommandTarget, rollCommandToJSON, setDiceSoNiceForDualityRoll } from './module/helpers/utils.mjs'; import { abilities } from './module/config/actorConfig.mjs'; import Resources from './module/applications/resources.mjs'; +import DHDualityRoll from './module/data/chat-message/dualityRoll.mjs'; globalThis.SYSTEM = SYSTEM; @@ -137,22 +138,28 @@ const renderDualityButton = async event => { title: button.dataset.label, value: rollModifier }); + + const systemData = new DHDualityRoll({ + title: button.dataset.label, + origin: target.id, + roll: roll._formula, + modifiers: modifiers, + hope: hope, + fear: fear, + advantage: advantage, + disadvantage: disadvantage + }); + const cls = getDocumentClass('ChatMessage'); const msgData = { type: 'dualityRoll', sound: CONFIG.sounds.dice, - system: { - title: button.dataset.label, - origin: target.id, - roll: roll._formula, - modifiers: modifiers, - hope: hope, - fear: fear, - advantage: advantage, - disadvantage: disadvantage - }, + system: systemData, user: game.user.id, - content: 'systems/daggerheart/templates/chat/duality-roll.hbs', + content: await foundry.applications.handlebars.renderTemplate( + 'systems/daggerheart/templates/chat/duality-roll.hbs', + systemData + ), rolls: [roll] }; @@ -226,29 +233,34 @@ Hooks.on('chatMessage', (_, message) => { : undefined, title }); - }).then(({ roll, attribute, title }) => { + }).then(async ({ roll, attribute, title }) => { const cls = getDocumentClass('ChatMessage'); + const systemData = new DHDualityRoll({ + title: title, + origin: target?.id, + roll: roll._formula, + modifiers: attribute ? [attribute] : [], + hope: { dice: rollCommand.hope ?? 'd12', value: roll.dice[0].total }, + fear: { dice: rollCommand.fear ?? 'd12', value: roll.dice[1].total }, + advantage: + rollCommand.advantage && !rollCommand.disadvantage + ? { dice: 'd6', value: roll.dice[2].total } + : undefined, + disadvantage: + rollCommand.disadvantage && !rollCommand.advantage + ? { dice: 'd6', value: roll.dice[2].total } + : undefined + }); + const msgData = { type: 'dualityRoll', sound: CONFIG.sounds.dice, - system: { - title: title, - origin: target?.id, - roll: roll._formula, - modifiers: attribute ? [attribute] : [], - hope: { dice: rollCommand.hope ?? 'd12', value: roll.dice[0].total }, - fear: { dice: rollCommand.fear ?? 'd12', value: roll.dice[1].total }, - advantage: - rollCommand.advantage && !rollCommand.disadvantage - ? { dice: 'd6', value: roll.dice[2].total } - : undefined, - disadvantage: - rollCommand.disadvantage && !rollCommand.advantage - ? { dice: 'd6', value: roll.dice[2].total } - : undefined - }, + system: systemData, user: game.user.id, - content: 'systems/daggerheart/templates/chat/duality-roll.hbs', + content: await foundry.applications.handlebars.renderTemplate( + 'systems/daggerheart/templates/chat/duality-roll.hbs', + systemData + ), rolls: [roll] }; diff --git a/module/applications/chatMessage.mjs b/module/applications/chatMessage.mjs index 30bd0a27..aef05bae 100644 --- a/module/applications/chatMessage.mjs +++ b/module/applications/chatMessage.mjs @@ -1,12 +1,8 @@ import { DualityRollColor } from '../data/settings/Appearance.mjs'; -import DHDualityRoll from "../data/chat-message/dualityRoll.mjs"; +import DHDualityRoll from '../data/chat-message/dualityRoll.mjs'; export default class DhpChatMessage extends foundry.documents.ChatMessage { async renderHTML() { - if (this.type === 'dualityRoll' || this.type === 'adversaryRoll' || this.type === 'abilityUse') { - this.content = await foundry.applications.handlebars.renderTemplate(this.content, this.system); - } - /* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */ const html = await super.renderHTML(); diff --git a/module/applications/rollSelectionDialog.mjs b/module/applications/rollSelectionDialog.mjs index 66ec0d1e..e97d7cf1 100644 --- a/module/applications/rollSelectionDialog.mjs +++ b/module/applications/rollSelectionDialog.mjs @@ -62,12 +62,8 @@ export default class RollSelectionDialog extends HandlebarsApplicationMixin(Appl context.fear = this.data.fear; context.advantage = this.data.advantage; context.disadvantage = this.data.disadvantage; - context.experiences = this.experiences.map(x => ({ - ...x, - selected: this.selectedExperiences.includes(x.id) - })); + context.experiences = Object.keys(this.experiences).map(id => ({ id, ...this.experiences[id] })); context.hopeResource = this.data.hopeResource + 1; - context.hopeUsed = this.getHopeUsed(); return context; } diff --git a/module/applications/sheets/character.mjs b/module/applications/sheets/character.mjs index c7430a36..3d076d57 100644 --- a/module/applications/sheets/character.mjs +++ b/module/applications/sheets/character.mjs @@ -5,6 +5,7 @@ import AncestrySelectionDialog from '../ancestrySelectionDialog.mjs'; import DaggerheartSheet from './daggerheart-sheet.mjs'; import { abilities } from '../../config/actorConfig.mjs'; import DhlevelUp from '../levelup.mjs'; +import DHDualityRoll from '../../data/chat-message/dualityRoll.mjs'; const { ActorSheetV2 } = foundry.applications.sheets; const { TextEditor } = foundry.applications.ux; @@ -286,7 +287,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) { const cls = getDocumentClass('ChatMessage'); - const systemContent = { + const systemContent = new DHDualityRoll({ title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', { ability: game.i18n.localize(abilities[button.dataset.attribute].label) }), @@ -297,9 +298,9 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) { fear: fear, advantage: advantage, disadvantage: disadvantage - }; + }); - const msg = new cls({ + await cls.create({ type: 'dualityRoll', sound: CONFIG.sounds.dice, system: systemContent, @@ -310,8 +311,6 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) { ), rolls: [roll] }); - - await cls.create(msg.toObject()); } static async toggleMarks(_, button) { @@ -368,7 +367,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) { evasion: x.actor.system.evasion })); - const systemData = { + const systemData = new DHDualityRoll({ title: weapon.name, origin: this.document.id, roll: roll._formula, @@ -379,7 +378,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) { disadvantage: disadvantage, damage: damage, targets: targets - }; + }); const cls = getDocumentClass('ChatMessage'); const msg = new cls({