diff --git a/changelog.md b/changelog.md index 526e63f6..83053fa0 100644 --- a/changelog.md +++ b/changelog.md @@ -4,7 +4,8 @@ - Fixed very specific game crash surrounding currency rounding when buying multiple items with discounts with a specific currency setup - Fixed giving multiple quantity of a single item would always give just 1 -- Fixed Item Pile data resetting upon token updates +- Fixed item pile data resetting upon token updates +- Fixed item pile interfaces not reopening after changing their item pile type ## Version 3.0.5 diff --git a/src/applications/dialogs/drop-currency-dialog/drop-currency-dialog.js b/src/applications/dialogs/drop-currency-dialog/drop-currency-dialog.js index dea69d09..eb652306 100644 --- a/src/applications/dialogs/drop-currency-dialog/drop-currency-dialog.js +++ b/src/applications/dialogs/drop-currency-dialog/drop-currency-dialog.js @@ -13,8 +13,9 @@ export default class DropCurrencyDialog extends SvelteApplication { */ constructor(sourceActor, targetActor, settings = {}, options = {}) { const localization = settings.localization || "DropCurrencies"; + const id = sourceActor ? (sourceActor.id + (targetActor ? "-" + targetActor.id : "")) : ""; super({ - id: `item-pile-drop-currency-${sourceActor ? (sourceActor.id + (targetActor ? "-" + targetActor.id : "")) : ""}-${foundry.utils.randomID()}`, + id: `item-pile-drop-currency-${id}-${foundry.utils.randomID()}`, title: settings.title ?? game.i18n.localize(`ITEM-PILES.Applications.${localization}.Title`), svelte: { class: DropCurrencyDialogShell, @@ -39,13 +40,14 @@ export default class DropCurrencyDialog extends SvelteApplication { }) } - static getActiveApps(id) { + static getActiveApps(sourceActor, targetActor) { + const id = sourceActor ? (sourceActor.id + (targetActor ? "-" + targetActor.id : "")) : ""; return getActiveApps(`item-pile-drop-currency-${id}`); } static async show(sourceActor, targetActor, settings = {}, options = {}) { if (sourceActor) { - const apps = this.getActiveApps(targetActor ? sourceActor.uuid + "-" + targetActor.uuid : sourceActor.uuid); + const apps = this.getActiveApps(sourceActor, targetActor); if (apps.length) { for (let app of apps) { app.render(false, { focus: true }); diff --git a/src/applications/dialogs/drop-item-dialog/drop-item-dialog.js b/src/applications/dialogs/drop-item-dialog/drop-item-dialog.js index 0074164e..199549bd 100644 --- a/src/applications/dialogs/drop-item-dialog/drop-item-dialog.js +++ b/src/applications/dialogs/drop-item-dialog/drop-item-dialog.js @@ -13,9 +13,10 @@ export default class DropItemDialog extends SvelteApplication { constructor(item, target, options = { localizationTitle: "DropItem" }) { + const id = item.id + (target ? "-" + target.id : ""); super({ title: game.i18n.localize(`ITEM-PILES.Applications.${options.localizationTitle}.Title`), - id: `item-pile-drop-item-${item.id}${target ? "-" + target.id : ""}-${foundry.utils.randomID()}`, + id: `item-pile-drop-item-${id}-${foundry.utils.randomID()}`, svelte: { class: DropItemDialogShell, target: document.body, @@ -39,7 +40,8 @@ export default class DropItemDialog extends SvelteApplication { }) } - static getActiveApps(id) { + static getActiveApps(item, target) { + const id = item.id + (target ? "-" + target.id : ""); return getActiveApps(`item-pile-drop-item-${id}`); } @@ -47,7 +49,7 @@ export default class DropItemDialog extends SvelteApplication { if (!options?.localizationTitle) { options.localizationTitle = "DropItem"; } - const apps = this.getActiveApps(item.uuid + (target ? "-" + target.uuid : "")); + const apps = this.getActiveApps(item, target); if (apps.length) { for (let app of apps) { app.render(false, { focus: true }); diff --git a/src/applications/dialogs/give-items-dialog/give-items-dialog.js b/src/applications/dialogs/give-items-dialog/give-items-dialog.js index acd070e0..6cbfb517 100644 --- a/src/applications/dialogs/give-items-dialog/give-items-dialog.js +++ b/src/applications/dialogs/give-items-dialog/give-items-dialog.js @@ -37,12 +37,12 @@ export default class GiveItems extends TJSDialog { }) } - static getActiveApps(id) { - return getActiveApps(`item-pile-give-items-${id}`); + static getActiveApps(item) { + return getActiveApps(`item-pile-give-items-${item.id}`); } static async show(item, options = {}) { - const apps = this.getActiveApps(item.id); + const apps = this.getActiveApps(item); if (apps.length) { for (let app of apps) { app.render(false, { focus: true }); diff --git a/src/applications/dialogs/trade-merchant-item-dialog/trade-merchant-item-dialog.js b/src/applications/dialogs/trade-merchant-item-dialog/trade-merchant-item-dialog.js index 86d89501..bb9db2f0 100644 --- a/src/applications/dialogs/trade-merchant-item-dialog/trade-merchant-item-dialog.js +++ b/src/applications/dialogs/trade-merchant-item-dialog/trade-merchant-item-dialog.js @@ -45,7 +45,7 @@ export default class TradeMerchantItemDialog extends SvelteApplication { } static async show(item, seller, buyer, settings = {}, options = {}) { - const apps = this.getActiveApps(item.uuid + "-" + seller.uuid + "-" + buyer.uuid); + const apps = this.getActiveApps(item.id + "-" + seller.id + "-" + buyer.id); if (apps.length) { for (let app of apps) { app.render(false, { focus: true }); diff --git a/src/applications/item-pile-config/item-pile-config.svelte b/src/applications/item-pile-config/item-pile-config.svelte index bba3d643..8c0b9424 100644 --- a/src/applications/item-pile-config/item-pile-config.svelte +++ b/src/applications/item-pile-config/item-pile-config.svelte @@ -77,22 +77,22 @@ let apps = []; switch (currentData.type) { case CONSTANTS.PILE_TYPES.MERCHANT: - if (MerchantApp.getActiveApp(pileActor.uuid)) { - promises.push(MerchantApp.getActiveApp(pileActor.uuid).close()); + if (MerchantApp.getActiveApp(pileActor)) { + promises.push(MerchantApp.getActiveApp(pileActor).close()); } - if (MerchantApp.getActiveApp(pileActor?.token?.uuid)) { - promises.push(MerchantApp.getActiveApp(pileActor?.token?.uuid).close()); + if (MerchantApp.getActiveApp(pileActor)) { + promises.push(MerchantApp.getActiveApp(pileActor).close()); } break; case CONSTANTS.PILE_TYPES.VAULT: - apps = VaultApp.getActiveApps(pileActor.uuid) - .concat(VaultApp.getActiveApps(pileActor?.token?.uuid)); + apps = VaultApp.getActiveApps(pileActor) + .concat(VaultApp.getActiveApps(pileActor)); break; default: - apps = ItemPileInventoryApp.getActiveApps(pileActor.uuid) - .concat(ItemPileInventoryApp.getActiveApps(pileActor?.token?.uuid)); + apps = ItemPileInventoryApp.getActiveApps(pileActor) + .concat(ItemPileInventoryApp.getActiveApps(pileActor)); break; } diff --git a/src/applications/item-pile-inventory-app/item-pile-inventory-app.js b/src/applications/item-pile-inventory-app/item-pile-inventory-app.js index bbfeea99..389c9efc 100644 --- a/src/applications/item-pile-inventory-app/item-pile-inventory-app.js +++ b/src/applications/item-pile-inventory-app/item-pile-inventory-app.js @@ -50,7 +50,8 @@ export default class ItemPileInventoryApp extends SvelteApplication { } static getActiveApps(source) { - return Helpers.getActiveApps(`item-pile-inventory-${source?.token?.id ?? source.id}`); + const id = typeof source === "string" ? source : source?.token?.id ?? source?.id; + return Helpers.getActiveApps(`item-pile-inventory-${id}`); } static async show(source, recipient = false, options = {}, dialogData = {}) { diff --git a/src/applications/vault-app/vault-app.js b/src/applications/vault-app/vault-app.js index 3f97a4c7..2c09b1dd 100644 --- a/src/applications/vault-app/vault-app.js +++ b/src/applications/vault-app/vault-app.js @@ -60,7 +60,8 @@ export default class VaultApp extends SvelteApplication { } static getActiveApps(source) { - return Helpers.getActiveApps(`item-pile-vault-${source?.token?.id ?? source.id}`); + const id = typeof source === "string" ? source : source?.token?.id ?? source?.id; + return Helpers.getActiveApps(`item-pile-vault-${id}`); } static async show(source, recipient = false, options = {}, dialogData = {}) { diff --git a/src/helpers/pile-utilities.js b/src/helpers/pile-utilities.js index 3f1c5a8f..41b68fe1 100644 --- a/src/helpers/pile-utilities.js +++ b/src/helpers/pile-utilities.js @@ -630,11 +630,11 @@ function getRelevantTokensAndActor(target) { } -export async function updateItemPileData(target, flagData, tokenData) { +export async function updateItemPileData(target, newFlags, tokenData) { if (!target) return; - flagData = getActorFlagData(target, { data: flagData }); + const flagData = getActorFlagData(target, { data: newFlags }); if (!tokenData) tokenData = {}; tokenData = foundry.utils.mergeObject(tokenData, {}); @@ -649,7 +649,7 @@ export async function updateItemPileData(target, flagData, tokenData) { const freshFlagData = getActorFlagData(target, { useDefaults: false }); const cleanedFlagData = cleanFlagData(flagData); const cleanFreshFlagData = cleanFlagData(freshFlagData); - const combinedFreshFlagData = cleanFlagData(foundry.utils.mergeObject(cleanedFlagData, cleanFreshFlagData), { addRemoveFlag: true }); + const combinedFreshFlagData = cleanFlagData(foundry.utils.mergeObject(cleanFreshFlagData, cleanedFlagData), { addRemoveFlag: true }); const updates = documentTokens.map(tokenDocument => { const overrideImage = foundry.utils.getProperty(tokenData, "texture.src")