This commit is contained in:
WBHarry 2025-05-24 21:06:04 +02:00
parent 2599d1287d
commit f9c30b583c
4 changed files with 72 additions and 4 deletions

View file

@ -10,6 +10,7 @@ import DhpChatLog from './module/ui/chatLog.mjs';
import DhpPlayers from './module/ui/players.mjs';
import DhpRuler from './module/ui/ruler.mjs';
import DhpTokenRuler from './module/ui/tokenRuler.mjs';
import { dualityRollEnricher } from './module/enrichers/DualityRollEnricher.mjs';
globalThis.SYSTEM = SYSTEM;
@ -21,6 +22,11 @@ Hooks.once('init', () => {
documents
};
CONFIG.TextEditor.enrichers.push({
pattern: /\[\[\/dr\s?(.*?)\]\]/g,
enricher: dualityRollEnricher
});
CONFIG.statusEffects = Object.values(SYSTEM.GENERAL.conditions).map(x => ({
...x,
name: game.i18n.localize(x.name)
@ -89,7 +95,6 @@ Hooks.once('init', () => {
game.socket.on(`system.${SYSTEM.id}`, handleSocketEvent);
registerDHPSettings();
RegisterHandlebarsHelpers.registerHelpers();
return preloadHandlebarsTemplates();
@ -121,6 +126,29 @@ Hooks.on(socketEvent.GMUpdate, async (action, uuid, update) => {
}
});
Hooks.on('renderChatMessageHTML', (message, element) => {
element.querySelectorAll('.duality-roll-button').forEach(element =>
element.addEventListener('click', async event => {
const button = event.currentTarget;
let target = game.canvas.tokens.controlled.length > 0 ? game.canvas.tokens.controlled[0].actor : null;
if (!game.user.isGM) {
target = game.user.character;
if (!target) {
notifications.error('DAGGERHEART.Notification.Error.NoAssignedPlayerCharacter');
return;
}
}
if (!target) {
notifications.error('DAGGERHEART.Notification.Error.NoSelectedToken');
return;
}
const test = await gmTarget.diceRoll(3);
})
);
});
const preloadHandlebarsTemplates = async function () {
return foundry.applications.handlebars.loadTemplates([
'systems/daggerheart/templates/sheets/parts/attributes.hbs',

View file

@ -93,13 +93,16 @@
"LacksDomain": "Your character doesn't have the domain of the card!",
"MaxLoadoutReached": "You can't have any more domain cards at this level!",
"DuplicateDomainCard": "You already have a domain card with that name!",
"ActionRequiresTarget": "The action requires at least one target"
"ActionRequiresTarget": "The action requires at least one target",
"NoAssignedPlayerCharacter": "You have no assigned character.",
"NoSelectedToken": "You have no selected token"
}
},
"General": {
"OpenBetaDisclaimer": "Daggerheart Open Beta {version}",
"Hope": "Hope",
"Fear": "Fear",
"Duality": "Duality",
"Check": "{check} Check",
"CriticalSuccess": "Critical Success",
"Advantage": "Advantage",
"Disadvantage": "Disadvantage",

View file

@ -0,0 +1,38 @@
import { abilities } from '../config/actorConfig.mjs';
export async function dualityRollEnricher(match, _options) {
try {
const {
hope = 'd12',
fear = 'd12',
attribute,
advantage,
disadvantage
} = JSON.parse(`{${match[1].replace(' ', ',').replace(/(\w+(?==))(=)/g, '"$1":')}}`);
const dualityElement = document.createElement('span');
const attributeLabel =
attribute && abilities[attribute]
? game.i18n.format('DAGGERHEART.General.Check', {
check: game.i18n.localize(abilities[attribute].label)
})
: null;
const label = attributeLabel ?? game.i18n.localize('DAGGERHEART.General.Duality');
dualityElement.innerHTML = `
<button class="duality-roll-button"
data-hope="${hope}"
data-fear="${fear}"
${attribute ? `data-attribute="${attribute}"` : ''}
${advantage ? 'data-advantage="true"' : ''}
${disadvantage ? 'data-disadvantage="true"' : ''}
>
<i class="fa-solid fa-circle-half-stroke"></i>
${label}
</button>
`;
return dualityElement;
} catch (_) {
return match[0];
}
}

View file

@ -76,7 +76,6 @@
<div class="tab features {{this.tabs.primary.features.cssClass}}" data-group="primary" data-tab="features">
<div class="tab-container">
<div class="flexcol tab-inner-container">
<div class="system-info">{{localize "DAGGERHEART.General.OpenBetaDisclaimer" version="V1.4"}}</div>
<div class="feature-sheet-body flexrow">
<div class="body-section flex2">
{{> "systems/daggerheart/templates/sheets/parts/defense.hbs" }}