fix chatmessage to render the template in constructor. Update namespaces.

This commit is contained in:
IrkTheImp 2025-05-29 20:42:25 -05:00
parent 4de3e94fd7
commit cc6c9a11bc
10 changed files with 117 additions and 76 deletions

View file

@ -1,19 +1,28 @@
import DhpDualityRoll from '../data/dualityRoll.mjs';
import { DualityRollColor } from '../data/settings/Appearance.mjs';
export default class DhpChatMesssage extends ChatMessage {
async renderHTML() {
if (
this.type === 'dualityRoll' ||
this.type === 'adversaryRoll' ||
this.type === 'damageRoll' ||
this.type === 'abilityUse'
) {
this.content = await foundry.applications.handlebars.renderTemplate(this.content, this.system);
}
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() {
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
const html = await super.renderHTML();
if (
this.type === 'dualityRoll' &&
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.appearance).dualityColorScheme ===

View file

@ -47,12 +47,15 @@ export default class DhpDeathMove extends HandlebarsApplicationMixin(Application
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/deathMove.hbs', {
player: this.actor.name,
title: game.i18n.localize(this.selectedMove.name),
img: this.selectedMove.img,
description: game.i18n.localize(this.selectedMove.description)
})
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/deathMove.hbs',
{
player: this.actor.name,
title: game.i18n.localize(this.selectedMove.name),
img: this.selectedMove.img,
description: game.i18n.localize(this.selectedMove.description)
}
)
});
cls.create(msg.toObject());

View file

@ -70,13 +70,16 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/downtime.hbs', {
player: this.actor.name,
title: game.i18n.localize(this.selectedActivity.name),
img: this.selectedActivity.img,
description: game.i18n.localize(this.selectedActivity.description),
refreshedFeatures: refreshedFeatures
})
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/downtime.hbs',
{
player: this.actor.name,
title: game.i18n.localize(this.selectedActivity.name),
img: this.selectedActivity.img,
description: game.i18n.localize(this.selectedActivity.description),
refreshedFeatures: refreshedFeatures
}
)
});
cls.create(msg.toObject());

View file

@ -123,10 +123,15 @@ export default class DhpEnvironment extends DaggerheartSheet(DocumentSheetV2) {
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/ability-use.hbs', {
title: game.i18n.format('DAGGERHEART.Chat.EnvironmentTitle', { actionType: button.dataset.actionType }),
card: { name: item.name, img: item.img, description: item.system.description }
})
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
{
title: game.i18n.format('DAGGERHEART.Chat.EnvironmentTitle', {
actionType: button.dataset.actionType
}),
card: { name: item.name, img: item.img, description: item.system.description }
}
)
});
cls.create(msg.toObject());

View file

@ -790,13 +790,16 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/ability-use.hbs', {
title: game.i18n.localize('DAGGERHEART.Chat.FeatureTitle'),
card: {
name: `${feature.name} - Roll Of ${feature.system.featureType.data.numbers[index].value}`,
img: feature.img
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
{
title: game.i18n.localize('DAGGERHEART.Chat.FeatureTitle'),
card: {
name: `${feature.name} - Roll Of ${feature.system.featureType.data.numbers[index].value}`,
img: feature.img
}
}
})
)
});
cls.create(msg.toObject());
@ -905,10 +908,13 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/ability-use.hbs', {
title: game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'),
card: { name: title, img: item.img, description: ability.description }
})
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
{
title: game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'),
card: { name: title, img: item.img, description: ability.description }
}
)
});
cls.create(msg.toObject());
@ -921,10 +927,13 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
const cls = getDocumentClass('ChatMessage');
const msg = new cls({
user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/ability-use.hbs', {
title: game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'),
card: { name: item.name, img: item.img, description: item.system.description }
})
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
{
title: game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'),
card: { name: item.name, img: item.img, description: item.system.description }
}
)
});
cls.create(msg.toObject());