diff --git a/lang/en.json b/lang/en.json index 9135c2b9..df6a3e64 100755 --- a/lang/en.json +++ b/lang/en.json @@ -137,7 +137,9 @@ "dropSummonsHere": "Drop Summons Here" }, "transform": { - "dropTransformHere": "Drop Transform Here" + "dropTransformHere": "Drop Transform Here", + "clearHitPoints": "Clear Hitpoints", + "clearStress": "Clear Stress" } } }, diff --git a/module/applications/sheets-configs/action-base-config.mjs b/module/applications/sheets-configs/action-base-config.mjs index 641f3c2c..c6676ede 100644 --- a/module/applications/sheets-configs/action-base-config.mjs +++ b/module/applications/sheets-configs/action-base-config.mjs @@ -121,6 +121,10 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) htmlElement.querySelectorAll('.summon-count-wrapper input').forEach(element => { element.addEventListener('change', this.updateSummonCount.bind(this)); }); + + htmlElement.querySelectorAll('.transform-resource input').forEach(element => { + element.addEventListener('change', this.updateTransformResource.bind(this)); + }); } async _prepareContext(_options) { @@ -136,6 +140,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) if (context.source.transform) { context.transform = { + ...context.source.transform, actor: await foundry.utils.fromUuid(context.source.transform.actorUUID) }; } @@ -359,6 +364,14 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2) this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); } + updateTransformResource(event) { + event.stopPropagation(); + + const data = this.action.toObject(); + data.transform.resourceRefresh[event.target.dataset.resource] = event.target.checked; + this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) }); + } + /** Specific implementation in extending classes **/ static async addEffect(_event) {} static removeEffect(_event, _button) {} diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index f6ffe75f..992e1714 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -197,7 +197,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel async executeWorkflow(config) { for (const [key, part] of this.workflow) { if (Hooks.call(`${CONFIG.DH.id}.pre${key.capitalize()}Action`, this, config) === false) return; - if ((await part.execute(config)) === false) return; + if ((await part.execute(config)) === false) return false; if (Hooks.call(`${CONFIG.DH.id}.post${key.capitalize()}Action`, this, config) === false) return; } } @@ -224,7 +224,9 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel } // Execute the Action Worflow in order based of schema fields - await this.executeWorkflow(config); + const result = await this.executeWorkflow(config); + if (result === false) return; + await config.resourceUpdates.updateResources(); if (Hooks.call(`${CONFIG.DH.id}.postUseAction`, this, config) === false) return; diff --git a/module/data/fields/action/transformField.mjs b/module/data/fields/action/transformField.mjs index 9e4acdc3..61ddc3ca 100644 --- a/module/data/fields/action/transformField.mjs +++ b/module/data/fields/action/transformField.mjs @@ -11,26 +11,60 @@ export default class DHSummonField extends fields.SchemaField { actorUUID: new fields.DocumentUUIDField({ type: 'Actor', required: true + }), + resourceRefresh: new fields.SchemaField({ + hitPoints: new fields.BooleanField({ initial: true }), + stress: new fields.BooleanField({ initial: true }) }) }; super(transformFields, options, context); } static async execute() { - if (!canvas.scene) - return ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.canvasError')); + if (!canvas.scene) { + ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.canvasError')); + return false; + } - if (!this.actor.token) - return ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.prototypeError')); + if (!this.actor.token) { + ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.prototypeError')); + return false; + } const actor = await DHSummonField.getWorldActor(await foundry.utils.fromUuid(this.transform.actorUUID)); + const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes; + const tokenSize = actor?.system.metadata.usesSize ? tokenSizes[actor.system.size] : actor.prototypeToken.width; await this.actor.token.update( - { ...actor.prototypeToken.toJSON(), actorId: actor.id }, + { ...actor.prototypeToken.toJSON(), actorId: actor.id, width: tokenSize, height: tokenSize }, { diff: false, recursive: false, noHook: true } ); + + const marks = { hitPoints: 0, stress: 0 }; + if (!this.transform.resourceRefresh.hitPoints) { + marks.hitPoints = Math.min( + this.actor.system.resources.hitPoints.value, + this.actor.token.actor.system.resources.hitPoints.max - 1 + ); + } + if (!this.transform.resourceRefresh.stress) { + marks.stress = Math.min( + this.actor.system.resources.stress.value, + this.actor.token.actor.system.resources.stress.max - 1 + ); + } + if (marks.hitPoints || marks.stress) { + this.actor.token.actor.update({ + 'system.resources': { + hitPoints: { value: marks.hitPoints }, + stress: { value: marks.stress } + } + }); + } + + const prevPosition = { ...this.actor.sheet.position }; this.actor.sheet.close(); - actor.sheet.render({ force: true }); + this.actor.token.actor.sheet.render({ force: true, position: prevPosition }); } /* Check for any available instances of the actor present in the world, or create a world actor based on compendium */ diff --git a/styles/less/sheets/actions/actions.less b/styles/less/sheets/actions/actions.less index b9bebc8e..a8618045 100644 --- a/styles/less/sheets/actions/actions.less +++ b/styles/less/sheets/actions/actions.less @@ -11,6 +11,21 @@ display: flex; flex-direction: column; gap: 10px; + + .transform-resources { + display: flex; + justify-content: space-between; + + .transform-resource { + display: flex; + flex-direction: column; + gap: 2px; + + .resource-title { + font-size: var(--font-size-18); + } + } + } } .actor-drop-line { diff --git a/templates/actionTypes/transform.hbs b/templates/actionTypes/transform.hbs index 1c7629e7..82be3c46 100644 --- a/templates/actionTypes/transform.hbs +++ b/templates/actionTypes/transform.hbs @@ -40,5 +40,16 @@ {{localize "DAGGERHEART.ACTIONS.Settings.transform.dropTransformHere"}} {{/unless}} + +
+
+ {{localize "DAGGERHEART.ACTIONS.Settings.transform.clearHitPoints"}} + +
+
+ {{localize "DAGGERHEART.ACTIONS.Settings.transform.clearStress"}} + +
+
\ No newline at end of file