Skip to content

Commit 32c6ff3

Browse files
committed
Fix treasure duplication when drop area is same as parent
1 parent 556a5cf commit 32c6ff3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

module/sheets/actor-sheet-utils.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,30 @@ async function prepareData(context, sheet) {
4242

4343
/**
4444
* @description Helper function to find the appropriate update configuration
45+
* @param {FUActor} sourceActor
4546
* @param type
4647
* @param subtype
4748
* @returns {{types: string[], subtypes: string[], update: ((function(*, *): Promise<void>)|*)} | {types: string[], update: ((function(*): Promise<void>)|*)}}
4849
*/
49-
function findItemConfig(type, subtype) {
50+
function findItemConfig(sourceActor, type, subtype) {
5051
const itemTypeConfigs = [
5152
{
5253
types: ['treasure'],
5354
subtypes: ['artifact', 'material', 'treasure'],
5455
update: async (itemData, item) => {
56+
// Do not duplicate if on self
57+
if (item.parent === sourceActor) {
58+
return;
59+
}
5560
const incrementValue = itemData.system.quantity?.value || 1;
5661
const newQuantity = (item.system.quantity.value || 0) + incrementValue;
5762
await item.update({ 'system.quantity.value': newQuantity });
5863
},
5964
},
6065
{
66+
// Effects are handled separately
6167
types: ['effect'],
6268
update: async (itemData) => {
63-
// Effects are handled separately
6469
return;
6570
},
6671
},
@@ -279,7 +284,7 @@ async function handleStashDrop(actor, item) {
279284
const existingItem = actor.items.find((i) => i.name === item.name && i.type === item.type);
280285
if (existingItem) {
281286
const subtype = item.system.subtype?.value;
282-
const config = findItemConfig(item.type, subtype);
287+
const config = findItemConfig(actor, item.type, subtype);
283288
if (config) {
284289
await config.update(item, existingItem);
285290
console.debug(`${item.name} was appended onto ${actor.name}`);

module/sheets/actor-standard-sheet.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ export class FUStandardActorSheet extends FUActorSheet {
604604

605605
const subtype = item.system.subtype?.value;
606606
// Determine the configuration based on item type
607-
const config = ActorSheetUtils.findItemConfig(item.type, subtype);
607+
const config = ActorSheetUtils.findItemConfig(item.parent, item.type, subtype);
608608
if (config) {
609609
// Check if there is an active ProseMirror editor
610610
const activeEditor = document.querySelector('.editor-content.ProseMirror');

0 commit comments

Comments
 (0)