From fe375cf2208d2821c77a659d3337af4aff64c5fd Mon Sep 17 00:00:00 2001 From: p4535992 Date: Sun, 3 Mar 2024 14:49:07 +0100 Subject: [PATCH 1/6] add 'getItemTypesThatCanStack' to the api for support complex operation on other modules --- docs/api.md | 13 +++++++++++++ src/API/api.js | 8 ++++++++ src/helpers/utilities.js | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/docs/api.md b/docs/api.md index ac556692..5e6e5ccf 100644 --- a/docs/api.md +++ b/docs/api.md @@ -83,6 +83,7 @@ * [rollItemTable](#rollItemTable) * [getPricesForItem](#getPricesForItem) * [tradeItems](#tradeItems) + * [getItemTypesThatCanStack](#getItemTypesThatCanStack) ## System settings methods @@ -1243,3 +1244,15 @@ Trades multiple items between one actor to another, and currencies and/or change | items | `Array>` | | An array of objects containing the item or the id of the item to be sold, the quantity to be sold, and the payment index to be used | | [interactionId] | `string/boolean` | `false` | The ID of this interaction | +### getItemTypesThatCanStack + +`game.itempiles.API.getItemTypesThatCanStack()` ⇒ `Set` + +Retrieve all system item types that can be stacked + +**Returns**: `Set` - The items that were created and the attributes that were changed + +| Param | Type | Default | Description | +|-----------------|------------------------------------------------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| + + diff --git a/src/API/api.js b/src/API/api.js index bd6bc442..20a3134f 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -2474,6 +2474,14 @@ class API { } + /** + * Retrieve all system item types that can be stacked + * @returns {Set} The items that can be stacked on this system + */ + static getItemTypesThatCanStack() { + return Utilities.getItemTypesThatCanStack(); + } + static canItemFitInVault(item, vaultActor) { return PileUtilities.canItemFitInVault(item, vaultActor); } diff --git a/src/helpers/utilities.js b/src/helpers/utilities.js index 87ddebb4..f8014140 100644 --- a/src/helpers/utilities.js +++ b/src/helpers/utilities.js @@ -132,6 +132,10 @@ export function refreshItemTypesThatCanStack() { getItemTypesThatCanStack(); } +/** + * Retrieve all system item types that can be stacked + * @returns {Set} The items that can be stacked on this system + */ export function getItemTypesThatCanStack() { if (!itemTypesWithQuantities) { From b550ece575b0693b0ad63159c6648608d7db48e3 Mon Sep 17 00:00:00 2001 From: p4535992 Date: Sun, 3 Mar 2024 14:54:43 +0100 Subject: [PATCH 2/6] better english --- docs/api.md | 2 +- src/API/api.js | 2 +- src/helpers/utilities.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index 5e6e5ccf..fb7b85a3 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1250,7 +1250,7 @@ Trades multiple items between one actor to another, and currencies and/or change Retrieve all system item types that can be stacked -**Returns**: `Set` - The items that were created and the attributes that were changed +**Returns**: `Set` - The items type that can be stacked on this system | Param | Type | Default | Description | |-----------------|------------------------------------------------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| diff --git a/src/API/api.js b/src/API/api.js index 20a3134f..4967acdd 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -2476,7 +2476,7 @@ class API { /** * Retrieve all system item types that can be stacked - * @returns {Set} The items that can be stacked on this system + * @returns {Set} The items type that can be stacked on this system */ static getItemTypesThatCanStack() { return Utilities.getItemTypesThatCanStack(); diff --git a/src/helpers/utilities.js b/src/helpers/utilities.js index f8014140..4ae3fb4c 100644 --- a/src/helpers/utilities.js +++ b/src/helpers/utilities.js @@ -134,7 +134,7 @@ export function refreshItemTypesThatCanStack() { /** * Retrieve all system item types that can be stacked - * @returns {Set} The items that can be stacked on this system + * @returns {Set} The items type that can be stacked on this system */ export function getItemTypesThatCanStack() { if (!itemTypesWithQuantities) { From 12452493647e786f99b4971911a9e7ba2b6e8a23 Mon Sep 17 00:00:00 2001 From: p4535992 Date: Sat, 9 Mar 2024 18:57:38 +0100 Subject: [PATCH 3/6] externalize some utility method --- docs/api.md | 105 +++++++++++++++++++++++++++++++--- src/API/api.js | 97 ++++++++++++++++++++++++++++--- src/constants/constants.js | 3 +- src/helpers/pile-utilities.js | 6 ++ 4 files changed, 193 insertions(+), 18 deletions(-) diff --git a/docs/api.md b/docs/api.md index fb7b85a3..0ca79c2a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -39,7 +39,13 @@ * [rattleItemPile](#rattleItemPile) * [isItemPileLocked](#isItemPileLocked) * [isItemPileClosed](#isItemPileClosed) + * [isValidItemPile](#isValidItemPile) + * [isRegularItemPile](#isRegularItemPile) * [isItemPileContainer](#isItemPileContainer) + * [isItemPileLootable](#isItemPileLootable) + * [isItemPileVault](#isItemPileVault) + * [isItemPileMerchant](#isItemPileMerchant) + * [isItemPileAuctioneer](#isItemPileAuctioneer) * [updateItemPile](#updateItemPile) * [deleteItemPile](#deleteItemPile) * [splitItemPileContents](#splitItemPileContents) @@ -516,9 +522,10 @@ Causes the item pile to play a sound as it was attempted to be opened, but was l Whether an item pile is locked. If it is not enabled or not a container, it is always false. -| Param | Type | -|--------|-----------------------| -| target | `Token/TokenDocument` | +| Param | Type | Default | Description | +|--------------------|-------------------------------|---------|-------------------------------| +| target | `Token/TokenDocument` | | Target token to check | +| [data] | `Object/boolean` | `false` | Existing data flags to use | --- @@ -528,9 +535,36 @@ Whether an item pile is locked. If it is not enabled or not a container, it is a Whether an item pile is closed. If it is not enabled or not a container, it is always false. -| Param | Type | -|--------|-----------------------| -| target | `Token/TokenDocument` | +| Param | Type | Default | Description | +|--------------------|-------------------------------|---------|-------------------------------| +| target | `Token/TokenDocument` | | Target token to check | +| [data] | `Object/boolean` | `false` | Existing data flags to use | + +--- + +### isValidItemPile + +`game.itempiles.API.isValidItemPile(target)` ⇒ `boolean` + +Whether an item pile is a valid item pile. 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 | + +--- + +### isRegularItemPile + +`game.itempiles.API.isRegularItemPile(target)` ⇒ `boolean` + +Whether an item pile is a regular item pile. 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 | --- @@ -540,9 +574,62 @@ Whether an item pile is closed. If it is not enabled or not a container, it is a Whether an item pile is a container. If it is not enabled, it is always false. -| Param | Type | -|--------|-----------------------| -| target | `Token/TokenDocument` | +| Param | Type | Default | Description | +|--------------------|-------------------------------|---------|-------------------------------| +| target | `Token/TokenDocument` | | Target token to check | +| [data] | `Object/boolean` | `false` | Existing data flags to use | + +--- + +### isItemPileLootable + +`game.itempiles.API.isItemPileLootable(target)` ⇒ `boolean` + +Whether an item pile is a lootable. 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 | + +--- + +### isItemPileVault + +`game.itempiles.API.isItemPileVault(target)` ⇒ `boolean` + +Whether an item pile is a vault. 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 | + +--- + +### isItemPileMerchant + +`game.itempiles.API.isItemPileMerchant(target)` ⇒ `boolean` + +Whether an item pile is a merchant. 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 | + +--- + +### isItemPileAuctioneer + +`game.itempiles.API.isItemPileAuctioneer(target)` ⇒ `boolean` + +Whether an item pile is a auctioneer. 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 | --- diff --git a/src/API/api.js b/src/API/api.js index 4967acdd..2a9a5372 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -951,33 +951,114 @@ class API { * Whether an item pile is locked. If it is not enabled or not a container, it is always false. * * @param {Token/TokenDocument} target - * + * @param {Object/boolean} [data=false] data existing flags data to use * @return {boolean} */ - static isItemPileLocked(target) { - return PileUtilities.isItemPileLocked(target); + static isItemPileLocked(target, data = false) { + return PileUtilities.isItemPileLocked(target, data); } /** * Whether an item pile is closed. If it is not enabled or not a container, it is always false. * * @param {Token/TokenDocument} target - * + * @param {Object/boolean} [data=false] data existing flags data to use * @return {boolean} */ - static isItemPileClosed(target) { - return PileUtilities.isItemPileClosed(target); + static isItemPileClosed(target, data = false) { + return PileUtilities.isItemPileClosed(target, data); } + /** + * Whether an item pile is a valid item pile. 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 isValidItemPile(target, data = false) { + return PileUtilities.isValidItemPile(target, data); + } + + /** + * Whether an item pile is a regular item pile. 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 isRegularItemPile(target, data = false) { + return PileUtilities.isRegularItemPile(target, data); + } + /** * Whether an item pile is a container. 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 isItemPileContainer(target, data = false) { + return PileUtilities.isItemPileContainer(target, data); + } + + /** + * Whether an item pile is a lootable. 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 isItemPileContainer(target) { - return PileUtilities.isItemPileContainer(target); + static isItemPileLootable(target, data = false) { + return PileUtilities.isItemPileLootable(target, data); + } + + /** + * Whether an item pile is a vault. 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 isItemPileVault(target, data = false) { + return PileUtilities.isItemPileVault(target, data); + } + + /** + * 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 isItemPileMerchant(target, data = false) { + return PileUtilities.isItemPileMerchant(target, data); + } + + /** + * 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 isItemPileAuctioneer(target, data = false) { + return PileUtilities.isItemPileAuctioneer(target, data); + } + + static isItemPileEmpty(target) { + + const targetActor = Utilities.getActor(target); + if (!targetActor) return false; + + const validItemPile = isValidItemPile(targetActor); + if (!validItemPile) return false; + + const hasNoItems = getActorItems(targetActor).length === 0; + const hasNoAttributes = getActorCurrencies(targetActor).length === 0; + + return validItemPile && hasNoItems && hasNoAttributes; + } /** diff --git a/src/constants/constants.js b/src/constants/constants.js index 6602342d..e514ab3c 100644 --- a/src/constants/constants.js +++ b/src/constants/constants.js @@ -75,7 +75,8 @@ const CONSTANTS = { PILE: "pile", CONTAINER: "container", MERCHANT: "merchant", - VAULT: "vault" + VAULT: "vault", + AUCTIONEER: "auctioneer", }, VAULT_LOGGING_TYPES: { diff --git a/src/helpers/pile-utilities.js b/src/helpers/pile-utilities.js index a701e8f8..bb50c337 100644 --- a/src/helpers/pile-utilities.js +++ b/src/helpers/pile-utilities.js @@ -129,6 +129,12 @@ export function isItemPileMerchant(target, data = false) { return pileData?.enabled && pileData?.type === CONSTANTS.PILE_TYPES.MERCHANT; } +export function isItemPileAuctioneer(target, data = false) { + const targetActor = Utilities.getActor(target); + const pileData = getActorFlagData(targetActor, data); + return pileData?.enabled && pileData?.type === CONSTANTS.PILE_TYPES.AUCTIONEER; +} + export function isItemPileClosed(target, data = false) { const targetActor = Utilities.getActor(target); const pileData = getActorFlagData(targetActor, data); From 2ace21fedc0f73ceea3c144363ba36bdae54a051 Mon Sep 17 00:00:00 2001 From: p4535992 Date: Sat, 9 Mar 2024 19:01:13 +0100 Subject: [PATCH 4/6] removed getItemTypesThatCanStack from api.md --- docs/api.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/docs/api.md b/docs/api.md index 0ca79c2a..bea566e5 100644 --- a/docs/api.md +++ b/docs/api.md @@ -89,7 +89,6 @@ * [rollItemTable](#rollItemTable) * [getPricesForItem](#getPricesForItem) * [tradeItems](#tradeItems) - * [getItemTypesThatCanStack](#getItemTypesThatCanStack) ## System settings methods @@ -1331,15 +1330,5 @@ Trades multiple items between one actor to another, and currencies and/or change | items | `Array>` | | An array of objects containing the item or the id of the item to be sold, the quantity to be sold, and the payment index to be used | | [interactionId] | `string/boolean` | `false` | The ID of this interaction | -### getItemTypesThatCanStack - -`game.itempiles.API.getItemTypesThatCanStack()` ⇒ `Set` - -Retrieve all system item types that can be stacked - -**Returns**: `Set` - The items type that can be stacked on this system - -| Param | Type | Default | Description | -|-----------------|------------------------------------------------------------------------------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| From 23cbec2a478d1a9ef79b19e127a14d28d9b323ef Mon Sep 17 00:00:00 2001 From: p4535992 Date: Sat, 9 Mar 2024 19:05:15 +0100 Subject: [PATCH 5/6] add isItemPileEmpty --- docs/api.md | 14 ++++++++++++++ src/API/api.js | 27 +++++++-------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/api.md b/docs/api.md index bea566e5..27115e7a 100644 --- a/docs/api.md +++ b/docs/api.md @@ -46,6 +46,7 @@ * [isItemPileVault](#isItemPileVault) * [isItemPileMerchant](#isItemPileMerchant) * [isItemPileAuctioneer](#isItemPileAuctioneer) + * [isItemPileEmpty](#isItemPileEmpty) * [updateItemPile](#updateItemPile) * [deleteItemPile](#deleteItemPile) * [splitItemPileContents](#splitItemPileContents) @@ -632,6 +633,19 @@ Whether an item pile is a auctioneer. If it is not enabled, it is always false. --- +### isItemPileEmpty + +`game.itempiles.API.isItemPileEmpty(target)` ⇒ `boolean` + +Whether an item pile is a empty pile. If it is not enabled, it is always false. + +| Param | Type | Default | Description | +|--------------------|-------------------------------|---------|-------------------------------| +| target | `Token/TokenDocument` | | Target token to check | + +--- + + ### updateItemPile `game.itempiles.API.updateItemPile(target, newData, options)` ⇒ `Promise` diff --git a/src/API/api.js b/src/API/api.js index 2a9a5372..7b59519c 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -1046,19 +1046,14 @@ class API { return PileUtilities.isItemPileAuctioneer(target, data); } + /** + * Whether an item pile is empty. If it is not enabled, it is always false. + * + * @param {Token/TokenDocument} target + * @return {boolean} + */ static isItemPileEmpty(target) { - - const targetActor = Utilities.getActor(target); - if (!targetActor) return false; - - const validItemPile = isValidItemPile(targetActor); - if (!validItemPile) return false; - - const hasNoItems = getActorItems(targetActor).length === 0; - const hasNoAttributes = getActorCurrencies(targetActor).length === 0; - - return validItemPile && hasNoItems && hasNoAttributes; - + return PileUtilities.isItemPileEmpty(target); } /** @@ -2555,14 +2550,6 @@ class API { } - /** - * Retrieve all system item types that can be stacked - * @returns {Set} The items type that can be stacked on this system - */ - static getItemTypesThatCanStack() { - return Utilities.getItemTypesThatCanStack(); - } - static canItemFitInVault(item, vaultActor) { return PileUtilities.canItemFitInVault(item, vaultActor); } From 71431e2c0b935c6f593fa6d80f92aea4d695c27e Mon Sep 17 00:00:00 2001 From: p4535992 Date: Sat, 9 Mar 2024 19:08:13 +0100 Subject: [PATCH 6/6] update doc --- src/API/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/API/api.js b/src/API/api.js index 7b59519c..aeeb1077 100644 --- a/src/API/api.js +++ b/src/API/api.js @@ -1047,7 +1047,7 @@ class API { } /** - * Whether an item pile is empty. If it is not enabled, it is always false. + * Whether an item pile is empty pile. If it is not enabled, it is always false. * * @param {Token/TokenDocument} target * @return {boolean}