From bcb78ac762317bd752fe61c7a1082e305df5d4e3 Mon Sep 17 00:00:00 2001 From: Haxxer Date: Wed, 17 Jan 2024 08:01:36 +0000 Subject: [PATCH] Fixes --- src/API/api.js | 10 +++++----- src/API/private-api.js | 2 +- src/helpers/pile-utilities.js | 4 ++-- src/helpers/transaction.js | 7 +++---- src/stores/vault-store.js | 4 +--- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/API/api.js b/src/API/api.js index 08216516..64588bc7 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -1215,9 +1215,9 @@ class API { } else if (itemData.item) { item = itemData.item instanceof Item ? itemData.item.toObject() : itemData.item; if (itemData.flags) { - foundry.utils.setProperty(item, "flags", foundry.utils.mergeObject( - foundry.utils.getProperty(item, "flags") ?? {}, - foundry.utils.getProperty(itemData, "flags")) + foundry.utils.setProperty(item, CONSTANTS.FLAGS.ITEM, foundry.utils.mergeObject( + foundry.utils.getProperty(item, CONSTANTS.FLAGS.ITEM) ?? {}, + foundry.utils.getProperty(itemData, CONSTANTS.FLAGS.ITEM)) ); } } else if (itemData.id) { @@ -1352,7 +1352,7 @@ class API { return { id: item._id, quantity: Math.max(itemData?.quantity ?? Utilities.getItemQuantity(itemData), 0), - flags: foundry.utils.getProperty(itemData, "flags") + flags: foundry.utils.getProperty(itemData, CONSTANTS.FLAGS.ITEM) } }); @@ -1700,7 +1700,7 @@ class API { * * @param {Array} currencies An array of object containing the data and quantity for each currency | * @param {number} currencies[].cost The cost of the currency -| * @param {string} currencies[].denom The abbreviation of the currency, which are usually {#}GP, which when {#} is replaced with the number it becomes 5GP. +| * @param {string} currencies[].denom The abbreviation of the currency, which are usually {#}GP, which when {#} is replaced with the number it becomes 5GP. * @param {string} currencies[].percent The cost of the currency is in percentage (for work the 'abbreviation' property must includes '%' substring) * @returns {string} An array of object containing the data and quantity for each currency */ diff --git a/src/API/private-api.js b/src/API/private-api.js index 03fb88ff..cced5bab 100644 --- a/src/API/private-api.js +++ b/src/API/private-api.js @@ -1642,7 +1642,7 @@ export default class PrivateAPI { foundry.utils.setProperty(flagData, "x", dropData.gridPosition?.x ?? 0); foundry.utils.setProperty(flagData, "y", dropData.gridPosition?.y ?? 0); } - foundry.utils.setProperty(dropData.itemData, "flags", flagData); + foundry.utils.setProperty(dropData.itemData, CONSTANTS.FLAGS.ITEM, flagData); if (sourceActor) { return game.itempiles.API.transferItems(sourceActor, targetActor, [dropData.itemData], { interactionId: dropData.interactionId }); diff --git a/src/helpers/pile-utilities.js b/src/helpers/pile-utilities.js index 6c7583b9..63a9e623 100644 --- a/src/helpers/pile-utilities.js +++ b/src/helpers/pile-utilities.js @@ -1953,7 +1953,7 @@ export async function rollTable({ if (existingItem) { existingItem.quantity += Math.max(newItem.quantity, 1); } else { - setProperty(newItem, "flags", newItem.item.flags); + setProperty(newItem, CONSTANTS.FLAGS.ITEM, getProperty(newItem.item, CONSTANTS.FLAGS.ITEM)); if (game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE && !getProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE)) { setProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE, Utilities.getItemQuantity(newItem.item)); } @@ -2044,7 +2044,7 @@ export async function rollMerchantTables({ tableData = false, actor = false } = if (existingItem) { existingItem.quantity += Math.max(newItem.quantity, 1); } else { - setProperty(newItem, "flags", newItem.item.flags); + setProperty(newItem, CONSTANTS.FLAGS.ITEM, newItem.item.flags); if (game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE && !getProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE)) { setProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE, Utilities.getItemQuantity(newItem.item)); } diff --git a/src/helpers/transaction.js b/src/helpers/transaction.js index 9f079632..0e11bbfd 100644 --- a/src/helpers/transaction.js +++ b/src/helpers/transaction.js @@ -1,6 +1,5 @@ import * as Utilities from "./utilities.js"; import * as PileUtilities from "./pile-utilities.js"; -import { areItemsColliding, getItemFlagData } from "./pile-utilities.js"; import ItemPileSocket from "../socket.js"; import PrivateAPI from "../API/private-api.js"; import { SYSTEMS } from "../systems.js"; @@ -56,7 +55,7 @@ export default class Transaction { foundry.utils.getProperty(itemData, CONSTANTS.FLAGS.ITEM + ".y") === undefined ) || - areItemsColliding(item, itemData) + PileUtilities.areItemsColliding(item, itemData) ) }); } else { @@ -181,8 +180,8 @@ export default class Transaction { this.itemDeltas = Array.from(this.itemDeltas).map(([id, quantity]) => { const item = this.actor.items.get(id).toObject(); - const existingFlagData = getItemFlagData(item); - const newFlagData = this.itemFlagMap.get(id) ?? {}; + const existingFlagData = PileUtilities.cleanItemFlagData(PileUtilities.getItemFlagData(item)); + const newFlagData = PileUtilities.cleanItemFlagData(this.itemFlagMap.get(id) ?? {}); setProperty(item, CONSTANTS.FLAGS.ITEM, foundry.utils.mergeObject(existingFlagData, newFlagData)); const type = this.itemTypeMap.get(id); Utilities.setItemQuantity(item, quantity, true); diff --git a/src/stores/vault-store.js b/src/stores/vault-store.js index d30de9e0..89e05010 100644 --- a/src/stores/vault-store.js +++ b/src/stores/vault-store.js @@ -319,8 +319,6 @@ export class VaultStore extends ItemPileStore { async onDropData(data, event, isExpander) { - debugger; - let validPosition = get(this.dragPosition); this.dragPosition.set({ x: 0, y: 0, w: 1, h: 1, flipped: false, active: false }); @@ -546,7 +544,7 @@ export class VaultItem extends PileItem { setProperty(flags, "x", x); setProperty(flags, "y", y); setProperty(flags, "flipped", flipped); - setProperty(itemData, "flags", flags); + setProperty(itemData, CONSTANTS.FLAGS.ITEM, flags); await game.itempiles.API.addItems(this.store.actor, [{ item: itemData, quantity