Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Aug 23, 2024
1 parent 295c2cb commit c46e00e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/API/chat-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ export default class ChatAPI {

return this._createNewChatMessage(game.user.id, {
user: game.user.id,
type: isPrivate && CONSTANTS.IS_V12 ? CHAT_MESSAGE_STYLES.WHISPER : CHAT_MESSAGE_STYLES.OTHER,
type: isPrivate && !CONSTANTS.IS_V12 ? CHAT_MESSAGE_STYLES.WHISPER : CHAT_MESSAGE_STYLES.OTHER,
content: chatCardHtml,
flavor: "Item Piles" + (isPrivate ? ": " + game.i18n.localize("ITEM-PILES.Chat.PrivateTrade") : ""),
speaker: ChatMessage.getSpeaker({ alias: game.user.name }),
Expand Down
35 changes: 14 additions & 21 deletions src/API/private-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,24 +1033,29 @@ export default class PrivateAPI {

let itemsDropped;

foundry.utils.setProperty(itemData.item, game.itempiles.API.ITEM_QUANTITY_ATTRIBUTE, itemData?.quantity ?? 1);
const items = [itemData.item];
const item = fromUuidSync(itemData.uuid);
const handler = Utilities.getItemTypeHandler(CONSTANTS.ITEM_TYPE_METHODS.TRANSFER, item.type);
if (handler) handler({ item, items });

// If there's a source of the item (it wasn't dropped from the item bar)
if (sourceUuid) {

foundry.utils.setProperty(itemData.item, game.itempiles.API.ITEM_QUANTITY_ATTRIBUTE, itemData.quantity);

// If there's a target token, add the item to it, otherwise create a new pile at the drop location
if (targetUuid) {
itemsDropped = await this._transferItems(sourceUuid, targetUuid, [itemData.item], userId);
itemsDropped = await this._transferItems(sourceUuid, targetUuid, items, userId);
} else {
itemsDropped = (await this._removeItems(sourceUuid, [itemData.item], userId)).map(item => {

itemsDropped = (await this._removeItems(sourceUuid, items, userId)).map(item => {
item.quantity = Math.abs(item.quantity)
Utilities.setItemQuantity(item.item, Math.abs(item.quantity), true);
return item;
});
targetUuid = await this._createItemPile({
sceneId, position, items: itemsDropped, tokenOverrides: {
elevation: elevation || fromUuidSync(sourceUuid)?.elevation || 0
}
}, checkContainers: false
})
}

Expand All @@ -1059,10 +1064,10 @@ export default class PrivateAPI {

// If there's a target token, add the item to it, otherwise create a new pile at the drop location
if (targetUuid) {
itemsDropped = await this._addItems(targetUuid, [itemData], userId);
itemsDropped = await this._addItems(targetUuid, items, userId);
} else {
targetUuid = await this._createItemPile({
sceneId, position, items: [itemData], tokenOverrides: { elevation: elevation || 0 }
sceneId, position, items, tokenOverrides: { elevation: elevation || 0 }
});
}

Expand All @@ -1083,7 +1088,7 @@ export default class PrivateAPI {
tokenOverrides = {},
actorOverrides = {},
itemPileFlags = {},
folders = false,
folders = false
} = {}) {

let returns = {};
Expand Down Expand Up @@ -1186,8 +1191,6 @@ export default class PrivateAPI {

await game.settings.set(CONSTANTS.MODULE_NAME, SETTINGS.DEFAULT_ITEM_PILE_ACTOR_ID, pileActor.id);

} else {

}

} else {
Expand All @@ -1210,16 +1213,6 @@ export default class PrivateAPI {
}
items[i] = itemData;
}
if (SYSTEMS.DATA.ITEM_TYPE_HANDLERS) {
const newItems = [];
for (const itemData of items) {
const item = new Item.implementation(itemData);
const handler = Utilities.getItemTypeHandler(CONSTANTS.ITEM_TYPE_METHODS.TRANSFER, item.type);
if (!handler) continue;
handler({ item, items: newItems });
}
items = items.concat(newItems);
}
} else {
items = []
}
Expand Down Expand Up @@ -1660,7 +1653,7 @@ export default class PrivateAPI {

const dropData = {
source: false, target: data?.target ?? false, elevation: data?.elevation, itemData: {
item: itemData, quantity: 1,
item: itemData, quantity: 1, uuid: data?.uuid
}, position: false
};

Expand Down
2 changes: 2 additions & 0 deletions src/helpers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export default class Transaction {
? Math.abs(data.quantity ?? Utilities.getItemQuantity(itemData))
: Math.abs(data.quantity ?? Utilities.getItemQuantity(itemData)) * (remove ? -1 : 1);

console.log(itemData.name, incomingQuantity);

let itemId = itemData._id ?? itemData.id;
let documentHasItem = false;
let documentExistingItem = false;
Expand Down
8 changes: 7 additions & 1 deletion src/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,13 @@ const Requests = {
return false;
}
Requests._addTimeout(handler);
const result = await method();
let result;
try {
result = await method();
} catch (err) {
Requests._clearPendingTimeout(handler);
return false;
}
Requests._clearPendingTimeout(handler);
Requests._unresponsiveGM = false;
Requests._lastGmUnresponsiveTimestamp = false;
Expand Down

0 comments on commit c46e00e

Please sign in to comment.