From 7f61715adf555ec724ac2540abfb0633b825c7d1 Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Wed, 22 Jul 2026 03:36:28 +0200 Subject: [PATCH] [Fix] Reload Fixes (#2099) --- lang/en.json | 11 ++- module/applications/ui/chatLog.mjs | 16 ++++- module/config/settingsConfig.mjs | 6 +- module/data/action/attackAction.mjs | 8 +-- module/data/chat-message/actorRoll.mjs | 19 +++-- module/data/settings/Automation.mjs | 2 +- module/dice/dhRoll.mjs | 8 ++- styles/less/ui/chat/chat.less | 96 ++++++++++++++++--------- templates/ui/chat/parts/button-part.hbs | 51 ++++++++----- templates/ui/chat/roll.hbs | 10 --- 10 files changed, 150 insertions(+), 77 deletions(-) diff --git a/lang/en.json b/lang/en.json index 7aa87c7a..232315c2 100755 --- a/lang/en.json +++ b/lang/en.json @@ -128,7 +128,12 @@ }, "Reload": { "checkReload": "Check Reload", - "reloadRequired": "Reload Required!" + "reloadRequired": "Reload Required!", + "notRolled": "Not Rolled", + "checkFailed": "Check Failed", + "checkPassed": "Check Passed", + "rerollConfirmationTitle": "Reroll Reload Check", + "rerollConfirmationText": "Are you sure you want to reload the reload check?" }, "RollField": { "diceRolling": { @@ -1328,7 +1333,7 @@ }, "ReloadChoices": { "off": { "label": "Don't Use" }, - "button": { "label": "Use button" }, + "manual": { "label": "Manual" }, "auto": { "label": "Automatic" } }, "RollTypes": { @@ -2820,7 +2825,7 @@ }, "reload": { "label": "Reload Checking", - "hint": "If the system should present a button for checking if the character will need to reload or do it automatically" + "hint": "If the system should automatically roll reload checks or wait for the manual press of a button in chat" }, "resourceScrollTexts": { "label": "Show Resource Change Scrolltexts", diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index 1ed4607f..5fb61857 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -287,7 +287,19 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo async onRollReloadCheck(_event, messageData) { const message = game.messages.get(messageData._id); - const needsReload = await message.system.action.handleReload?.({ awaitRoll: true }); - await message.update({ 'system.needsReload': needsReload }); + + if (message.system.reloadCheckValue) { + const confirmed = await foundry.applications.api.DialogV2.confirm({ + window: { + title: _loc('DAGGERHEART.ACTIONS.Reload.rerollConfirmationTitle') + }, + content: _loc('DAGGERHEART.ACTIONS.Reload.rerollConfirmationText') + }); + + if (!confirmed) return; + } + + const { rollValue } = await message.system.action.handleReload?.({ awaitRoll: true }); + await message.update({ 'system.reloadCheckValue': rollValue }); } } diff --git a/module/config/settingsConfig.mjs b/module/config/settingsConfig.mjs index daa89959..92a3361c 100644 --- a/module/config/settingsConfig.mjs +++ b/module/config/settingsConfig.mjs @@ -68,9 +68,9 @@ export const reloadChoices = { id: 'off', label: 'DAGGERHEART.CONFIG.ReloadChoices.off.label' }, - button: { - id: 'button', - label: 'DAGGERHEART.CONFIG.ReloadChoices.button.label' + manual: { + id: 'manual', + label: 'DAGGERHEART.CONFIG.ReloadChoices.manual.label' }, auto: { id: 'auto', diff --git a/module/data/action/attackAction.mjs b/module/data/action/attackAction.mjs index bf78520d..ba11c6ff 100644 --- a/module/data/action/attackAction.mjs +++ b/module/data/action/attackAction.mjs @@ -74,13 +74,13 @@ export default class DHAttackAction extends DHDamageAction { else game.dice3d.showForRoll(roll, game.user, true); } - - const needsToReload = roll.total === 1; - if (needsToReload) { + + const needsReload = roll.total === 1; + if (needsReload) { this.item.update({ 'system.resource.value': 0 }); } - return needsToReload; + return { needsReload, rollValue: roll.total }; } /** diff --git a/module/data/chat-message/actorRoll.mjs b/module/data/chat-message/actorRoll.mjs index 7071ed1e..3dcf2a8d 100644 --- a/module/data/chat-message/actorRoll.mjs +++ b/module/data/chat-message/actorRoll.mjs @@ -42,7 +42,7 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { hasEffect: new fields.BooleanField({ initial: false }), hasSave: new fields.BooleanField({ initial: false }), hasTarget: new fields.BooleanField({ initial: false }), - needsReload: new fields.BooleanField({ initial: false }), + reloadCheckValue: new fields.NumberField({ integer: true, nullable: true, initial: null }), isDirect: new fields.BooleanField({ initial: false }), onSave: new fields.StringField(), source: new fields.SchemaField({ @@ -76,10 +76,14 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { return fromUuidSync(this.source.actor); } - get actionItem() { + get item() { const actionActor = this.actionActor; if (!actionActor || !this.source.item) return null; + + return actionActor.items.get(this.source.item); + } + get actionItem() { switch (this.source.originItem.type) { case CONFIG.DH.ITEM.originItemType.restMove: const restMoves = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).restMoves; @@ -87,11 +91,18 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { this.source.originItem.actionIndex ]; default: - const item = actionActor.items.get(this.source.item); - return item ? item.system.actionsList?.find(a => a.id === this.source.action) : null; + return this.item?.system.actionsList?.find(a => a.id === this.source.action); } } + get hasReload() { + return this.item?.system.hasReload; + } + + get reloadCheckFailed() { + return this.reloadCheckValue === 1; + } + get action() { const { actionActor, actionItem: itemAction } = this; if (!this.source.action) return null; diff --git a/module/data/settings/Automation.mjs b/module/data/settings/Automation.mjs index e7bc0458..523ddaac 100644 --- a/module/data/settings/Automation.mjs +++ b/module/data/settings/Automation.mjs @@ -199,7 +199,7 @@ export default class DhAutomation extends foundry.abstract.DataModel { reload: new fields.StringField({ required: true, choices: CONFIG.DH.SETTINGS.reloadChoices, - initial: CONFIG.DH.SETTINGS.reloadChoices.button.id, + initial: CONFIG.DH.SETTINGS.reloadChoices.manual.id, label: 'DAGGERHEART.SETTINGS.Automation.FIELDS.reload.label', hint: 'DAGGERHEART.SETTINGS.Automation.FIELDS.reload.hint' }), diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 62d9ff9f..68185984 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -139,7 +139,7 @@ export default class DHRoll extends BaseRoll { item?.system.hasReload && action?.type === 'attack' && reloadSetting === CONFIG.DH.SETTINGS.reloadChoices.auto.id; - const needsReload = useReload ? await action?.handleReload?.() : false; + const reloadResult = useReload ? await action?.handleReload?.() : {}; const cls = getDocumentClass('ChatMessage'), msgData = { @@ -148,7 +148,11 @@ export default class DHRoll extends BaseRoll { title: roll.title, speaker: cls.getSpeaker({ actor: roll.data?.parent }), sound: config.mute ? null : CONFIG.sounds.dice, - system: { ...config, actionDescription, needsReload }, + system: { + ...config, + actionDescription, + reloadCheckValue: reloadResult.rollValue + }, rolls: [roll] }; diff --git a/styles/less/ui/chat/chat.less b/styles/less/ui/chat/chat.less index 8c3f4b08..1b18a823 100644 --- a/styles/less/ui/chat/chat.less +++ b/styles/less/ui/chat/chat.less @@ -271,28 +271,6 @@ } } - .roll-reload-container { - text-align: center; - display: flex; - align-items: center; - justify-content: center; - gap: 4px; - - .reload-warning { - display: flex; - align-items: center; - border-radius: 5px; - width: fit-content; - gap: 5px; - cursor: pointer; - padding: 5px; - transition: all 0.3s ease; - color: @beige; - background: @red-40; - outline: 1px solid @red; - } - } - .roll-part-extra { display: flex; justify-content: center; @@ -643,20 +621,74 @@ } .roll-buttons { - display: flex; - flex-wrap: wrap; - gap: 5px; - width: 100%; margin-top: 8px; + display: flex; + flex-direction: column; + gap: 5px; button { - height: 36px; - flex: 1 1 calc(50% - 5px); - font-family: @font-body; - font-weight: 700; + height: 32px; + } - &:nth-last-child(1):nth-child(odd) { - flex-basis: 100%; + .main-buttons { + display: flex; + gap: 5px; + + button { + flex: 1; + + &.end-button { + flex: 0; + } + } + } + + .extra-button-row { + width: 100%; + display: flex; + gap: 5px; + + .image-container { + position: relative; + display: flex; + align-items: center; + justify-content: center; + + img { + height: 24px; + filter: @dark-filter; + } + + .dice-result { + position: absolute; + font-size: 18px; + color: @beige; + filter: drop-shadow(0 0 1px @light-white); + } + } + + .reload-data { + flex: 1; + display: flex; + align-items: center; + justify-content: center; + border-radius: 5px; + gap: 5px; + cursor: pointer; + padding: 5px; + transition: all 0.3s ease; + color: @golden; + background: @golden-40; + + &.failed-check { + background: @red-40; + color: @red; + } + + &.passed-check { + background: @green-40; + color: @green; + } } } } diff --git a/templates/ui/chat/parts/button-part.hbs b/templates/ui/chat/parts/button-part.hbs index b631192c..6dc39804 100644 --- a/templates/ui/chat/parts/button-part.hbs +++ b/templates/ui/chat/parts/button-part.hbs @@ -1,21 +1,40 @@
\ No newline at end of file diff --git a/templates/ui/chat/roll.hbs b/templates/ui/chat/roll.hbs index ab4e197e..362aeadd 100644 --- a/templates/ui/chat/roll.hbs +++ b/templates/ui/chat/roll.hbs @@ -1,15 +1,5 @@{{localize "DAGGERHEART.ACTIONS.Reload.reloadRequired"}}
- {{/if}} -