Added Drag of features from Adversary/Environment settings to anywhere in Foundry

This commit is contained in:
WBHarry 2025-07-05 03:14:09 +02:00
parent 424335a3f2
commit b625a03977
4 changed files with 36 additions and 4 deletions

View file

@ -32,7 +32,10 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
submitOnChange: true, submitOnChange: true,
closeOnSubmit: false closeOnSubmit: false
}, },
dragDrop: [{ dragSelector: null, dropSelector: '.tab.features' }] dragDrop: [
{ dragSelector: null, dropSelector: '.tab.features' },
{ dragSelector: '.feature-item', dropSelector: null }
]
}; };
static PARTS = { static PARTS = {
@ -114,6 +117,7 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
_createDragDropHandlers() { _createDragDropHandlers() {
return this.options.dragDrop.map(d => { return this.options.dragDrop.map(d => {
d.callbacks = { d.callbacks = {
dragstart: this._onDragStart.bind(this),
drop: this._onDrop.bind(this) drop: this._onDrop.bind(this)
}; };
return new foundry.applications.ux.DragDrop.implementation(d); return new foundry.applications.ux.DragDrop.implementation(d);
@ -170,8 +174,21 @@ export default class DHAdversarySettings extends HandlebarsApplicationMixin(Appl
this.render(); this.render();
} }
async _onDragStart(event) {
const featureItem = event.currentTarget.closest('.feature-item');
if (featureItem) {
const feature = this.actor.items.get(featureItem.id);
const featureData = { type: 'Item', uuid: feature.uuid, fromInternal: true };
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
}
}
async _onDrop(event) { async _onDrop(event) {
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event); const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
if (data.fromInternal) return;
const item = await fromUuid(data.uuid); const item = await fromUuid(data.uuid);
if (item.type === 'feature') { if (item.type === 'feature') {
await this.actor.createEmbeddedDocuments('Item', [item]); await this.actor.createEmbeddedDocuments('Item', [item]);

View file

@ -36,7 +36,8 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
}, },
dragDrop: [ dragDrop: [
{ dragSelector: null, dropSelector: '.category-container' }, { dragSelector: null, dropSelector: '.category-container' },
{ dragSelector: null, dropSelector: '.tab.features' } { dragSelector: null, dropSelector: '.tab.features' },
{ dragSelector: '.feature-item', dropSelector: null }
] ]
}; };
@ -106,6 +107,7 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
_createDragDropHandlers() { _createDragDropHandlers() {
return this.options.dragDrop.map(d => { return this.options.dragDrop.map(d => {
d.callbacks = { d.callbacks = {
dragstart: this._onDragStart.bind(this),
drop: this._onDrop.bind(this) drop: this._onDrop.bind(this)
}; };
return new foundry.applications.ux.DragDrop.implementation(d); return new foundry.applications.ux.DragDrop.implementation(d);
@ -175,8 +177,21 @@ export default class DHEnvironmentSettings extends HandlebarsApplicationMixin(Ap
this.render(); this.render();
} }
async _onDragStart(event) {
const featureItem = event.currentTarget.closest('.feature-item');
if (featureItem) {
const feature = this.actor.items.get(featureItem.id);
const featureData = { type: 'Item', uuid: feature.uuid, fromInternal: true };
event.dataTransfer.setData('text/plain', JSON.stringify(featureData));
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0);
}
}
async _onDrop(event) { async _onDrop(event) {
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event); const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
if (data.fromInternal) return;
const item = await fromUuid(data.uuid); const item = await fromUuid(data.uuid);
if (item.type === 'adversary' && event.target.closest('.category-container')) { if (item.type === 'adversary' && event.target.closest('.category-container')) {
const target = event.target.closest('.category-container'); const target = event.target.closest('.category-container');

View file

@ -10,7 +10,7 @@
<legend>{{localize tabs.features.label}}</legend> <legend>{{localize tabs.features.label}}</legend>
<ul class="feature-list"> <ul class="feature-list">
{{#each document.system.features as |feature|}} {{#each document.system.features as |feature|}}
<li class="feature-item"> <li class="feature-item" id="{{feature.id}}">
<img src="{{feature.img}}" alt=""> <img src="{{feature.img}}" alt="">
<div class="label"> <div class="label">
<span>{{feature.name}}</span> <span>{{feature.name}}</span>

View file

@ -10,7 +10,7 @@
<legend>{{localize tabs.features.label}}</legend> <legend>{{localize tabs.features.label}}</legend>
<ul class="feature-list"> <ul class="feature-list">
{{#each document.system.features as |feature|}} {{#each document.system.features as |feature|}}
<li class="feature-item"> <li class="feature-item" id="{{feature.id}}">
<img src="{{feature.img}}" alt=""> <img src="{{feature.img}}" alt="">
<div class="label"> <div class="label">
<span>{{feature.name}}</span> <span>{{feature.name}}</span>