Skip to content

Commit

Permalink
Merge pull request #542 from p4535992/add_some_check_to_the_api
Browse files Browse the repository at this point in the history
Externalize some utilities method to the api
  • Loading branch information
Haxxer authored Mar 10, 2024
2 parents 3f7f3b6 + 71431e2 commit c9f8024
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 18 deletions.
121 changes: 112 additions & 9 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
* [rattleItemPile](#rattleItemPile)
* [isItemPileLocked](#isItemPileLocked)
* [isItemPileClosed](#isItemPileClosed)
* [isValidItemPile](#isValidItemPile)
* [isRegularItemPile](#isRegularItemPile)
* [isItemPileContainer](#isItemPileContainer)
* [isItemPileLootable](#isItemPileLootable)
* [isItemPileVault](#isItemPileVault)
* [isItemPileMerchant](#isItemPileMerchant)
* [isItemPileAuctioneer](#isItemPileAuctioneer)
* [isItemPileEmpty](#isItemPileEmpty)
* [updateItemPile](#updateItemPile)
* [deleteItemPile](#deleteItemPile)
* [splitItemPileContents](#splitItemPileContents)
Expand Down Expand Up @@ -515,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 |

---

Expand All @@ -527,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 |

---

Expand All @@ -539,12 +574,78 @@ 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 |

---

### 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 Expand Up @@ -1243,3 +1344,5 @@ Trades multiple items between one actor to another, and currencies and/or change
| items | `Array<Object<{item: Item/string, quantity: number, paymentIndex: number}>>` | | 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 |



92 changes: 84 additions & 8 deletions src/API/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -951,33 +951,109 @@ 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 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);
}

/**
* Whether an item pile is empty pile. If it is not enabled, it is always false.
*
* @param {Token/TokenDocument} target
* @return {boolean}
*/
static isItemPileContainer(target) {
return PileUtilities.isItemPileContainer(target);
static isItemPileEmpty(target) {
return PileUtilities.isItemPileEmpty(target);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ const CONSTANTS = {
PILE: "pile",
CONTAINER: "container",
MERCHANT: "merchant",
VAULT: "vault"
VAULT: "vault",
AUCTIONEER: "auctioneer",
},

VAULT_LOGGING_TYPES: {
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/pile-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/helpers/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export function refreshItemTypesThatCanStack() {
getItemTypesThatCanStack();
}

/**
* Retrieve all system item types that can be stacked
* @returns {Set<string>} The items type that can be stacked on this system
*/
export function getItemTypesThatCanStack() {
if (!itemTypesWithQuantities) {

Expand Down

0 comments on commit c9f8024

Please sign in to comment.