From fbcb9e4572864e998fa8e0309df9c38ba1045484 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Fri, 17 Jul 2026 14:10:06 +0200 Subject: [PATCH] Moved DamageTypes to roll.options --- module/applications/ui/chatLog.mjs | 4 +- module/data/chat-message/actorRoll.mjs | 17 +++-- module/data/chat-message/chatDamageData.mjs | 11 +-- module/dice/damageRoll.mjs | 8 +- .../parts/tagTeamDamageParts.hbs | 35 +++++---- templates/ui/chat/parts/damage-part.hbs | 73 +++++++++---------- 6 files changed, 72 insertions(+), 76 deletions(-) diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index 60b6cceb..1c462930 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -258,9 +258,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo await message.system.damage.rerollDamageDie(damageType, dice, result); await message.update({ 'system.damage.types': { - [damageType]: { - roll: message.system.damage.types[damageType].roll.toJSON() - } + [damageType]: message.system.damage.types[damageType].toJSON() } }); } else { diff --git a/module/data/chat-message/actorRoll.mjs b/module/data/chat-message/actorRoll.mjs index c2655610..0b5d2678 100644 --- a/module/data/chat-message/actorRoll.mjs +++ b/module/data/chat-message/actorRoll.mjs @@ -140,9 +140,9 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { const update = { system: { damage: { types: {} } } }; for (const key of Object.keys(this.damage.types)) { const type = this.damage.types[key]; - const reroll = await type.roll.reroll(); + const reroll = await type.reroll(); rerolls.push(reroll); - update.system.damage.types[key] = { roll: reroll.toJSON() }; + update.system.damage.types[key] = reroll.toJSON(); } await triggerChatRollFx(rerolls); @@ -192,10 +192,15 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel { source.damage = { types: Object.keys(source.damage).reduce((acc, key) => { const damageData = source.damage[key]; - acc[key] = { - roll: damageData.parts[0]?.roll ?? null, - damageTypes: damageData.parts[0]?.damageTypes ?? [] - }; + const oldRoll = damageData.parts[0]?.roll; + acc[key] = oldRoll ? { + ...oldRoll, + options: { + ...oldRoll.options, + damageTypes: damageData.parts[0].damageTypes ?? [] + } + } : null; + return acc; }, {}) }; diff --git a/module/data/chat-message/chatDamageData.mjs b/module/data/chat-message/chatDamageData.mjs index c233781c..b866ddaf 100644 --- a/module/data/chat-message/chatDamageData.mjs +++ b/module/data/chat-message/chatDamageData.mjs @@ -11,10 +11,7 @@ export class ChatDamageData extends foundry.abstract.DataModel { const fields = foundry.data.fields; return { - types: new fields.TypedObjectField(new fields.SchemaField({ - roll: new fields.JSONField({validate: ChatDamageData.#validateRoll}), - damageTypes: new fields.ArrayField(new fields.StringField({ choices: CONFIG.DH.GENERAL.damageTypes })) - })) + types: new fields.TypedObjectField(new fields.JSONField({validate: ChatDamageData.#validateRoll})) }; } @@ -31,14 +28,14 @@ export class ChatDamageData extends foundry.abstract.DataModel { for (const key of Object.keys(this.types)) { const type = this.types[key]; try { - type.roll = Roll.fromData(type.roll); - type.roll.modifierTotal = CONFIG.Dice.daggerheart.DHRoll.calculateTotalModifiers(type.roll); + this.types[key] = Roll.fromData(type); + this.types[key].options.modifierTotal = CONFIG.Dice.daggerheart.DHRoll.calculateTotalModifiers(type); } catch {} } } async rerollDamageDie(damageType, dice, resultIndex) { - const reroll = this.types[damageType].roll; + const reroll = this.types[damageType]; const rerollDice = reroll.dice[dice]; await rerollDice.rerollResult(resultIndex); await reroll._evaluate(); diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 14b88c15..56712337 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -19,12 +19,10 @@ export default class DamageRoll extends DHRoll { for (const roll of config.roll) { await roll.roll.evaluate(); - + roll.roll.options = { damageTypes: roll.damageTypes ?? [] }; + if (!config.damage?.types) config.damage = { types: {} }; - config.damage.types[roll.applyTo] = { - roll: roll.roll, - damageTypes: roll.damageTypes ?? [] - }; + config.damage.types[roll.applyTo] = roll.roll; } roll._evaluated = true; diff --git a/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs b/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs index 90f720cf..5f37c6d1 100644 --- a/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs +++ b/templates/dialogs/tagTeamDialog/parts/tagTeamDamageParts.hbs @@ -1,25 +1,24 @@ -{{#each damage.types as |damage key|}} +{{#each damage.types as |roll key|}}
{{localize (concat "DAGGERHEART.CONFIG.HealingType." key ".name")}}: {{damage.roll.total}}
- {{#with damage.roll}} -
- {{#each this.dice as |dice index|}} - - {{dice.total}} - - - {{#unless @last}} - + - {{/unless}} - {{/each}} - {{#if this.modifierTotal}} - {{#if this.dice.length}}{{#if (gte this.modifierTotal 0)}}+{{else}}-{{/if}}{{/if}} - {{positive this.modifierTotal}} - {{/if}} -
- {{/with}} + +
+ {{#each roll.dice as |dice index|}} + + {{dice.total}} + + + {{#unless @last}} + + + {{/unless}} + {{/each}} + {{#if roll.modifierTotal}} + {{#if roll.dice.length}}{{#if (gte roll.modifierTotal 0)}}+{{else}}-{{/if}}{{/if}} + {{positive roll.modifierTotal}} + {{/if}} +
{{/each}} \ No newline at end of file diff --git a/templates/ui/chat/parts/damage-part.hbs b/templates/ui/chat/parts/damage-part.hbs index e1d35b97..43fc3a6f 100644 --- a/templates/ui/chat/parts/damage-part.hbs +++ b/templates/ui/chat/parts/damage-part.hbs @@ -10,57 +10,56 @@
- {{#each damage.types as | data index | }} -
{{localize (concat 'DAGGERHEART.CONFIG.HealingType.' index '.inChatRoll')}}: {{data.roll.total}}
+ {{#each damage.types as | roll index | }} +
{{localize (concat 'DAGGERHEART.CONFIG.HealingType.' index '.inChatRoll')}}: {{roll.total}}
{{/each}}
- {{#each damage.types as | data index | }} + {{#each damage.types as | roll index | }}
{{#if ../hasHealing}}{{localize (concat 'DAGGERHEART.CONFIG.HealingType.' index '.name')}}{{else}}{{localize (concat 'DAGGERHEART.CONFIG.HealingType.' index '.inChatRoll')}}{{/if}}
{{localize "DAGGERHEART.GENERAL.total"}}: {{roll.total}}
{{#if (and (eq index "hitPoints") ../isDirect)}}
{{localize "DAGGERHEART.CONFIG.DamageType.direct.short"}}
{{/if}}
- {{#with data.roll}} - {{#if (and (not @root.hasHealing) damageTypes.length)}} - - {{/if}} -
- {{#if dice.length}} - {{#each dice}} - {{#each results}} - {{#if active}} -
-
- {{#if hasRerolls}}{{/if}} - {{result}} -
+ + {{#if (and (not @root.hasHealing) roll.options.damageTypes.length)}} + + {{/if}} +
+ {{#if roll.dice.length}} + {{#each roll.dice}} + {{#each results}} + {{#if active}} +
+
+ {{#if hasRerolls}}{{/if}} + {{result}}
- {{/if}} - {{/each}} +
+ {{/if}} {{/each}} - {{#if modifierTotal}} -
-
{{modifierTotal}}
-
- {{/if}} - {{else}} -
-
{{total}}
+ {{/each}} + {{#if roll.modifierTotal}} +
+
{{roll.modifierTotal}}
{{/if}} -
- {{/with}} + {{else}} +
+
{{roll.total}}
+
+ {{/if}} +
{{/each}}