This commit is contained in:
WBHarry 2025-11-23 15:03:11 +01:00
parent cb65266c43
commit 451f99bf05
5 changed files with 27 additions and 32 deletions

View file

@ -33,9 +33,9 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
removeResource: DHBaseItemSheet.#removeResource removeResource: DHBaseItemSheet.#removeResource
}, },
dragDrop: [ dragDrop: [
{ dragSelector: null, dropSelector: '.tab.features .drop-section' }, { dragSelector: null, dropSelector: '.drop-section' },
{ dragSelector: '.feature-item', dropSelector: null }, { dragSelector: '.feature-item', dropSelector: null },
{ dragSelector: '.action-item', dropSelector: null } { dragSelector: '.inventory-item', dropSelector: null }
], ],
contextMenus: [ contextMenus: [
{ {
@ -242,37 +242,30 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
* @param {DragEvent} event - The drag event * @param {DragEvent} event - The drag event
*/ */
async _onDragStart(event) { async _onDragStart(event) {
/* Can prolly be improved a lot, but I don't wanna >_< */
const featureItem = event.currentTarget.closest('.feature-item'); const featureItem = event.currentTarget.closest('.feature-item');
const inventoryItem = event.currentTarget.closest('.inventory-item');
const lineItem = event.currentTarget.closest('.item-line');
const dragItemData = featureItem ?? inventoryItem ?? lineItem;
if (featureItem) { const dragItem = await foundry.utils.fromUuid(dragItemData.dataset.itemUuid);
const feature = this.document.system.features.find(x => x?.id === featureItem.id); if (dragItem) {
if (!feature) { if (!dragItem) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing')); ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.featureIsMissing'));
return; return;
} }
const featureData = { type: 'Item', data: { ...feature.toObject(), _id: null }, fromInternal: true }; let dragData = {};
event.dataTransfer.setData('text/plain', JSON.stringify(featureData)); if (dragItemData.dataset.type === 'effect')
event.dataTransfer.setDragImage(featureItem.querySelector('img'), 60, 0); dragData = {
} else { type: 'ActiveEffect',
const actionItem = event.currentTarget.closest('.action-item'); fromInternal: this.document.uuid,
if (actionItem) { data: { ...dragItem, uuid: dragItem.uuid, id: dragItem.id }
const action = this.document.system.actions[actionItem.dataset.index];
if (!action) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.actionIsMissing'));
return;
}
const actionData = {
type: 'Action',
data: { ...action.toObject(), id: action.id, itemUuid: this.document.uuid },
fromInternal: true
}; };
event.dataTransfer.setData('text/plain', JSON.stringify(actionData)); else dragData = { type: 'Item', uuid: dragItem.uuid, id: dragItem.id, fromInternal: this.document.id };
event.dataTransfer.setDragImage(actionItem.querySelector('img'), 60, 0);
} else { event.dataTransfer.setData('text/plain', JSON.stringify(dragData));
super._onDragStart(event); event.dataTransfer.setDragImage(dragItemData.querySelector('img'), 60, 0);
}
} }
} }
@ -284,7 +277,7 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) {
super._onDrop(event); super._onDrop(event);
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event); const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
if (data.fromInternal) return; if (data.fromInternal === this.document.id) return;
const target = event.target.closest('fieldset.drop-section'); const target = event.target.closest('fieldset.drop-section');
let item = await fromUuid(data.uuid); let item = await fromUuid(data.uuid);

View file

