daggerheart/module/applications/chatMessage.mjs
IrkTheImp 9fb9a4af55
fix dr command roll bug (#241)
* swap to use the DualityRoll not base roll

* update command to use new dice roll.

* reinstate DhpActor in action (which causes circular reference)

* fix additional dr options
2025-07-03 00:02:20 +02:00

40 lines
1.4 KiB
JavaScript

export default class DhpChatMessage extends foundry.documents.ChatMessage {
async renderHTML() {
if (this.system.messageTemplate)
this.content = await foundry.applications.handlebars.renderTemplate(
this.system.messageTemplate,
this.system
);
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
const html = await super.renderHTML();
this.applyPermission(html);
if (this.type === 'dualityRoll') {
html.classList.add('duality');
switch (this.system.roll.result.duality) {
case 1:
html.classList.add('hope');
break;
case -1:
html.classList.add('fear');
break;
default:
html.classList.add('critical');
break;
}
}
return html;
}
applyPermission(html) {
const elements = html.querySelectorAll('[data-perm-id]');
elements.forEach(e => {
const uuid = e.dataset.permId,
document = fromUuidSync(uuid);
e.setAttribute('data-view-perm', document.testUserPermission(game.user, 'OBSERVER'));
e.setAttribute('data-use-perm', document.testUserPermission(game.user, 'OWNER'));
});
}
}