Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jan 5, 2024
1 parent 99bed2f commit e1be157
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/API/private-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}

Expand Down
23 changes: 11 additions & 12 deletions src/helpers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

}

}
}

Expand All @@ -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
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/stores/pile-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit e1be157

Please sign in to comment.