Added drag/drop for features onto adversary/environment settings

This commit is contained in:
WBHarry 2025-07-05 03:01:43 +02:00
parent c3b8def6b1
commit 424335a3f2
3 changed files with 36 additions and 4 deletions

View file

@ -5,6 +5,7 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
super({});
this.actor = actor;
this._dragDrop = this._createDragDropHandlers();
}
get title() {
@ -30,7 +31,8 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
handler: this.updateForm,
submitOnChange: true,
closeOnSubmit: false
}
},
dragDrop: [{ dragSelector: null, dropSelector: '.tab.features' }]
};
static PARTS = {
@ -103,6 +105,21 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
return context;
}
_attachPartListeners(partId, htmlElement, options) {
super._attachPartListeners(partId, htmlElement, options);
this._dragDrop.forEach(d => d.bind(htmlElement));
}
_createDragDropHandlers() {
return this.options.dragDrop.map(d => {
d.callbacks = {
drop: this._onDrop.bind(this)
};
return new foundry.applications.ux.DragDrop.implementation(d);
});
}
_getTabs(tabs) {
for (const v of Object.values(tabs)) {
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
@ -152,4 +169,13 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
await this.actor.update(formData.object);
this.render();
}
async _onDrop(event) {
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
const item = await fromUuid(data.uuid);
if (item.type === 'feature') {
await this.actor.createEmbeddedDocuments('Item', [item]);
this.render();
}
}
}

View file

@ -34,7 +34,10 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
submitOnChange: true,
closeOnSubmit: false
},
dragDrop: [{ dragSelector: null, dropSelector: '.category-container' }]
dragDrop: [
{ dragSelector: null, dropSelector: '.category-container' },
{ dragSelector: null, dropSelector: '.tab.features' }
]
};
static PARTS = {
@ -175,7 +178,7 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
async _onDrop(event) {
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
const item = await fromUuid(data.uuid);
if (item.type === 'adversary') {
if (item.type === 'adversary' && event.target.closest('.category-container')) {
const target = event.target.closest('.category-container');
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
const current = foundry.utils.getProperty(this.actor, path).map(x => x.uuid);
@ -183,6 +186,9 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
[path]: [...current, item.uuid]
});
this.render();
} else if (item.type === 'feature' && event.target.closest('.tab.features')) {
await this.actor.createEmbeddedDocuments('Item', [item]);
this.render();
}
}

View file

@ -4,6 +4,6 @@
data-group='{{tabs.features.group}}'
>
<div class="feature-section">
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize tabs.actions.label) type='action'}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(localize tabs.features.label) type='feature'}}
</div>
</section>