Skip to content

Commit

Permalink
Merge pull request #589 from fantasycalendar/Item_container_support
Browse files Browse the repository at this point in the history
Item container support
  • Loading branch information
Haxxer authored Aug 23, 2024
2 parents 83c177a + ab28e05 commit 5c9d42d
Show file tree
Hide file tree
Showing 22 changed files with 643 additions and 223 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Item Piles Changelog

## Version 3.1.0

- Added support for "container" type items in D&D5e - this is a custom implementation, so other systems' containers will not work out of the box
- Splitting currencies in item piles takes into account across all currencies across containers in the pile
- Added tree-like display for items in containers

## Version 3.0.11

- Added `ITEM-PILES.Trade` localization for compatibility with Rest Recovery
Expand Down
64 changes: 32 additions & 32 deletions docs/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -612,12 +612,12 @@ Called after an item has been dropped on the canvas.

Called before an item is added to the target. This is not called in any transfers.

| Param | Type | Description |
|---------------|----------------------------------|-------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument</code> | The target that is going to receive the items |
| itemsToCreate | <code>array</code> | An array of objects each containing the item and the quantity that is going to be created |
| itemsToUpdate | <code>array</code> | An array of objects each containing the item and the quantity that is going to be updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |
| Param | Type | Description |
|------------------------|----------------------------------|-------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument</code> | The target that is going to receive the items |
| itemsToCreate | <code>array</code> | An array of objects each containing the item and the quantity that is going to be created |
| itemQuantitiesToUpdate | <code>array</code> | An array of objects each containing the item and the quantity that is going to be updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |

If the hook returns `false`, the action is interrupted.

Expand All @@ -640,12 +640,12 @@ Called after an item has been added to the target. This is not called in any tra

Called before an item is removed from the target. This is not called in any transfers.

| Param | Type | Description |
|---------------|----------------------------------|-------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument</code> | The target that is going to have items removed |
| itemsToDelete | <code>array</code> | An array of objects each containing the item id that is going to be deleted |
| itemsToUpdate | <code>array</code> | An array of objects each containing the item and the quantity that is going to be updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |
| Param | Type | Description |
|------------------------|----------------------------------|-------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument</code> | The target that is going to have items removed |
| itemsToDelete | <code>array</code> | An array of objects each containing the item id that is going to be deleted |
| itemQuantitiesToUpdate | <code>array</code> | An array of objects each containing the item and the quantity that is going to be updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |

If the hook returns `false`, the action is interrupted.

Expand Down Expand Up @@ -949,13 +949,13 @@ Called after all attributes' values was transferred from the source to the targe

Called before currencies are updated to an actor. Not called in the case of a transfer.

| Param | Type | Description |
|---------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument/UUID</code> | The target that will have currencies added to it |
| actorUpdates | <code>object</code> | An object, where the keys are the attribute that is going to be updated, the value being the quantity is going to be changed |
| itemsToCreate | <code>array</code> | An array of objects each containing the item id and the quantity that was added |
| itemsToUpdate | <code>array</code> | An array of objects each containing the item id and the quantity that was updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |
| Param | Type | Description |
|------------------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument/UUID</code> | The target that will have currencies added to it |
| actorUpdates | <code>object</code> | An object, where the keys are the attribute that is going to be updated, the value being the quantity is going to be changed |
| itemsToCreate | <code>array</code> | An array of objects each containing the item id and the quantity that was added |
| itemQuantitiesToUpdate | <code>array</code> | An array of objects each containing the item id and the quantity that was updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |

If the hook returns `false`, the action is interrupted.

Expand All @@ -979,13 +979,13 @@ Called after currencies were updated to the target. Not called in the case of a

Called before currencies are added to an actor. Not called in the case of a transfer.

| Param | Type | Description |
|---------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument/UUID</code> | The target that will have currencies added to it |
| actorUpdates | <code>object</code> | An object, where the keys are the attribute that is going to be updated, the value being the quantity is going to be changed |
| itemsToCreate | <code>array</code> | An array of objects each containing the item id and the quantity that was added |
| itemsToUpdate | <code>array</code> | An array of objects each containing the item id and the quantity that was updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |
| Param | Type | Description |
|------------------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument/UUID</code> | The target that will have currencies added to it |
| actorUpdates | <code>object</code> | An object, where the keys are the attribute that is going to be updated, the value being the quantity is going to be changed |
| itemsToCreate | <code>array</code> | An array of objects each containing the item id and the quantity that was added |
| itemQuantitiesToUpdate | <code>array</code> | An array of objects each containing the item id and the quantity that was updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |

If the hook returns `false`, the action is interrupted.

Expand All @@ -1009,12 +1009,12 @@ Called after currencies were added to the target. Not called in the case of a tr

Called before currencies were removed from the target. Not called in the case of a transfer.

