From 3a18e8ecaad4baa8f11a868171d2761a206ab3c2 Mon Sep 17 00:00:00 2001 From: p4535992 Date: Thu, 18 Apr 2024 13:10:02 +0200 Subject: [PATCH 1/4] ready to test --- docs/api.md | 25 ++++++++++--- languages/en.json | 8 ++++- src/API/api.js | 24 +++++++++++-- src/API/private-api.js | 4 +++ .../item-pile-config/item-pile-config.svelte | 8 +++++ .../item-pile-config/settings/main.svelte | 16 +++++++++ src/constants/constants.js | 11 ++++-- src/helpers/pile-utilities.js | 12 +++++++ src/module.js | 36 +++++++++++++++++++ 9 files changed, 133 insertions(+), 11 deletions(-) diff --git a/docs/api.md b/docs/api.md index 27115e7a..f18ea46c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -46,6 +46,7 @@ * [isItemPileVault](#isItemPileVault) * [isItemPileMerchant](#isItemPileMerchant) * [isItemPileAuctioneer](#isItemPileAuctioneer) + * [isItemPileBanker](#isItemPileBanker) * [isItemPileEmpty](#isItemPileEmpty) * [updateItemPile](#updateItemPile) * [deleteItemPile](#deleteItemPile) @@ -633,6 +634,19 @@ Whether an item pile is a auctioneer. If it is not enabled, it is always false. --- +### isItemPileBanker + +`game.itempiles.API.isItemPileBanker(target)` ⇒ `boolean` + +Whether an item pile is a banker. If it is not enabled, it is always false. + +| Param | Type | Default | Description | +|--------------------|-------------------------------|---------|-------------------------------| +| target | `Token/TokenDocument` | | Target token to check | +| [data] | `Object/boolean` | `false` | Existing data flags to use | + +--- + ### isItemPileEmpty `game.itempiles.API.isItemPileEmpty(target)` ⇒ `boolean` @@ -766,11 +780,12 @@ Refreshes the merchant's inventory, potentially removing existing items and popu **Returns**: `Promise>` - An array of object containing the item data and their quantity -| Param | Type | Default | Description | -|------------------------------------|------------------------------------|---------|--------------------------------------------------------------------------------| -| target | `Actor/TokenDocument/Token/String` | | The merchant actor to refresh the inventory of | -| options | `object` | | Options to pass to the function | -| [options.removeExistingActorItems] | `boolean` | `true` | Whether to clear the merchant's existing inventory before adding the new items | +| Param | Type | Default | Description | +|-------------------------------------|------------------------------------|---------|--------------------------------------------------------------------------------| +| target | `Actor/TokenDocument/Token/String` | | The merchant actor to refresh the inventory of | +| options | `object` | | Options to pass to the function | +| [options.removeExistingActorItems] | `boolean` | `true` | Whether to clear the merchant's existing inventory before adding the new items | +| [options.ignoreCheckOnMerchantType] | `boolean` | `false` | Populate this target with the same roll tables set on the merchant settings, but on actor with the merchant type disabled | --- diff --git a/languages/en.json b/languages/en.json index c852bb00..d3d7e600 100644 --- a/languages/en.json +++ b/languages/en.json @@ -37,7 +37,9 @@ "DropNoToken": "You don't have a token on this scene, so you can't drop any items here.", "NoVaultAccess": "You don't have permission to view this vault.", "NoVaultAccessActor": "{actor_name} doesn't have permission to view this vault.", - "ItemNoQuantity": "{item_name} has 0 quantity, so you can't transfer this item!" + "ItemNoQuantity": "{item_name} has 0 quantity, so you can't transfer this item!", + "NoRollTableAndNoActorIsPresent": "No actor or any tables is present", + "NoRollTableIsPresent": "No tables is been set on the actor {actorName}" }, "Warnings": { "NoGMsConnected": "WARNING - No GMs connected - Item Piles requires a GM to be connected for players to be able to utilize most of the module's features.", @@ -555,6 +557,10 @@ "DeleteWhenEmptyDefault": "Default module setting", "DeleteWhenEmptyYes": "Yes, delete when empty", "DeleteWhenEmptyNo": "No, don't delete when empty", + "OnCreateTokenRollTable": "Refresh the inventory on the token when created", + "OnCreateTokenRollTableExplanation": "With this setting, when the actor token is created on the canvas it will refresh the inventory on the token based on some rollTable. NOTE: You must set at least have one roll table set , and if the actor is set to be a merchant by default all the old items are removed so be aware...", + "OnCreateTokenRollTableNoMerchant": "Refresh the inventory on the token when created even if is not a merchant", + "OnCreateTokenRollTableExplanationNoMerchant": "With this setting, the effect of the setting 'Refresh the inventory on the token when created' is been applied even if this is not a merchant. NOTE: for security reason Vault, Banker, Auctioneer are excluded", "CanStackItems": "Can Stack Items", "CanStackItemsExplanation": "With this setting, items added to the item pile will stack with similar items. This can also be controlled per-item in their configuration. Note: This is dependent on the system as well, since some items do not have quantity so they can never be stacked.", "CanStackItemsYes": "Yes, stack items (unless item says otherwise)", diff --git a/src/API/api.js b/src/API/api.js index 3a1d469b..3412cdd5 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -1081,7 +1081,7 @@ class API { } /** - * Whether an item pile is a merchant. If it is not enabled, it is always false. + * Whether an item pile is a auctioneer. If it is not enabled, it is always false. * * @param {Token/TokenDocument} target * @param {Object/boolean} [data=false] data existing flags data to use @@ -1097,6 +1097,23 @@ class API { return PileUtilities.isItemPileAuctioneer(target, data); } + /** + * 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 isItemPileBanker(target, data = false) { + if(!game.modules.get("item_piles_bankers")?.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); + return false; + } + return PileUtilities.isItemPileBanker(target, data); + } + /** * Whether an item pile is empty pile. If it is not enabled, it is always false. * @@ -2257,9 +2274,10 @@ class API { * @param {Actor/Token/TokenDocument} target The merchant actor to refresh the inventory of * @param {object} options Options to pass to the function * @param {boolean} [options.removeExistingActorItems=true] Whether to clear the merchant's existing inventory before adding the new items + * @param {boolean} [options.ignoreCheckOnMerchantType=false] Populate this target with the same roll tables set on the merchant settings, but on actor with the merchant type disabled * @returns {Promise} */ - static async refreshMerchantInventory(target, { removeExistingActorItems = true } = {}) { + static async refreshMerchantInventory(target, { removeExistingActorItems = true, ignoreCheckOnMerchantType = false } = {}) { if (target) { target = Utilities.getActor(target); @@ -2270,7 +2288,7 @@ class API { const targetUuid = Utilities.getUuid(target); - if (!PileUtilities.isItemPileMerchant(target)) { + if (!ignoreCheckOnMerchantType && !PileUtilities.isItemPileMerchant(target)) { throw Helpers.custom_error(`refreshMerchantInventory | target of uuid ${targetUuid} is not a merchant`); } diff --git a/src/API/private-api.js b/src/API/private-api.js index 29797584..e5813027 100644 --- a/src/API/private-api.js +++ b/src/API/private-api.js @@ -1062,6 +1062,8 @@ export default class PrivateAPI { pileDataDefaults.showItemName = true; pileDataDefaults.overrideSingleItemScale = true; pileDataDefaults.singleItemScale = 0.75; + pileDataDefaults.onCreateTokenRollTable = false; + pileDataDefaults.onCreateTokenRollTableNoMerchant = false; } pileDataDefaults = foundry.utils.mergeObject(pileDataDefaults, itemPileFlags); @@ -1114,6 +1116,8 @@ export default class PrivateAPI { pileDataDefaults.showItemName = true; pileDataDefaults.overrideSingleItemScale = true; pileDataDefaults.singleItemScale = 0.75; + pileDataDefaults.onCreateTokenRollTable = false; + pileDataDefaults.onCreateTokenRollTableNoMerchant = false; } pileDataDefaults = foundry.utils.mergeObject(pileDataDefaults, itemPileFlags); diff --git a/src/applications/item-pile-config/item-pile-config.svelte b/src/applications/item-pile-config/item-pile-config.svelte index b86acb92..70e07995 100644 --- a/src/applications/item-pile-config/item-pile-config.svelte +++ b/src/applications/item-pile-config/item-pile-config.svelte @@ -34,6 +34,14 @@ pileData.deleteWhenEmpty = !!pileData?.deleteWhenEmpty; } + if (typeof pileData?.onCreateTokenRollTable === "boolean") { + pileData.onCreateTokenRollTable = !!pileData?.onCreateTokenRollTable; + } + + if (typeof pileData?.onCreateTokenRollTableNoMerchant === "boolean") { + pileData.onCreateTokenRollTableNoMerchant = !!pileData?.onCreateTokenRollTableNoMerchant; + } + let pileEnabled = writable(pileData.enabled); $: pileData.enabled = $pileEnabled; diff --git a/src/applications/item-pile-config/settings/main.svelte b/src/applications/item-pile-config/settings/main.svelte index 0f8f9118..d9590318 100644 --- a/src/applications/item-pile-config/settings/main.svelte +++ b/src/applications/item-pile-config/settings/main.svelte @@ -158,6 +158,22 @@ +
+ + +
+ +
+ + +
+