Skip to content

Commit

Permalink
version 1.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Dec 29, 2023
1 parent 894d0b7 commit 53dd3ae
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## Changelog
### 1.2.4

- Update api and api doumentation

### 1.2.3

- Add some new API methods
Expand Down
6 changes: 3 additions & 3 deletions src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "lazymoney",
"title": "Lazy Money",
"description": "Easily add or remove currency with automatic conversion and no overdraft.",
"version": "1.2.3",
"version": "1.2.4",
"authors": [
{
"name": "DeVelox",
Expand Down Expand Up @@ -68,8 +68,8 @@
},
"manifestPlusVersion": "1.2.1",
"url": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e",
"manifest": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.2.3/module.json",
"download": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.2.3/module.zip",
"manifest": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.2.4/module.json",
"download": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.2.4/module.zip",
"readme": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/blob/master/README.md",
"changelog": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/blob/master/CHANGELOG.md",
"bugs": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/issues",
Expand Down
64 changes: 64 additions & 0 deletions src/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ const API = {
);
},

async manageCurrencyAsync(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
// }
// const [uuidOrItem] = inAttributes;
if (typeof inAttributes !== "object") {
throw error("manageCurrency | inAttributes must be of type object");
}

return await LazyMoneyHelpers.manageCurrency(
inAttributes.actor,
inAttributes.currencyValue,
inAttributes.currencyDenom
);
},

manageCurrencySync(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
Expand Down Expand Up @@ -52,6 +68,22 @@ const API = {
);
},

async addCurrencyAsync(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
// }
// const [uuidOrItem] = inAttributes;
if (typeof inAttributes !== "object") {
throw error("addCurrency | inAttributes must be of type object");
}

return await LazyMoneyHelpers.addCurrency(
inAttributes.actor,
inAttributes.currencyValue,
inAttributes.currencyDenom
);
},

addCurrencySync(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
Expand Down Expand Up @@ -80,6 +112,22 @@ const API = {
);
},

async subtractCurrencyAsync(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
// }
// const [uuidOrItem] = inAttributes;
if (typeof inAttributes !== "object") {
throw error("subtractCurrency | inAttributes must be of type object");
}

return await LazyMoneyHelpers.subtractCurrency(
inAttributes.actor,
inAttributes.currencyValue,
inAttributes.currencyDenom
);
},

subtractCurrencySync(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
Expand Down Expand Up @@ -112,6 +160,22 @@ const API = {
);
},

async hasEnoughCurrencyAsync(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
// }
// const [uuidOrItem] = inAttributes;
if (typeof inAttributes !== "object") {
throw error("hasEnoughCurrency | inAttributes must be of type object");
}

return await LazyMoneyHelpers.hasEnoughCurrency(
inAttributes.actor,
inAttributes.currencyValue,
inAttributes.currencyDenom
);
},

