Skip to content

Commit

Permalink
Fixes to interfaces and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Jul 5, 2024
1 parent 6e480e6 commit 49f0ce7
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 24 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 });
Expand Down
8 changes: 5 additions & 3 deletions src/applications/dialogs/drop-item-dialog/drop-item-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,15 +40,16 @@ 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}`);
}

static async show(item, target, options = {}) {
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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
16 changes: 8 additions & 8 deletions src/applications/item-pile-config/item-pile-config.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
3 changes: 2 additions & 1 deletion src/applications/vault-app/vault-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) {
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/pile-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, {});

Expand All @@ -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")
Expand Down

0 comments on commit 49f0ce7

Please sign in to comment.