Skip to content

Commit

Permalink
add isItemPileEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Mar 9, 2024
1 parent 2ace21f commit 23cbec2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
14 changes: 14 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* [isItemPileVault](#isItemPileVault)
* [isItemPileMerchant](#isItemPileMerchant)
* [isItemPileAuctioneer](#isItemPileAuctioneer)
* [isItemPileEmpty](#isItemPileEmpty)
* [updateItemPile](#updateItemPile)
* [deleteItemPile](#deleteItemPile)
* [splitItemPileContents](#splitItemPileContents)
Expand Down Expand Up @@ -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`
Expand Down
27 changes: 7 additions & 20 deletions src/API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -2555,14 +2550,6 @@ class API {

}

/**
* Retrieve all system item types that can be stacked
* @returns {Set<string>} The items type that can be stacked on this system
*/
static getItemTypesThatCanStack() {
return Utilities.getItemTypesThatCanStack();
}

static canItemFitInVault(item, vaultActor) {
return PileUtilities.canItemFitInVault(item, vaultActor);
}
Expand Down

0 comments on commit 23cbec2

Please sign in to comment.