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 DhpDualityRoll from '../data/dualityRoll.mjs';
import { DualityRollColor } from '../data/settings/Appearance.mjs'; import { DualityRollColor } from '../data/settings/Appearance.mjs';
export default class DhpChatMesssage extends ChatMessage { export default class DhpChatMessage extends ChatMessage {
async renderHTML() { constructor(data, options) {
if ( super(data, options);
this.type === 'dualityRoll' ||
this.type === 'adversaryRoll' ||
this.type === 'damageRoll' ||
this.type === 'abilityUse'
) {
this.content = await foundry.applications.handlebars.renderTemplate(this.content, this.system);
}
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. */ /* 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();
if ( if (
this.type === 'dualityRoll' && this.type === 'dualityRoll' &&
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.appearance).dualityColorScheme === 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 cls = getDocumentClass('ChatMessage');
const msg = new cls({ const msg = new cls({
user: game.user.id, user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/deathMove.hbs', { content: await foundry.applications.handlebars.renderTemplate(
player: this.actor.name, 'systems/daggerheart/templates/chat/deathMove.hbs',
title: game.i18n.localize(this.selectedMove.name), {
img: this.selectedMove.img, player: this.actor.name,
description: game.i18n.localize(this.selectedMove.description) title: game.i18n.localize(this.selectedMove.name),
}) img: this.selectedMove.img,
description: game.i18n.localize(this.selectedMove.description)
}
)
}); });
cls.create(msg.toObject()); cls.create(msg.toObject());

View file

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

View file

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

View file

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

View file

@ -337,7 +337,7 @@ export default class DhpPC extends foundry.abstract.TypeDataModel {
get refreshableFeatures() { get refreshableFeatures() {
return this.parent.items.reduce( return this.parent.items.reduce(
(acc, x) => { (acc, x) => {
if (x.type === 'feature' && x.system.refreshData?.type) { if (x.type === 'feature' && x.system.refreshData?.type === 'feature' && x.system.refreshData?.type) {
acc[x.system.refreshData.type].push(x); acc[x.system.refreshData.type].push(x);
} }

View file

@ -5,9 +5,12 @@ export default class SelectDialog extends Dialog {
this.data = { this.data = {
title: data.title, title: data.title,
buttons: data.buttons, buttons: data.buttons,
content: renderTemplate('systems/daggerheart/templates/dialog/item-select.hbs', { content: foundry.applications.handlebars.renderTemplate(
items: data.choices 'systems/daggerheart/templates/dialog/item-select.hbs',
}) {
items: data.choices
}
)
}; };
this.actor = data.actor; this.actor = data.actor;

View file

@ -355,11 +355,14 @@ export default class DhpActor extends Actor {
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const msg = new cls({
user: game.user.id, user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/damage-roll.hbs', { content: await foundry.applications.handlebars.renderTemplate(
roll: roll.formula, 'systems/daggerheart/templates/chat/damage-roll.hbs',
total: roll.result, {
type: action.damage.type roll: roll.formula,
}) total: roll.result,
type: action.damage.type
}
)
}); });
cls.create(msg.toObject()); cls.create(msg.toObject());
@ -374,11 +377,14 @@ export default class DhpActor extends Actor {
const cls = getDocumentClass('ChatMessage'); const cls = getDocumentClass('ChatMessage');
const msg = new cls({ const msg = new cls({
user: game.user.id, user: game.user.id,
content: await renderTemplate('systems/daggerheart/templates/chat/healing-roll.hbs', { content: await foundry.applications.handlebars.renderTemplate(
roll: roll.formula, 'systems/daggerheart/templates/chat/healing-roll.hbs',
total: roll.result, {
type: action.healing.type roll: roll.formula,
}) total: roll.result,
type: action.healing.type
}
)
}); });
cls.create(msg.toObject()); cls.create(msg.toObject());

View file

@ -38,25 +38,28 @@ export default class DhpItem extends Item {
}, {}); }, {});
// Render the document creation form // Render the document creation form
const html = await renderTemplate('systems/daggerheart/templates/sidebar/documentCreate.hbs', { const html = await foundry.applications.handlebars.renderTemplate(
folders, 'systems/daggerheart/templates/sidebar/documentCreate.hbs',
name: data.name || game.i18n.format('DOCUMENT.New', { type: label }), {
folder: data.folder, folders,
hasFolders: folders.length >= 1, name: data.name || game.i18n.format('DOCUMENT.New', { type: label }),
type: data.type || CONFIG[documentName]?.defaultType || typeObjects.armor, folder: data.folder,
types: { hasFolders: folders.length >= 1,
Items: [typeObjects.armor, typeObjects.weapon, typeObjects.consumable, typeObjects.miscellaneous], type: data.type || CONFIG[documentName]?.defaultType || typeObjects.armor,
Character: [ types: {
typeObjects.class, Items: [typeObjects.armor, typeObjects.weapon, typeObjects.consumable, typeObjects.miscellaneous],
typeObjects.subclass, Character: [
typeObjects.ancestry, typeObjects.class,
typeObjects.community, typeObjects.subclass,
typeObjects.feature, typeObjects.ancestry,
typeObjects.domainCard typeObjects.community,
] typeObjects.feature,
}, typeObjects.domainCard
hasTypes: types.length > 1 ]
}); },
hasTypes: types.length > 1
}
);
// Render the confirmation dialog window // Render the confirmation dialog window
return Dialog.prompt({ return Dialog.prompt({

View file

@ -2828,14 +2828,14 @@ div.daggerheart.views.multiclass {
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url(https://fonts.gstatic.com/s/montserrat/v29/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCtr6Ew-.ttf) format('truetype'); src: url(https://fonts.gstatic.com/s/montserrat/v30/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCtr6Ew-.ttf) format('truetype');
} }
@font-face { @font-face {
font-family: 'Montserrat'; font-family: 'Montserrat';
font-style: normal; font-style: normal;
font-weight: 600; font-weight: 600;
font-display: swap; font-display: swap;
src: url(https://fonts.gstatic.com/s/montserrat/v29/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCu170w-.ttf) format('truetype'); src: url(https://fonts.gstatic.com/s/montserrat/v30/JTUHjIg1_i6t8kCHKm4532VJOt5-QNFgpCu170w-.ttf) format('truetype');
} }
.application.sheet.daggerheart.dh-style h1 { .application.sheet.daggerheart.dh-style h1 {
font-family: 'Cinzel Decorative', serif; font-family: 'Cinzel Decorative', serif;