[Fix] Inventory Item Transfer (#1316)

* Fixed so items from the inventory tab of the Party sheet can be dragged out

* Added transfer logic

* Added translation

* Improved item transfer dialog title

* Simplified title

* Updated image

* Simplified the handlebars templates for itemTransfer

* Improved item-identicial check

* Slight improved rendering

* .
This commit is contained in:
WBHarry 2025-11-23 15:04:42 +01:00 committed by GitHub
parent 9f7554cdff
commit 2920ead81a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 228 additions and 47 deletions

View file

@ -1,3 +1,4 @@
import { itemIsIdentical } from '../../../helpers/utils.mjs';
import DHBaseActorSettings from './actor-setting.mjs';
import DHApplicationMixin from './application-mixin.mjs';
@ -217,6 +218,70 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
/* Application Drag/Drop */
/* -------------------------------------------- */
async _onDrop(event) {
const data = foundry.applications.ux.TextEditor.implementation.getDragEventData(event);
if (data.originActor === this.document.uuid) return { cancel: true };
/* Handling transfer of inventoryItems */
let cancel = false;
const physicalActorTypes = ['character', 'party'];
if (physicalActorTypes.includes(this.document.type)) {
const originActor = data.originActor ? await foundry.utils.fromUuid(data.originActor) : null;
if (data.originId && originActor && physicalActorTypes.includes(originActor.type)) {
const dropDocument = await foundry.utils.fromUuid(data.uuid);
if (dropDocument.system.metadata.isInventoryItem) {
cancel = true;
if (dropDocument.system.metadata.isQuantifiable) {
const actorItem = originActor.items.get(data.originId);
const quantityTransfered =
actorItem.system.quantity === 1
? 1
: await game.system.api.applications.dialogs.ItemTransferDialog.configure(dropDocument);
if (quantityTransfered) {
if (quantityTransfered === actorItem.system.quantity) {
await originActor.deleteEmbeddedDocuments('Item', [data.originId]);
} else {
cancel = true;
await actorItem.update({
'system.quantity': actorItem.system.quantity - quantityTransfered
});
}
const existingItem = this.document.items.find(x => itemIsIdentical(x, dropDocument));
if (existingItem) {
cancel = true;
await existingItem.update({
'system.quantity': existingItem.system.quantity + quantityTransfered
});
} else {
const createData = dropDocument.toObject();
await this.document.createEmbeddedDocuments('Item', [
{
...createData,
system: {
...createData.system,
quantity: quantityTransfered
}
}
]);
}
} else {
cancel = true;
}
} else {
await originActor.deleteEmbeddedDocuments('Item', [data.originId], { render: false });
const createData = dropDocument.toObject();
await this.document.createEmbeddedDocuments('Item', [createData]);
}
}
}
}
return { cancel };
}
/**
* On dragStart on the item.
* @param {DragEvent} event - The drag event