From f6bd1430e3e6763afd524e9b0477a4a62e1f3085 Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Mon, 29 Dec 2025 13:02:22 +0100 Subject: [PATCH] Fixed drag/drop of features for environments (#1488) --- .../sheets-configs/adversary-settings.mjs | 19 ++++++++++++++--- .../sheets-configs/environment-settings.mjs | 13 ++++++++++++ .../sheets/actors/environment.mjs | 21 ++++++++++++++++++- .../adversary-settings/features.hbs | 2 +- .../environment-settings/features.hbs | 2 +- .../sheets/actors/environment/features.hbs | 2 +- 6 files changed, 52 insertions(+), 7 deletions(-) diff --git a/module/applications/sheets-configs/adversary-settings.mjs b/module/applications/sheets-configs/adversary-settings.mjs index bcc8b1c9..d3d215be 100644 --- a/module/applications/sheets-configs/adversary-settings.mjs +++ b/module/applications/sheets-configs/adversary-settings.mjs @@ -51,6 +51,19 @@ export default class DHAdversarySettings extends DHBaseActorSettings { } }; + async _prepareContext(options) { + const context = await super._prepareContext(options); + + const featureForms = ['passive', 'action', 'reaction']; + context.features = context.document.system.features.sort((a, b) => + a.system.featureForm !== b.system.featureForm + ? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm) + : a.sort - b.sort + ); + + return context; + } + /* -------------------------------------------- */ /** @@ -98,16 +111,16 @@ export default class DHAdversarySettings extends DHBaseActorSettings { async _onDrop(event) { const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event); - + const item = await fromUuid(data.uuid); if (item?.type === 'feature') { if (data.fromInternal && item.parent?.uuid === this.actor.uuid) { return; } - + const itemData = item.toObject(); delete itemData._id; - + await this.actor.createEmbeddedDocuments('Item', [itemData]); } } diff --git a/module/applications/sheets-configs/environment-settings.mjs b/module/applications/sheets-configs/environment-settings.mjs index 2efa3b38..15f5701d 100644 --- a/module/applications/sheets-configs/environment-settings.mjs +++ b/module/applications/sheets-configs/environment-settings.mjs @@ -49,6 +49,19 @@ export default class DHEnvironmentSettings extends DHBaseActorSettings { } }; + async _prepareContext(options) { + const context = await super._prepareContext(options); + + const featureForms = ['passive', 'action', 'reaction']; + context.features = context.document.system.features.sort((a, b) => + a.system.featureForm !== b.system.featureForm + ? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm) + : a.sort - b.sort + ); + + return context; + } + /** * Adds a new category entry to the actor. * @type {ApplicationClickAction} diff --git a/module/applications/sheets/actors/environment.mjs b/module/applications/sheets/actors/environment.mjs index 01a60ec1..f8ff74a6 100644 --- a/module/applications/sheets/actors/environment.mjs +++ b/module/applications/sheets/actors/environment.mjs @@ -30,7 +30,7 @@ export default class DhpEnvironment extends DHBaseActorSheet { dragSelector: '[data-item-id][draggable="true"], [data-item-id] [draggable="true"]', dropSelector: null } - ], + ] }; /**@override */ @@ -79,6 +79,9 @@ export default class DhpEnvironment extends DHBaseActorSheet { case 'header': await this._prepareHeaderContext(context, options); + break; + case 'features': + await this._prepareFeaturesContext(context, options); break; case 'notes': await this._prepareNotesContext(context, options); @@ -115,6 +118,22 @@ export default class DhpEnvironment extends DHBaseActorSheet { } } + /** + * Prepare render context for the features part. + * @param {ApplicationRenderContext} context + * @param {ApplicationRenderOptions} options + * @returns {Promise} + * @protected + */ + async _prepareFeaturesContext(context, _options) { + const featureForms = ['passive', 'action', 'reaction']; + context.features = this.document.system.features.sort((a, b) => + a.system.featureForm !== b.system.featureForm + ? featureForms.indexOf(a.system.featureForm) - featureForms.indexOf(b.system.featureForm) + : a.sort - b.sort + ); + } + /** * Prepare render context for the Header part. * @param {ApplicationRenderContext} context diff --git a/templates/sheets-settings/adversary-settings/features.hbs b/templates/sheets-settings/adversary-settings/features.hbs index bc6a1ddf..2f2f5f47 100644 --- a/templates/sheets-settings/adversary-settings/features.hbs +++ b/templates/sheets-settings/adversary-settings/features.hbs @@ -9,7 +9,7 @@
{{localize tabs.features.label}}