mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 14:36:13 +01:00
Added drag/drop for features onto adversary/environment settings
This commit is contained in:
parent
c3b8def6b1
commit
424335a3f2
3 changed files with 36 additions and 4 deletions
|
|
@ -5,6 +5,7 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
|
||||||
super({});
|
super({});
|
||||||
|
|
||||||
this.actor = actor;
|
this.actor = actor;
|
||||||
|
this._dragDrop = this._createDragDropHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
get title() {
|
get title() {
|
||||||
|
|
@ -30,7 +31,8 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
|
||||||
handler: this.updateForm,
|
handler: this.updateForm,
|
||||||
submitOnChange: true,
|
submitOnChange: true,
|
||||||
closeOnSubmit: false
|
closeOnSubmit: false
|
||||||
}
|
},
|
||||||
|
dragDrop: [{ dragSelector: null, dropSelector: '.tab.features' }]
|
||||||
};
|
};
|
||||||
|
|
||||||
static PARTS = {
|
static PARTS = {
|
||||||
|
|
@ -103,6 +105,21 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
|
||||||
return context;
|
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) {
|
_getTabs(tabs) {
|
||||||
for (const v of Object.values(tabs)) {
|
for (const v of Object.values(tabs)) {
|
||||||
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
|
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);
|
await this.actor.update(formData.object);
|
||||||
this.render();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,10 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
|
||||||
submitOnChange: true,
|
submitOnChange: true,
|
||||||
closeOnSubmit: false
|
closeOnSubmit: false
|
||||||
},
|
},
|
||||||
dragDrop: [{ dragSelector: null, dropSelector: '.category-container' }]
|
dragDrop: [
|
||||||
|
{ dragSelector: null, dropSelector: '.category-container' },
|
||||||
|
{ dragSelector: null, dropSelector: '.tab.features' }
|
||||||
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
static PARTS = {
|
static PARTS = {
|
||||||
|
|
@ -175,7 +178,7 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
|
||||||
async _onDrop(event) {
|
async _onDrop(event) {
|
||||||
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
|
||||||
const item = await fromUuid(data.uuid);
|
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 target = event.target.closest('.category-container');
|
||||||
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
|
const path = `system.potentialAdversaries.${target.dataset.potentialAdversary}.adversaries`;
|
||||||
const current = foundry.utils.getProperty(this.actor, path).map(x => x.uuid);
|
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]
|
[path]: [...current, item.uuid]
|
||||||
});
|
});
|
||||||
this.render();
|
this.render();
|
||||||
|
} else if (item.type === 'feature' && event.target.closest('.tab.features')) {
|
||||||
|
await this.actor.createEmbeddedDocuments('Item', [item]);
|
||||||
|
this.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@
|
||||||
data-group='{{tabs.features.group}}'
|
data-group='{{tabs.features.group}}'
|
||||||
>
|
>
|
||||||
<div class="feature-section">
|
<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>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue