From 23cbec2a478d1a9ef79b19e127a14d28d9b323ef Mon Sep 17 00:00:00 2001 From: p4535992 Date: Sat, 9 Mar 2024 19:05:15 +0100 Subject: [PATCH] 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); }