From 045754d107295eccf4580b66be03651f36e58f53 Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Tue, 15 Jul 2025 17:01:17 +0200 Subject: [PATCH] [Feature] 340-341 RollMode & ChatSpeaker (#347) * Added RollMode to standalone DamageDialog and to RollDialog. ChatMessage now add ChatSpeaker * Just a little fix for Damage Action --------- Co-authored-by: Dapoolp --- lang/en.json | 1 + module/applications/dialogs/d20RollDialog.mjs | 14 +++-- module/applications/dialogs/damageDialog.mjs | 12 ++++- module/applications/ui/chatLog.mjs | 2 +- module/data/action/baseAction.mjs | 3 +- module/data/action/damageAction.mjs | 13 +++-- module/dice/dhRoll.mjs | 2 +- module/documents/chatMessage.mjs | 11 ++++ .../less/dialog/damage-selection/sheet.less | 54 ++++++++++++------- .../less/dialog/dice-roll/roll-selection.less | 14 +++++ .../dialogs/dice-roll/damageSelection.hbs | 15 ++++-- templates/dialogs/dice-roll/rollSelection.hbs | 13 +++-- 12 files changed, 112 insertions(+), 42 deletions(-) diff --git a/lang/en.json b/lang/en.json index 3bf99e3a..b9e0fefa 100755 --- a/lang/en.json +++ b/lang/en.json @@ -1231,6 +1231,7 @@ "quantity": "Quantity", "range": "Range", "recovery": "Recovery", + "roll": "Roll", "scalable": "Scalable", "stress": "Stress", "take": "Take", diff --git a/module/applications/dialogs/d20RollDialog.mjs b/module/applications/dialogs/d20RollDialog.mjs index 6cb0761c..7987dd6b 100644 --- a/module/applications/dialogs/d20RollDialog.mjs +++ b/module/applications/dialogs/d20RollDialog.mjs @@ -64,6 +64,13 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio context.rollConfig = this.config; context.hasRoll = !!this.config.roll; context.canRoll = true; + context.selectedRollMode = this.config.selectedRollMode; + context.rollModes = Object.entries(CONFIG.Dice.rollModes).map(([action, { label, icon }]) => ({ + action, + label, + icon + })); + if (this.config.costs?.length) { const updatedCosts = this.action.calcCosts(this.config.costs); context.costs = updatedCosts.map(x => ({ @@ -99,6 +106,8 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio static updateRollConfiguration(event, _, formData) { const { ...rest } = foundry.utils.expandObject(formData.object); + this.config.selectedRollMode = rest.selectedRollMode; + if (this.config.costs) { this.config.costs = foundry.utils.mergeObject(this.config.costs, rest.costs); } @@ -122,11 +131,6 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio } static selectExperience(_, button) { - /* if (this.config.experiences.find(x => x === button.dataset.key)) { - this.config.experiences = this.config.experiences.filter(x => x !== button.dataset.key); - } else { - this.config.experiences = [...this.config.experiences, button.dataset.key]; - } */ this.config.experiences = this.config.experiences.indexOf(button.dataset.key) > -1 ? this.config.experiences.filter(x => x !== button.dataset.key) diff --git a/module/applications/dialogs/damageDialog.mjs b/module/applications/dialogs/damageDialog.mjs index 4030d7a7..70dcace8 100644 --- a/module/applications/dialogs/damageDialog.mjs +++ b/module/applications/dialogs/damageDialog.mjs @@ -48,12 +48,22 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application : game.i18n.localize('DAGGERHEART.EFFECTS.ApplyLocations.damageRoll.name'); context.extraFormula = this.config.extraFormula; context.formula = this.roll.constructFormula(this.config); + context.directDamage = this.config.directDamage; + context.selectedRollMode = this.config.selectedRollMode; + context.rollModes = Object.entries(CONFIG.Dice.rollModes).map(([action, { label, icon }]) => ({ + action, + label, + icon + })); + return context; } - static updateRollConfiguration(event, _, formData) { + static updateRollConfiguration(_event, _, formData) { const { ...rest } = foundry.utils.expandObject(formData.object); this.config.extraFormula = rest.extraFormula; + this.config.selectedRollMode = rest.selectedRollMode; + this.render(); } diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index aa604dda..4570b076 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -88,7 +88,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo onRollDamage = async (event, message) => { event.stopPropagation(); const actor = await this.getActor(message.system.source.actor); - if (!actor || !game.user.isGM) return true; + if (game.user.character?.id !== actor.id && !game.user.isGM) return true; if (message.system.source.item && message.system.source.action) { const action = this.getAction(actor, message.system.source.item, message.system.source.action); if (!action || !action?.rollDamage) return; diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index 39051434..a46b0a85 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -268,7 +268,8 @@ export default class DHBaseAction extends foundry.abstract.DataModel { hasDamage: !!this.damage?.parts?.length, hasHealing: !!this.healing, hasEffect: !!this.effects?.length, - hasSave: this.hasSave + hasSave: this.hasSave, + selectedRollMode: game.settings.get('core', 'rollMode') }; } diff --git a/module/data/action/damageAction.mjs b/module/data/action/damageAction.mjs index 492c4184..388c5eb8 100644 --- a/module/data/action/damageAction.mjs +++ b/module/data/action/damageAction.mjs @@ -10,6 +10,7 @@ export default class DHDamageAction extends DHBaseAction { } async rollDamage(event, data) { + const systemData = data.system ?? data; let formula = this.damage.parts.map(p => this.getFormulaValue(p, data).getFormula(this.actor)).join(' + '), damageTypes = [...new Set(this.damage.parts.reduce((a, c) => a.concat([...c.type]), []))]; @@ -19,15 +20,15 @@ export default class DHDamageAction extends DHBaseAction { let roll = { formula: formula, total: formula }, bonusDamage = []; - if (isNaN(formula)) formula = Roll.replaceFormulaData(formula, this.getRollData(data.system ?? data)); - + if (isNaN(formula)) formula = Roll.replaceFormulaData(formula, this.getRollData(systemData)); + const config = { title: game.i18n.format('DAGGERHEART.UI.Chat.damageRoll.title', { damage: this.name }), roll: { formula }, - targets: data.system?.targets.filter(t => t.hit) ?? data.targets, + targets: systemData.targets.filter(t => t.hit) ?? data.targets, hasSave: this.hasSave, - isCritical: data.system?.roll?.isCritical ?? false, - source: data.system?.source, + isCritical: systemData.roll?.isCritical ?? false, + source: systemData.source, data: this.getRollData(), damageTypes, event @@ -36,6 +37,8 @@ export default class DHDamageAction extends DHBaseAction { if (data.system) { config.source.message = data._id; config.directDamage = false; + } else { + config.directDamage = true; } roll = CONFIG.Dice.daggerheart.DamageRoll.build(config); diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 22f5bb28..27288f15 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -87,7 +87,7 @@ export default class DHRoll extends Roll { system: config, rolls: [roll] }; - return await cls.create(msg); + return await cls.create(msg, { rollMode: config.selectedRollMode }); } static applyKeybindings(config) { diff --git a/module/documents/chatMessage.mjs b/module/documents/chatMessage.mjs index ef76d18f..409b4dd0 100644 --- a/module/documents/chatMessage.mjs +++ b/module/documents/chatMessage.mjs @@ -37,4 +37,15 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage { e.setAttribute('data-use-perm', document.testUserPermission(game.user, 'OWNER')); }); } + + async _preCreate(data, options, user) { + options.speaker = ChatMessage.getSpeaker(); + const rollActorOwner = data.rolls?.[0]?.data?.parent?.owner; + if (rollActorOwner) { + data.author = rollActorOwner ? rollActorOwner.id : data.author; + await this.updateSource({ author: rollActorOwner ?? user }); + } + + return super._preCreate(data, options, rollActorOwner ?? user); + } } diff --git a/styles/less/dialog/damage-selection/sheet.less b/styles/less/dialog/damage-selection/sheet.less index 43e4f4d2..461fb0b5 100644 --- a/styles/less/dialog/damage-selection/sheet.less +++ b/styles/less/dialog/damage-selection/sheet.less @@ -1,20 +1,34 @@ -@import '../../utils/colors.less'; - -.daggerheart.dialog.dh-style.views.damage-selection { - .damage-section-container { - display: flex; - flex-direction: column; - gap: 12px; - - input[type='text'], - input[type='number'] { - color: light-dark(@dark, @beige); - outline: 2px solid transparent; - transition: all 0.3s ease; - - &:hover { - outline: 2px solid light-dark(@dark, @beige); - } - } - } -} +@import '../../utils/colors.less'; + +.daggerheart.dialog.dh-style.views.damage-selection { + .damage-section-container { + display: flex; + flex-direction: column; + gap: 12px; + + input[type='text'], + input[type='number'] { + color: light-dark(@dark, @beige); + outline: 2px solid transparent; + transition: all 0.3s ease; + + &:hover { + outline: 2px solid light-dark(@dark, @beige); + } + } + + .damage-section-controls { + display: flex; + align-items: center; + gap: 16px; + + .roll-mode-select { + width: min-content; + } + + button { + flex: 1; + } + } + } +} diff --git a/styles/less/dialog/dice-roll/roll-selection.less b/styles/less/dialog/dice-roll/roll-selection.less index 575b7ce9..14bccf3d 100644 --- a/styles/less/dialog/dice-roll/roll-selection.less +++ b/styles/less/dialog/dice-roll/roll-selection.less @@ -114,5 +114,19 @@ } } } + + .roll-dialog-controls { + display: flex; + align-items: center; + gap: 16px; + + .roll-mode-select { + width: min-content; + } + + button { + flex: 1; + } + } } } diff --git a/templates/dialogs/dice-roll/damageSelection.hbs b/templates/dialogs/dice-roll/damageSelection.hbs index 0286990e..bd97cfdf 100644 --- a/templates/dialogs/dice-roll/damageSelection.hbs +++ b/templates/dialogs/dice-roll/damageSelection.hbs @@ -6,8 +6,15 @@
- +
+ {{#if directDamage}} + + {{/if}} + +
\ No newline at end of file diff --git a/templates/dialogs/dice-roll/rollSelection.hbs b/templates/dialogs/dice-roll/rollSelection.hbs index 5c0ba41d..11fce27a 100644 --- a/templates/dialogs/dice-roll/rollSelection.hbs +++ b/templates/dialogs/dice-roll/rollSelection.hbs @@ -117,10 +117,15 @@ {{/unless}} Formula: {{@root.formula}} - +
+ + +
{{else}}