Skip to content

Commit

Permalink
Fixed giving items, interface updating being broken in v11
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jul 4, 2024
1 parent c7c2305 commit 109b567
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Item Piles Changelog

## Version 3.0.5

- Fixed issue in Foundry v11 that would cause item piles to not refresh when items and currencies were taken from them, allowing users to take multiple items
- Fixed bug with giving item always giving 1 item

## Version 3.0.4

- Fixed random-ish errors when duplicating item piles and then trying to open their interfaces
Expand Down
6 changes: 4 additions & 2 deletions src/API/private-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1846,8 +1846,6 @@ export default class PrivateAPI {

if (user?.active || gms.length || game.user.isGM) {

dropData.itemData.quantity = 1;

if (PileUtilities.canItemStack(dropData.itemData.item)) {
let itemQuantity = Utilities.getItemQuantity(item);
if ((!itemQuantity || itemQuantity <= 0)) {
Expand All @@ -1858,7 +1856,11 @@ export default class PrivateAPI {
dropData.itemData.quantity = await DropItemDialog.show(item, dropData.target.actor, {
localizationTitle: "GiveItem"
});
} else if (!dropData.itemData.quantity) {
dropData.itemData.quantity = 1;
}
} else {
dropData.itemData.quantity = 1;
}

Utilities.setItemQuantity(dropData.itemData.item, dropData.itemData.quantity);
Expand Down
7 changes: 5 additions & 2 deletions src/stores/item-pile-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ export default class ItemPileStore {
setupSubscriptions() {

this.subscribeTo(this.document, () => {
const { renderData } = this.document.updateOptions;
const updateData = this.document.updateOptions;
const renderData = updateData?.renderData ?? updateData?.data ?? {};
if (foundry.utils.hasProperty(renderData, CONSTANTS.FLAGS.SHARING)) {
this.shareData.set(SharingUtilities.getItemPileSharingData(this.actor));
13
this.refreshItems();
}
if (foundry.utils.hasProperty(renderData, CONSTANTS.FLAGS.PILE)) {
Expand All @@ -164,7 +166,8 @@ export default class ItemPileStore {

if (this.recipientDocument) {
this.subscribeTo(this.recipientDocument, () => {
const { renderData } = this.document.updateOptions;
const updateData = this.document.updateOptions;
const renderData = updateData?.renderData ?? updateData?.data ?? {};
if (foundry.utils.hasProperty(renderData, CONSTANTS.FLAGS.SHARING)) {
this.recipientShareData.set(SharingUtilities.getItemPileSharingData(this.recipient));
this.refreshItems();
Expand Down
6 changes: 4 additions & 2 deletions src/stores/pile-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export class PileItem extends PileBaseItem {
});

this.subscribeTo(this.itemDocument, () => {
const { renderData } = this.itemDocument.updateOptions;
const updateData = this.itemDocument.updateOptions;
const renderData = updateData?.renderData ?? updateData?.data ?? {};
const itemData = CompendiumUtilities.findSimilarItemInCompendiumSync(this.item);
this.name.set(itemData?.name ?? this.item.name);
this.img.set(itemData?.img ?? this.item.img);
Expand Down Expand Up @@ -253,7 +254,8 @@ export class PileAttribute extends PileBaseItem {
});

this.subscribeTo(this.store.document, () => {
const { renderData } = this.store.document.updateOptions;
const updateData = this.store.document.updateOptions;
const renderData = updateData?.renderData ?? updateData?.data ?? {};
this.path = this.attribute.path;
this.name.set(this.attribute.name);
this.img.set(this.attribute.img);
Expand Down
3 changes: 2 additions & 1 deletion src/stores/vault-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ export class VaultStore extends ItemPileStore {
});

this.subscribeTo(this.document, () => {
const { renderData } = this.document.updateOptions;
const updateData = this.document.updateOptions;
const renderData = updateData?.renderData ?? updateData?.data ?? {};
if (foundry.utils.hasProperty(renderData, CONSTANTS.FLAGS.LOG)) {
this.processLogEntries();
}
Expand Down

0 comments on commit 109b567

Please sign in to comment.