hasEnoughCurrencySync(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
Expand Down
132 changes: 126 additions & 6 deletions wiki/api.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
The api is reachable from the variable `game.modules.get('lazymoney').api` or from the socket libary `socketLib` on the variable `game.modules.get('lazymoney').socket` if present and active.


## manageCurrencyAsync({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;void&gt;</code>
## manageCurrency({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;void&gt;</code>

Manage currency on actor
Manage currency on actor (Async Version)

**Returns**: <code>Promise&lt;void&gt;</code> - Return nothing

Expand All @@ -16,17 +17,41 @@ Manage currency on actor
**Example**:

```
game.modules.get('lazymoney').api.manageCurrency({
await game.modules.get('lazymoney').api.manageCurrencyAsync({
actor: "Actor.7bm6EK8jnopnGRS4",
currencyValue: 30,
currencyDenom: "gp"
})
```

## manageCurrencySync({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>void</code>

Manage currency on actor (Sync Version)

**Returns**: <code>void</code> - Return nothing

| Param | Type | Description | Note |
| --- | --- | --- | --- |
| actor | <code>uuid of the actor or actor </code> | The uuid of the actor or the actor object himself | If you use the module 'Item Macro' the variable value is 'actor' |
| currencyValue | <code>string|number</code> | The currency value string or number format. eg. "=3", "+1", "-2", 2 , -2 | |
| currencyDenom | <code>string</code> | The currency denomination (cp, sp, ep, gp, pp) | |

**Example**:

```
game.modules.get('lazymoney').api.manageCurrencySync({
actor: "Actor.7bm6EK8jnopnGRS4",
currencyValue: 30,
currencyDenom: "gp"
})
```

## addCurrencyAsync({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;void&gt;</code>
## addCurrency({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;void&gt;</code>

Add currency on actor
Add currency on actor (Async version)

**Returns**: <code>Promise&lt;void&gt;</code> - Return nothing

Expand All @@ -39,18 +64,41 @@ Add currency on actor
**Example**:

```
game.modules.get('lazymoney').api.addCurrency({
await game.modules.get('lazymoney').api.addCurrencyAsync({
actor: "Actor.7bm6EK8jnopnGRS4",
currencyValue: 30,
currencyDenom: "gp"
})
```

## addCurrencySync({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>void</code>

Add currency on actor (Sync version)

**Returns**: <code>void</code> - Return nothing

| Param | Type | Description | Note |
| --- | --- | --- | --- |
| actor | <code>uuid of the actor or actor </code> | The uuid of the actor or the actor object himself | If you use the module 'Item Macro' the variable value is 'actor' |
| currencyValue | <code>string|number</code> | The currency value string or number format. eg. "+1", 2 | |
| currencyDenom | <code>string</code> | The currency denomination (cp, sp, ep, gp, pp) | |

**Example**:

```
game.modules.get('lazymoney').api.addCurrencySync({
actor: "Actor.7bm6EK8jnopnGRS4",
currencyValue: 30,
currencyDenom: "gp"
})
```

## subtractCurrencyAsync({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;void&gt;</code>
## subtractCurrency({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;void&gt;</code>

Subtract currency on actor
Subtract currency on actor (Async Version)

**Returns**: <code>Promise&lt;void&gt;</code> - Return nothing

Expand All @@ -63,14 +111,86 @@ Subtract currency on actor
**Example**:

```
game.modules.get('lazymoney').api.subtractCurrency({
await game.modules.get('lazymoney').api.subtractCurrencyAsync({
actor: "Actor.7bm6EK8jnopnGRS4",
currencyValue: 30,
currencyDenom: "gp"
})
```

## subtractCurrencySync({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>void</code>

Subtract currency on actor (Sync version)

**Returns**: <code>void</code> - Return nothing

| Param | Type | Description | Note |
| --- | --- | --- | --- |
| actor | <code>uuid of the actor or actor </code> | The uuid of the actor or the actor object himself | If you use the module 'Item Macro' the variable value is 'actor' |
| currencyValue | <code>string|number</code> | The currency value string or number format. eg. "-2", 2 | |
| currencyDenom | <code>string</code> | The currency denomination (cp, sp, ep, gp, pp) | |

**Example**:

```
game.modules.get('lazymoney').api.subtractCurrencySync({
actor: "Actor.7bm6EK8jnopnGRS4",
currencyValue: 30,
currencyDenom: "gp"
})
```

## hasEnoughCurrencyAsync({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;boolean&gt;</code>
## hasEnoughCurrency({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;boolean&gt;</code>

There is enough currency on actor (Async version)

**Returns**: <code>Promise&lt;boolean&gt;</code> - Return nothing

| Param | Type | Description | Note |
| --- | --- | --- | --- |
| actor | <code>uuid of the actor or actor </code> | The uuid of the actor or the actor object himself | If you use the module 'Item Macro' the variable value is 'actor' |
| currencyValue | <code>string|number</code> | The currency value string or number format. eg. "-2", 2 | |
| currencyDenom | <code>string</code> | The currency denomination (cp, sp, ep, gp, pp) | |

**Example**:

```
const isRichOrPoor = await game.modules.get('lazymoney').api.hasEnoughCurrencyAsync({
actor: "Actor.7bm6EK8jnopnGRS4",
currencyValue: 30,
currencyDenom: "gp"
})
```

## hasEnoughCurrencySync({actor: uuid|Actor, currencyValue:string|number, currencyDenom:string}):void ⇒ <code>boolean</code>

There is enough currency on actor (Sync version)

**Returns**: <code>boolean</code> - Return nothing

| Param | Type | Description | Note |
| --- | --- | --- | --- |
| actor | <code>uuid of the actor or actor </code> | The uuid of the actor or the actor object himself | If you use the module 'Item Macro' the variable value is 'actor' |
| currencyValue | <code>string|number</code> | The currency value string or number format. eg. "-2", 2 | |
| currencyDenom | <code>string</code> | The currency denomination (cp, sp, ep, gp, pp) | |

**Example**:

```
const isRichOrPoor = game.modules.get('lazymoney').api.hasEnoughCurrencySync({
actor: "Actor.7bm6EK8jnopnGRS4",
currencyValue: 30,
currencyDenom: "gp"
})
```

# OLD API (TO REMOVE ONLY FOR DND5E)

## convertToCopper({currencyValue:string|number, currencyDenom:string}):void ⇒ <code>Promise&lt;number&gt;</code>

Convert currency to Copper
Expand Down

0 comments on commit 53dd3ae

Please sign in to comment.