update all chat messages to render templates

This commit is contained in:
IrkTheImp 2025-05-29 21:51:54 -05:00
parent cc6c9a11bc
commit 6a1848760b
7 changed files with 130 additions and 112 deletions

View file

@ -774,7 +774,8 @@
"AbilityCheckTitle": "{ability} Check" "AbilityCheckTitle": "{ability} Check"
}, },
"AttackRoll": { "AttackRoll": {
"Title": "Attack - {attack}" "Title": "Attack - {attack}",
"RollDamage": "Roll Damage"
}, },
"DamageRoll": { "DamageRoll": {
"Title": "Damage - {damage}", "Title": "Damage - {damage}",

View file

@ -2,23 +2,6 @@ import DhpDualityRoll from '../data/dualityRoll.mjs';
import { DualityRollColor } from '../data/settings/Appearance.mjs'; import { DualityRollColor } from '../data/settings/Appearance.mjs';
export default class DhpChatMessage extends ChatMessage { export default class DhpChatMessage extends ChatMessage {
constructor(data, options) {
super(data, options);
if (
data.type === 'dualityRoll' ||
data.type === 'adversaryRoll' ||
data.type === 'damageRoll' ||
data.type === 'abilityUse'
) {
this.#templateInjection(data);
}
}
async #templateInjection(data) {
return await foundry.applications.handlebars.renderTemplate(data.content, data.system);
}
async renderHTML() { async renderHTML() {
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */ /* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
const html = await super.renderHTML(); const html = await super.renderHTML();

View file

@ -330,15 +330,19 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
); );
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const systemData = {
type: 'adversaryRoll',
system: {
roll: roll._formula, roll: roll._formula,
total: roll._total, total: roll._total,
modifiers: modifiers, modifiers: modifiers,
diceResults: diceResults diceResults: diceResults
}, };
content: 'systems/daggerheart/templates/chat/adversary-roll.hbs', const msg = new cls({
type: 'adversaryRoll',
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/adversary-roll.hbs',
systemData
),
rolls: [roll] rolls: [roll]
}); });
@ -362,10 +366,7 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
})); }));
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const systemData = {
type: 'adversaryRoll',
sound: CONFIG.sounds.dice,
system: {
title: button.dataset.name, title: button.dataset.name,
origin: this.document.id, origin: this.document.id,
roll: roll._formula, roll: roll._formula,
@ -375,8 +376,15 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) {
dice: dice, dice: dice,
targets: targets, targets: targets,
damage: { value: button.dataset.damage, type: button.dataset.damageType } damage: { value: button.dataset.damage, type: button.dataset.damageType }
}, };
content: 'systems/daggerheart/templates/chat/adversary-attack-roll.hbs', const msg = new cls({
type: 'adversaryRoll',
sound: CONFIG.sounds.dice,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/adversary-attack-roll.hbs',
systemData
),
rolls: [roll] rolls: [roll]
}); });

View file

@ -494,10 +494,8 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
); );
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msgData = {
type: 'dualityRoll', const systemContent = {
sound: CONFIG.sounds.dice,
system: {
title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', { title: game.i18n.format('DAGGERHEART.Chat.DualityRoll.AbilityCheckTitle', {
ability: game.i18n.localize(abilities[button.dataset.attribute].label) ability: game.i18n.localize(abilities[button.dataset.attribute].label)
}), }),
@ -508,13 +506,21 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
fear: fear, fear: fear,
advantage: advantage, advantage: advantage,
disadvantage: disadvantage disadvantage: disadvantage
},
user: game.user.id,
content: 'systems/daggerheart/templates/chat/duality-roll.hbs',
rolls: [roll]
}; };
await cls.create(msgData); const msg = new cls({
type: 'dualityRoll',
sound: CONFIG.sounds.dice,
system: systemContent,
user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/duality-roll.hbs',
systemContent
),
rolls: [roll]
});
await cls.create(msg.toObject());
} }
static async toggleMarks(_, button) { static async toggleMarks(_, button) {
@ -588,11 +594,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
evasion: x.actor.system.evasion evasion: x.actor.system.evasion
})); }));
const cls = getDocumentClass('ChatMessage'); const systemData = {
const msg = new cls({
type: 'dualityRoll',
sound: CONFIG.sounds.dice,
system: {
title: weapon.name, title: weapon.name,
origin: this.document.id, origin: this.document.id,
roll: roll._formula, roll: roll._formula,
@ -603,8 +605,17 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
disadvantage: disadvantage, disadvantage: disadvantage,
damage: damage, damage: damage,
targets: targets targets: targets
}, };
content: 'systems/daggerheart/templates/chat/attack-roll.hbs',
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
type: 'dualityRoll',
sound: CONFIG.sounds.dice,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/attack-roll.hbs',
systemData
),
rolls: [roll] rolls: [roll]
}); });
@ -642,17 +653,21 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
const card = this.document.items.find(x => x.uuid === button.dataset.key); const card = this.document.items.find(x => x.uuid === button.dataset.key);
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const systemData = {
type: 'abilityUse',
user: game.user.id,
content: 'systems/daggerheart/templates/chat/ability-use.hbs',
system: {
title: `${game.i18n.localize('DAGGERHEART.Chat.DomainCard.Title')} - ${capitalize(button.dataset.domain)}`, title: `${game.i18n.localize('DAGGERHEART.Chat.DomainCard.Title')} - ${capitalize(button.dataset.domain)}`,
img: card.img, img: card.img,
name: card.name, name: card.name,
description: card.system.effect, description: card.system.effect,
actions: card.system.actions actions: card.system.actions
} };
const msg = new cls({
type: 'abilityUse',
user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
systemData
),
system: systemData
}); });
cls.create(msg.toObject()); cls.create(msg.toObject());
@ -855,17 +870,21 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
const item = await fromUuid(button.dataset.id); const item = await fromUuid(button.dataset.id);
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const systemData = {
type: 'abilityUse',
user: game.user.id,
content: 'systems/daggerheart/templates/chat/ability-use.hbs',
system: {
title: game.i18n.localize('DAGGERHEART.Chat.FeatureTitle'), title: game.i18n.localize('DAGGERHEART.Chat.FeatureTitle'),
img: item.img, img: item.img,
name: item.name, name: item.name,
description: item.system.description, description: item.system.description,
actions: item.system.actions actions: item.system.actions
} };
const msg = new cls({
type: 'abilityUse',
user: game.user.id,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
systemData
),
system: systemData
}); });
cls.create(msg.toObject()); cls.create(msg.toObject());
@ -876,10 +895,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
const type = button.dataset.type; const type = button.dataset.type;
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const systemData = {
type: 'abilityUse',
user: game.user.id,
system: {
title: title:
type === 'ancestry' type === 'ancestry'
? game.i18n.localize('DAGGERHEART.Chat.FoundationCard.AncestryTitle') ? game.i18n.localize('DAGGERHEART.Chat.FoundationCard.AncestryTitle')
@ -890,8 +906,15 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
name: item.name, name: item.name,
description: item.system.description, description: item.system.description,
actions: [] actions: []
}, };
content: 'systems/daggerheart/templates/chat/ability-use.hbs' const msg = new cls({
type: 'abilityUse',
user: game.user.id,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
systemData
)
}); });
cls.create(msg.toObject()); cls.create(msg.toObject());

View file

@ -246,11 +246,7 @@ export default class DhpActor extends Actor {
} }
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const systemData = {
type: 'damageRoll',
user: game.user.id,
sound: CONFIG.sounds.dice,
system: {
title: game.i18n.format('DAGGERHEART.Chat.DamageRoll.Title', { damage: title }), title: game.i18n.format('DAGGERHEART.Chat.DamageRoll.Title', { damage: title }),
roll: rollString, roll: rollString,
damage: { damage: {
@ -260,8 +256,16 @@ export default class DhpActor extends Actor {
dice: dice, dice: dice,
modifiers: modifiers, modifiers: modifiers,
targets: targets targets: targets
}, };
content: 'systems/daggerheart/templates/chat/damage-roll.hbs', const msg = new cls({
type: 'damageRoll',
user: game.user.id,
sound: CONFIG.sounds.dice,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/damage-roll.hbs',
systemData
),
rolls: [roll] rolls: [roll]
}); });

View file

@ -164,7 +164,7 @@
</div> </div>
{{/if}} {{/if}}
<div class="dice-actions"> <div class="dice-actions">
<button class="duality-action" data-value="{{this.total}}" data-damage="{{this.damage.value}}" data-damage-type="{{this.damage.type}}" {{#if this.damage.disabled}}disabled{{/if}}><span>Roll Damage</span></button> <button class="duality-action" data-value="{{this.total}}" data-damage="{{this.damage.value}}" data-damage-type="{{this.damage.type}}" {{#if this.damage.disabled}}disabled{{/if}}><span>{{localize "DAGGERHEART.Chat.AttackRoll.RollDamage"}}</span></button>
</div> </div>
</div> </div>
</div> </div>

View file

@ -23,7 +23,6 @@
</section> </section>
</div> </div>
</div> </div>
<div class="dice-total">{{this.damage.total}}</div> <div class="dice-total">{{this.damage.total}}</div>
<div class="dice-actions"> <div class="dice-actions">
<button class="damage-button" data-target-hit="true" {{#if (eq this.targets.length 0)}}disabled{{/if}}>{{localize "DAGGERHEART.Chat.DamageRoll.DealDamageToTargets"}}</button> <button class="damage-button" data-target-hit="true" {{#if (eq this.targets.length 0)}}disabled{{/if}}>{{localize "DAGGERHEART.Chat.DamageRoll.DealDamageToTargets"}}</button>