@ -125,8 +125,8 @@ export default class ClassSheet extends DHBaseItemSheet {
async _onDrop(event) { async _onDrop(event) {
event.stopPropagation(); event.stopPropagation();
const data = TextEditor.getDragEventData(event); const data = TextEditor.getDragEventData(event);
const item = data.data ?? (await fromUuid(data.uuid)); const item = await fromUuid(data.uuid);
const itemType = data.data ? data.type : item.type; const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
const target = event.target.closest('fieldset.drop-section'); const target = event.target.closest('fieldset.drop-section');
if (itemType === 'subclass') { if (itemType === 'subclass') {
if (item.system.linkedClass) { if (item.system.linkedClass) {

View file

@ -1,4 +1,4 @@
<li class='feature-item' data-item-uuid='{{feature.uuid}}' data-type="{{type}}"> <li class='feature-item' data-item-uuid='{{feature.uuid}}' id="{{feature._id}}" data-type="{{type}}">
<div class='feature-line'> <div class='feature-line'>
<img class='image' src='{{feature.img}}' /> <img class='image' src='{{feature.img}}' />
<h4> <h4>

View file

@ -14,6 +14,7 @@
data-action="editDoc" data-action="editDoc"
data-item-uuid="{{document.system.primaryFeature.uuid}}" data-item-uuid="{{document.system.primaryFeature.uuid}}"
data-type="primary" data-type="primary"
id="{{document.system.primaryFeature._id}}"
> >
<img class="image" src="{{document.system.primaryFeature.img}}" /> <img class="image" src="{{document.system.primaryFeature.img}}" />
<span>{{document.system.primaryFeature.name}}</span> <span>{{document.system.primaryFeature.name}}</span>
@ -36,6 +37,7 @@
data-action="editDoc" data-action="editDoc"
data-item-uuid="{{document.system.secondaryFeature.uuid}}" data-item-uuid="{{document.system.secondaryFeature.uuid}}"
data-type="secondary" data-type="secondary"
id="{{document.system.secondaryFeature._id}}"
> >
<img class="image" src="{{document.system.secondaryFeature.img}}" /> <img class="image" src="{{document.system.secondaryFeature.img}}" />
<span>{{document.system.secondaryFeature.name}}</span> <span>{{document.system.secondaryFeature.name}}</span>

View file

@ -32,7 +32,7 @@
<input type="text" name="system.characterGuide.suggestedTraits.knowledge" value="{{source.system.characterGuide.suggestedTraits.knowledge}}" /> <input type="text" name="system.characterGuide.suggestedTraits.knowledge" value="{{source.system.characterGuide.suggestedTraits.knowledge}}" />
</fieldset> </fieldset>
<fieldset class="one-column"> <fieldset class="one-column {{#if (eq document.parent.type 'character')}}disabled{{/if}}">
<legend>{{localize "DAGGERHEART.ITEMS.Class.guide.suggestedEquipment"}}</legend> <legend>{{localize "DAGGERHEART.ITEMS.Class.guide.suggestedEquipment"}}</legend>
<fieldset class="one-column drop-section primary-weapon-section {{#if (eq document.parent.type 'character')}}inactive{{/if}}"> <fieldset class="one-column drop-section primary-weapon-section {{#if (eq document.parent.type 'character')}}inactive{{/if}}">
<legend>{{localize "DAGGERHEART.ITEMS.Class.guide.suggestedPrimaryWeaponTitle"}}</legend> <legend>{{localize "DAGGERHEART.ITEMS.Class.guide.suggestedPrimaryWeaponTitle"}}</legend>
@ -86,7 +86,7 @@
</fieldset> </fieldset>
</fieldset> </fieldset>
<fieldset class="one-column"> <fieldset class="one-column {{#if (eq document.parent.type 'character')}}disabled{{/if}}">
<legend>{{localize "DAGGERHEART.GENERAL.inventory"}}</legend> <legend>{{localize "DAGGERHEART.GENERAL.inventory"}}</legend>
<fieldset class="one-column drop-section take-section {{#if (eq document.parent.type 'character')}}inactive{{/if}}"> <fieldset class="one-column drop-section take-section {{#if (eq document.parent.type 'character')}}inactive{{/if}}">
<legend>{{localize "DAGGERHEART.GENERAL.take"}}</legend> <legend>{{localize "DAGGERHEART.GENERAL.take"}}</legend>