| Param | Type | Description |
|---------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument/UUID</code> | The target that will have its currencies removed |
| actorUpdates | <code>object</code> | An object, where the keys are the attribute that is going to be updated, the value being the quantity is going to be changed |
| itemsToUpdate | <code>array</code> | An array of objects each containing the item id and the quantity that was updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |
| Param | Type | Description |
|------------------------|---------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| target | <code>Actor/TokenDocument/UUID</code> | The target that will have its currencies removed |
| actorUpdates | <code>object</code> | An object, where the keys are the attribute that is going to be updated, the value being the quantity is going to be changed |
| itemQuantitiesToUpdate | <code>array</code> | An array of objects each containing the item id and the quantity that was updated |
| interactionId | <code>string/boolean</code> | The ID of this interaction, to identify ongoing transfers |

If the hook returns `false`, the action is interrupted.

Expand Down
37 changes: 18 additions & 19 deletions src/API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import TradeAPI from "./trade-api.js";
import PrivateAPI from "./private-api.js";
import { SYSTEMS } from "../systems.js";
import ItemPileConfig from "../applications/item-pile-config/item-pile-config.js";
import { getCharactersForItemPile } from "../helpers/sharing-utilities.js";

class API {
/**
Expand Down Expand Up @@ -1082,37 +1081,37 @@ class API {
}

/**
* Whether an item pile is an auctioneer. If it is not enabled, it is always false.
* Whether an item pile is a banker. If it is not enabled, it is always false.
*
* @param {Token/TokenDocument} target
* @param {Object/boolean} [data=false] data existing flags data to use
* @return {boolean}
*/
static isItemPileAuctioneer(target, data = false) {
if (!game.modules.get("item_piles_auctioneer")?.active) {
static isItemPileBanker(target, data = false) {
if (!game.modules.get("item_piles_bankers")?.active) {
let word = "install and activate";
if (game.modules.get('item_piles_auctioneer')) word = "activate";
Helpers.custom_warning(`This api method from Item Piles requires the 'item_piles_auctioneer' module. Please ${word} it.`, true);
if (game.modules.get('item_piles_bankers')) word = "activate";
Helpers.custom_warning(`This api method from Item Piles requires the 'item_piles_bankers' module. Please ${word} it.`, true);
return false;
}
return PileUtilities.isItemPileAuctioneer(target, data);
return PileUtilities.isItemPileBanker(target, data);
}

/**
* Whether an item pile is a banker. If it is not enabled, it is always false.
* Whether an item pile is a merchant. If it is not enabled, it is always false.
*
* @param {Token/TokenDocument} target
* @param {Object/boolean} [data=false] data existing flags data to use
* @return {boolean}
*/
static isItemPileBanker(target, data = false) {
if (!game.modules.get("item_piles_bankers")?.active) {
static isItemPileAuctioneer(target, data = false) {
if (!game.modules.get("item_piles_auctioneer")?.active) {
let word = "install and activate";
if (game.modules.get('item_piles_bankers')) word = "activate";
Helpers.custom_warning(`This api method from Item Piles requires the 'item_piles_bankers' module. Please ${word} it.`, true);
if (game.modules.get('item_piles_auctioneer')) word = "activate";
Helpers.custom_warning(`This api method from Item Piles requires the 'item_piles_auctioneer' module. Please ${word} it.`, true);
return false;
}
return PileUtilities.isItemPileBanker(target, data);
return PileUtilities.isItemPileAuctioneer(target, data);
}

/**
Expand Down Expand Up @@ -1203,13 +1202,10 @@ class API {
throw Helpers.custom_error("SplitItemPileContents | instigator must be of type TokenDocument or Actor")
}

const actorUuids = (targets || SharingUtilities.getCharactersForItemPile(itemPileActor))
const actorUuids = (targets || SharingUtilities.getPlayersForItemPile(itemPileActor)
.map(u => u.character))
.map(actor => Utilities.getUuid(actor));

if (!actorUuids.length) {
throw Helpers.custom_error("SplitItemPileContents | Could not find any characters to split item piles' content with")
}

return ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.SPLIT_PILE, itemPileUuid, actorUuids, game.user.id, instigator);

}
Expand Down Expand Up @@ -1984,6 +1980,7 @@ class API {
purchaseData: [{ cost: overallCost, quantity, secondaryPrices }],
buyer: targetActor
});

}

/**
Expand Down Expand Up @@ -2263,7 +2260,9 @@ class API {

if (items) {
for (const entry of items) {
entry.item = targetActor ? targetActor.items.get(entry.item._id) : new Item.implementation(entry.item);
entry.item = targetActor
? targetActor.items.get(entry.item._id)
: new Item.implementation(entry.item);
}
}

Expand Down
Loading

0 comments on commit 5c9d42d

Please sign in to comment.