From e1be157f5a885fa08b66d9377962934e9df4054a Mon Sep 17 00:00:00 2001 From: Haxxer Date: Fri, 5 Jan 2024 10:45:37 +0000 Subject: [PATCH] Fixes --- changelog.md | 4 ++++ src/API/private-api.js | 2 +- src/helpers/transaction.js | 23 +++++++++++------------ src/stores/pile-item.js | 8 ++++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/changelog.md b/changelog.md index c1396e21..7ffde96c 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Item Piles Changelog +## Version 2.8.16 + +- Fixed items that were linked with the item linking module losing their links + ## Version 2.8.15 - Fixed non-stackable items being fully deleted when added to vaults even though they may have quantity in the origin character inventory diff --git a/src/API/private-api.js b/src/API/private-api.js index 03d148f1..09488c88 100644 --- a/src/API/private-api.js +++ b/src/API/private-api.js @@ -1097,7 +1097,7 @@ export default class PrivateAPI { } }) - await game.settings.set(CONSTANTS.MODULE_NAME, "defaultItemPileActorID", pileActor.id); + await game.settings.set(CONSTANTS.MODULE_NAME, SETTINGS.DEFAULT_ITEM_PILE_ACTOR_ID, pileActor.id); } diff --git a/src/helpers/transaction.js b/src/helpers/transaction.js index 6c3986e8..9f079632 100644 --- a/src/helpers/transaction.js +++ b/src/helpers/transaction.js @@ -100,39 +100,38 @@ export default class Transaction { this.itemsToUpdate.push(update); } + this.itemDeltas.set(actorExistingItem.id, (this.itemDeltas.has(actorExistingItem.id) ? this.itemDeltas.get(actorExistingItem.id) : 0) + incomingQuantity); + } else if (remove) { this.itemsToForceDelete.add(actorExistingItem.id); + this.itemDeltas.set(actorExistingItem.id, (this.itemDeltas.has(actorExistingItem.id) ? this.itemDeltas.get(actorExistingItem.id) : 0) + incomingQuantity); } else { - itemData._id = randomID(); + if (!itemData._id) { + itemData._id = randomID(); + } Utilities.setItemQuantity(itemData, incomingQuantity); this.itemsToCreate.push(itemData); this.itemTypeMap.set(itemData._id, type) } - this.itemDeltas.set(actorExistingItem.id, (this.itemDeltas.has(actorExistingItem.id) ? this.itemDeltas.get(actorExistingItem.id) : 0) + incomingQuantity); - } else { - - if (!itemData._id || !canItemStack) { - itemData._id = randomID(); - } - const existingItemCreation = Utilities.findSimilarItem(this.itemsToCreate, itemData); if (existingItemCreation && canItemStack) { const newQuantity = Utilities.getItemQuantity(existingItemCreation) + incomingQuantity; Utilities.setItemQuantity(existingItemCreation, newQuantity); } else { + if (!itemData._id) { + itemData._id = randomID(); + } Utilities.setItemQuantity(itemData, incomingQuantity); this.itemsToCreate.push(itemData); this.itemTypeMap.set(itemData._id, type) } - } - } } @@ -142,7 +141,7 @@ export default class Transaction { } this.actorUpdates = attributes.reduce((acc, attribute) => { const incomingQuantity = Math.abs(attribute.quantity) * (remove ? -1 : 1); - acc[attribute.path] = acc[attribute.path] ?? Number(getProperty(this.actor, attribute.path) ?? 0); + acc[attribute.path] = acc[attribute.path] ?? Number(foundry.utils.getProperty(this.actor, attribute.path) ?? 0); if (set) { if (!onlyDelta) { acc[attribute.path] = incomingQuantity @@ -165,7 +164,7 @@ export default class Transaction { if (this.attributeDeltas.get(entry[0]) === 0) { this.attributeDeltas.delete(entry[0]); } - return Number(getProperty(this.actor, entry[0])) !== entry[1]; + return Number(foundry.utils.getProperty(this.actor, entry[0])) !== entry[1]; })) this.itemsToCreate = this.itemsToCreate.filter(item => { return !PileUtilities.canItemStack(item, this.actor) || Utilities.getItemQuantity(item) > 0 || this.itemTypeMap.get(item._id) === "currency" diff --git a/src/stores/pile-item.js b/src/stores/pile-item.js index 06de91b1..447a5d27 100644 --- a/src/stores/pile-item.js +++ b/src/stores/pile-item.js @@ -8,6 +8,7 @@ import * as Helpers from "../helpers/helpers.js"; import { Plugins } from "../plugins/main.js"; import { SYSTEMS } from "../systems.js"; import * as CompendiumUtilities from "../helpers/compendium-utilities.js"; +import { updateItemData } from "../helpers/pile-utilities.js"; class PileBaseItem { @@ -200,10 +201,9 @@ export class PileItem extends PileBaseItem { } async updateFlags() { - await this.item.update({ - [CONSTANTS.FLAGS.ITEM]: get(this.itemFlagData), - [CONSTANTS.FLAGS.VERSION]: Helpers.getModuleVersion() - }) + await PileUtilities.updateItemData(this.item, { + flags: get(this.itemFlagData) + }); } preview() {