Action Macro working again

This commit is contained in:
Dapoolp 2025-08-12 03:58:25 +02:00
parent 7a798901cc
commit 6533877b79
9 changed files with 19 additions and 65 deletions

View file

@ -1,19 +1,13 @@
import DHBaseAction from './baseAction.mjs'; import DHBaseAction from './baseAction.mjs';
export default class DHMacroAction extends DHBaseAction { export default class DHMacroAction extends DHBaseAction {
static defineSchema() { static extraSchemas = [...super.extraSchemas, 'macro'];
const fields = foundry.data.fields;
return {
...super.defineSchema(),
documentUUID: new fields.DocumentUUIDField({ type: 'Macro' })
};
}
async trigger(event, ...args) { async trigger(event, ...args) {
const fixUUID = !this.documentUUID.includes('Macro.') ? `Macro.${this.documentUUID}` : this.documentUUID, const fixUUID = !this.macro.includes('Macro.') ? `Macro.${this.macro}` : this.macro,
macro = await fromUuid(fixUUID); macro = await fromUuid(fixUUID);
try { try {
if (!macro) throw new Error(`No macro found for the UUID: ${this.documentUUID}.`); if (!macro) throw new Error(`No macro found for the UUID: ${this.macro}.`);
macro.execute(); macro.execute();
} catch (error) { } catch (error) {
ui.notifications.error(error); ui.notifications.error(error);

View file

@ -8,3 +8,4 @@ export { default as BeastformField } from './beastformField.mjs';
export { default as DamageField } from './damageField.mjs'; export { default as DamageField } from './damageField.mjs';
export { default as HealingField } from './healingField.mjs'; export { default as HealingField } from './healingField.mjs';
export { default as RollField } from './rollField.mjs'; export { default as RollField } from './rollField.mjs';
export { default as MacroField } from './macroField.mjs';

View file

@ -0,0 +1,7 @@
const fields = foundry.data.fields;
export default class MacroField extends fields.DocumentUUIDField {
constructor(context = {}) {
super({ type: "Macro" }, context);
}
}

View file

@ -84,7 +84,7 @@ export class ActionField extends foundry.data.fields.ObjectField {
getModel(value) { getModel(value) {
return ( return (
game.system.api.models.actions.actionsTypes[value.type] ?? game.system.api.models.actions.actionsTypes[value.type] ??
game.system.api.models.actions.actionsTypes.attack null
); );
} }
@ -93,7 +93,6 @@ export class ActionField extends foundry.data.fields.ObjectField {
/** @override */ /** @override */
_cleanType(value, options) { _cleanType(value, options) {
if (!(typeof value === 'object')) value = {}; if (!(typeof value === 'object')) value = {};
const cls = this.getModel(value); const cls = this.getModel(value);
if (cls) return cls.cleanData(value, options); if (cls) return cls.cleanData(value, options);
return value; return value;

View file

@ -15,9 +15,8 @@ export const preloadHandlebarsTemplates = async function () {
'systems/daggerheart/templates/sheets/global/partials/feature-section-item.hbs', 'systems/daggerheart/templates/sheets/global/partials/feature-section-item.hbs',
'systems/daggerheart/templates/ui/combatTracker/combatTrackerSection.hbs', 'systems/daggerheart/templates/ui/combatTracker/combatTrackerSection.hbs',
'systems/daggerheart/templates/actionTypes/damage.hbs', 'systems/daggerheart/templates/actionTypes/damage.hbs',
'systems/daggerheart/templates/actionTypes/healing.hbs',
'systems/daggerheart/templates/actionTypes/resource.hbs', 'systems/daggerheart/templates/actionTypes/resource.hbs',
'systems/daggerheart/templates/actionTypes/uuid.hbs', 'systems/daggerheart/templates/actionTypes/macro.hbs',
'systems/daggerheart/templates/actionTypes/uses.hbs', 'systems/daggerheart/templates/actionTypes/uses.hbs',
'systems/daggerheart/templates/actionTypes/roll.hbs', 'systems/daggerheart/templates/actionTypes/roll.hbs',
'systems/daggerheart/templates/actionTypes/save.hbs', 'systems/daggerheart/templates/actionTypes/save.hbs',

View file

@ -1,41 +0,0 @@
<fieldset class="one-column">
<legend>
{{localize "DAGGERHEART.GENERAL.healing"}}
</legend>
{{#if (and (not @root.isNPC) @root.hasRoll)}}
{{formField fields.resultBased value=source.resultBased name="healing.resultBased" localize=true classes="checkbox"}}
{{/if}}
{{#if (and (not @root.isNPC) @root.hasRoll source.resultBased)}}
<div class="nest-inputs">
<fieldset class="one-column">
<legend>
<div>{{localize "DAGGERHEART.GENERAL.withThing" thing=(localize "DAGGERHEART.GENERAL.hope")}}</div>
</legend>
{{> formula fields=fields.value.fields source=source.value target="value"}}
</fieldset>
<fieldset class="one-column">
<legend>
<div>{{localize "DAGGERHEART.GENERAL.withThing" thing=(localize "DAGGERHEART.GENERAL.fear")}}</div>
</legend>
{{> formula fields=fields.valueAlt.fields source=source.valueAlt target="valueAlt"}}
</fieldset>
</div>
{{else}}
{{> formula fields=fields.value.fields source=source.value target="value"}}
{{/if}}
{{formField fields.applyTo value=source.applyTo name="healing.applyTo" localize=true}}
</fieldset>
{{#*inline "formula"}}
{{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat "healing." target ".custom.enabled") classes="checkbox"}}
{{#if source.custom.enabled}}
{{formField fields.custom.fields.formula value=source.custom.formula name=(concat "healing." target ".custom.formula") localize=true}}
{{else}}
<div class="nest-inputs">
{{formField fields.multiplier value=source.multiplier name=(concat "healing." target ".multiplier") localize=true}}
{{formField fields.dice value=source.dice name=(concat "healing." target ".dice")}}
{{formField fields.bonus value=source.bonus name=(concat "healing." target ".bonus") localize=true}}
</div>
{{/if}}
{{/inline}}

View file

@ -0,0 +1,5 @@
<fieldset>
<legend>{{localize "DOCUMENT.Macro"}}</legend>
{{formInput fields name="macro" value=source}}
</fieldset>

View file

@ -1,9 +0,0 @@
<fieldset class="action-category">
<legend class="action-category-label" data-action="toggleSection" data-section="effects">
<div>{{localize "DOCUMENT.Macro"}}</div>
</legend>
<div class="action-category-data open">
{{formInput fields value=source name="documentUUID" placeholder=fields.options.placeholder}}
</div>
</fieldset>

View file

@ -6,9 +6,8 @@
{{#if fields.roll}}{{> 'systems/daggerheart/templates/actionTypes/roll.hbs' fields=fields.roll.fields source=source.roll}}{{/if}} {{#if fields.roll}}{{> 'systems/daggerheart/templates/actionTypes/roll.hbs' fields=fields.roll.fields source=source.roll}}{{/if}}
{{#if fields.save}}{{> 'systems/daggerheart/templates/actionTypes/save.hbs' fields=fields.save.fields source=source.save}}{{/if}} {{#if fields.save}}{{> 'systems/daggerheart/templates/actionTypes/save.hbs' fields=fields.save.fields source=source.save}}{{/if}}
{{#if fields.damage}}{{> 'systems/daggerheart/templates/actionTypes/damage.hbs' fields=fields.damage.fields.parts.element.fields source=source.damage}}{{/if}} {{#if fields.damage}}{{> 'systems/daggerheart/templates/actionTypes/damage.hbs' fields=fields.damage.fields.parts.element.fields source=source.damage}}{{/if}}
{{!-- {{#if fields.healing}}{{> 'systems/daggerheart/templates/actionTypes/healing.hbs' fields=fields.healing.fields source=source.healing}}{{/if}} --}}
{{#if fields.resource}}{{> 'systems/daggerheart/templates/actionTypes/resource.hbs' fields=fields.resource.fields source=source.resource}}{{/if}} {{#if fields.resource}}{{> 'systems/daggerheart/templates/actionTypes/resource.hbs' fields=fields.resource.fields source=source.resource}}{{/if}}
{{#if fields.documentUUID}}{{> 'systems/daggerheart/templates/actionTypes/uuid.hbs' fields=fields.documentUUID source=source.documentUUID}}{{/if}} {{#if fields.macro}}{{> 'systems/daggerheart/templates/actionTypes/macro.hbs' fields=fields.macro source=source.macro}}{{/if}}
{{#if fields.effects}}{{> 'systems/daggerheart/templates/actionTypes/effect.hbs' fields=fields.effects.element.fields source=source.effects}}{{/if}} {{#if fields.effects}}{{> 'systems/daggerheart/templates/actionTypes/effect.hbs' fields=fields.effects.element.fields source=source.effects}}{{/if}}
{{#if fields.beastform}}{{> 'systems/daggerheart/templates/actionTypes/beastform.hbs' fields=fields.beastform.fields source=source.beastform}}{{/if}} {{#if fields.beastform}}{{> 'systems/daggerheart/templates/actionTypes/beastform.hbs' fields=fields.beastform.fields source=source.beastform}}{{/if}}
</section> </section>