Skip to content

Commit

Permalink
API improvements, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Haxxer committed Aug 25, 2024
1 parent efaae57 commit f4f0f0f
Show file tree
Hide file tree
Showing 6 changed files with 246 additions and 60 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added tree-like display for items in containers
- Added support for currency exchange in custom item purchase prices
- If you have configured an item that costs 1 gold piece and 1 magical rock, and you only have 1 platinum piece and 1 magical rock, you now get 9 gold pieces back as change, whereas before you needed exactly 1 gold piece and 1 magical rock.
- Added `game.itempiles.API.combineItemPiles` which allows you to combine several item piles' inventory into a single item pile
- Added option for a custom sell price on items
- Added detection for when the GM is unresponsive for item piles to make changes for players
- Fixed localization issue with `ITEM-PILES.Trade`, now moved to `ITEM-PILES.PlayerList.TradeButton`
Expand Down
141 changes: 82 additions & 59 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
* [transferAttributes](#transferAttributes)
* [transferAllAttributes](#transferAllAttributes)
* [transferEverything](#transferEverything)
* [combineItemPiles](#combineItemPiles)
* [updateCurrencies](#updateCurrencies)
* [addCurrencies](#addCurrencies)
* [removeCurrencies](#removeCurrencies)
Expand Down Expand Up @@ -522,10 +523,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 | Default | Description |
|--------------------|-------------------------------|---------|-------------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -535,10 +536,10 @@ 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 | Default | Description |
|--------------------|-------------------------------|---------|-------------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -548,10 +549,10 @@ Whether an item pile is closed. If it is not enabled or not a container, it is a

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 |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -561,10 +562,10 @@ Whether an item pile is a valid item pile. If it is not enabled, it is always fa

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 |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -574,10 +575,10 @@ Whether an item pile is a regular item pile. If it is not enabled, it is always

Whether an item pile is a container. 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 |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -587,10 +588,10 @@ Whether an item pile is a container. If it is not enabled, it is always false.

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 |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -600,10 +601,10 @@ Whether an item pile is a lootable. If it is not enabled, it is always false.

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 |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -613,10 +614,10 @@ Whether an item pile is a vault. If it is not enabled, it is always false.

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 |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -626,10 +627,10 @@ 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 | Type | Default | Description |
|--------------------|-------------------------------|---------|-------------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |
| Param | Type | Default | Description |
|--------|-----------------------|---------|----------------------------|
| target | `Token/TokenDocument` | | Target token to check |
| [data] | `Object/boolean` | `false` | Existing data flags to use |

---

Expand All @@ -639,13 +640,12 @@ Whether an item pile is a auctioneer. If it is not enabled, it is always false.

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 |
| Param | Type | Default | Description |
|--------|-----------------------|---------|-----------------------|
| target | `Token/TokenDocument` | | Target token to check |

---


### updateItemPile

`game.itempiles.API.updateItemPile(target, newData, options)``Promise`
Expand Down Expand Up @@ -951,21 +951,41 @@ Transfers all items and attributes between the source and the target.

**Returns**: `Promise<object>` - An object containing all items and attributes transferred to the target

| Param | Type | Default | Description |
|-------------------------|-----------------------------|---------|-----------------------------------------------------------------------------------|
| source | `Actor/Token/TokenDocument` | | The actor to transfer all items and attributes from |
| target | `Actor/Token/TokenDocument` | | The actor to receive all the items and attributes |
| options | `object` | | Options to pass to the function |
| [options.itemFilters] | `Array/boolean` | `false` | Array of item types disallowed - will default to module settings if none provided |
| [options.interactionId] | `string/boolean` | `false` | The ID of this interaction |
| Param | Type | Default | Description |
|----------------------------|-----------------------------|---------|-----------------------------------------------------------------------------------|
| source | `Actor/Token/TokenDocument` | | The actor to transfer all items and attributes from |
| target | `Actor/Token/TokenDocument` | | The actor to receive all the items and attributes |
| options | `object` | | Options to pass to the function |
| [options.itemFilters] | `Array/boolean` | `false` | Array of item types disallowed - will default to module settings if none provided |
| [options.skipVaultLogging] | `boolean` | `false` | Whether to skip logging this action to the target actor if it is a vault |
| [options.interactionId] | `string/boolean` | `false` | The ID of this interaction |

---

### combineItemPiles

`game.itempiles.API.combineItemPiles(target, sources, options)``Promise<object>`

Transfers all items and attributes between the source and the target.

**Returns**: `Promise<object>` - An object containing all items and attributes transferred to the target

| Param | Type | Default | Description |
|-------------------------------|-----------------------------|---------|-----------------------------------------------------------------------------------|
| target | `Actor/Token/TokenDocument` | | The actor to transfer items and currencies to |
| sources | `Actor/Token/TokenDocument` | | The actors to transfer items and currencies from |
| options | `object` | | Options to pass to the function |
| [options.itemFilters] | `Array/boolean` | `false` | Array of item types disallowed - will default to module settings if none provided |
| [options.targetItemPileFlags] | `object/boolean` | `false` | Item pile flags to set on the target as a part of this transfer |
| [options.interactionId] | `string/boolean` | `false` | The ID of this interaction |

---

### updateCurrencies

`game.itempiles.API.updateCurrencies(target, currencies, options)``Promise<object>`

Updates currencies to the target.
Updates currencies to the target.
It differs from the add and remove operations in that it "sets" the currency of the target with the passed value.
This is useful in cases where you want to pre-fill something with a specific amount of currency.

Expand Down Expand Up @@ -1108,9 +1128,11 @@ Transfers all currencies between the source and the target.

Turns an array containing the data and quantities for each currency into a string of currencies

**NOTE:** This is just a utility method for module intercompatibility to use the other currencies api methods based on a string input.
**NOTE:
** This is just a utility method for module intercompatibility to use the other currencies api methods based on a string input.

**Returns**: `Array.<string>` - An array of string containing the abbreviation for each currency registered (eg, ["GP","SP"])
**Returns
**: `Array.<string>` - An array of string containing the abbreviation for each currency registered (eg, ["GP","SP"])

---

Expand All @@ -1120,16 +1142,17 @@ Turns an array containing the data and quantities for each currency into a strin

Turns an array containing the data and quantities for each currency into a string of currencies

**NOTE:** This is just a utility method for module intercompatibility to use the other currencies api methods based on a string input.
**NOTE:
** This is just a utility method for module intercompatibility to use the other currencies api methods based on a string input.

**Returns**: `string` - A string of currencies to add (eg, "5gp 25sp")

| Param | Type | Default | Description |
|---------------------------|----------|---------|------------------------------------------------|
| currencies | `Array` | | An array of object containing the data and quantity for each currency |
| currencies[].cost | `number` | | The quantity of the currency |
| currencies[].abbreviation | `string` | | The abbreviation of the currency, which are usually {#}GP, which when {#} is replaced with the number it becomes 5GP. |
| currencies[].percent | `boolean`| | The cost of the currency is in percentage (NOTE: for work the 'abbreviation' property must includes '%' substring) |
| Param | Type | Default | Description |
|---------------------------|-----------|---------|-----------------------------------------------------------------------------------------------------------------------|
| currencies | `Array` | | An array of object containing the data and quantity for each currency |
| currencies[].cost | `number` | | The quantity of the currency |
| currencies[].abbreviation | `string` | | The abbreviation of the currency, which are usually {#}GP, which when {#} is replaced with the number it becomes 5GP. |
| currencies[].percent | `boolean` | | The cost of the currency is in percentage (NOTE: for work the 'abbreviation' property must includes '%' substring) |

---

Expand Down Expand Up @@ -1189,8 +1212,8 @@ Turns a string of currencies or a number into an object containing payment data,

const tokenOrActor = game.actors.getName("Bharash");
const currencies = {
cost: 10,
abbreviation: "GP",
cost: 10,
abbreviation: "GP",
};
const currencyS = game.itempiles.API.getStringFromCurrencies(currencies);
const currencyData = game.itempiles.API.getPaymentData(currencyS, { target: tokenOrActor });
Expand Down
Loading

0 comments on commit f4f0f0f

Please sign in to comment.