Skip to content

Commit

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

- Add some new API methods

### 1.2.2

Expand Down
16 changes: 6 additions & 10 deletions src/module.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "lazymoney",
"title": "Lazy Money (Dnd5e)",
"title": "Lazy Money",
"description": "Easily add or remove currency with automatic conversion and no overdraft.",
"version": "1.2.2",
"version": "1.2.3",
"authors": [
{
"name": "DeVelox",
Expand Down Expand Up @@ -62,14 +62,14 @@
"esmodules": ["module.js"],
"styles": ["styles/lazymoney.css"],
"compatibility": {
"minimum": 10,
"minimum": 11,
"verified": 11,
"maximum": 11
},
"manifestPlusVersion": "1.2.1",
"url": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e",
"manifest": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.2.2/module.json",
"download": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.2.2/module.zip",
"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",
"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 All @@ -78,11 +78,7 @@
"systems": [
{
"id": "dnd5e",
"type": "system",
"manifest": "https://raw.githubusercontent.com/foundryvtt/dnd5e/master/system.json",
"compatibility": {
"verified": "2.0.2"
}
"type": "system"
},
{
"id": "a5e",
Expand Down
62 changes: 61 additions & 1 deletion src/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const API = {
// }
// const [uuidOrItem] = inAttributes;
if (typeof inAttributes !== "object") {
throw error("addCurrency | inAttributes must be of type object");
throw error("manageCurrency | inAttributes must be of type object");
}

return await LazyMoneyHelpers.manageCurrency(
Expand All @@ -20,6 +20,22 @@ const API = {
);
},

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

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

async addCurrency(inAttributes) {
// if (!Array.isArray(inAttributes)) {
// throw error("retrieveAndApplyBonuses| inAttributes must be of type array");
Expand All @@ -36,6 +52,18 @@ const API = {
);
},

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

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

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

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

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

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

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

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

/**
* The currencies used in this system
*
Expand Down
58 changes: 56 additions & 2 deletions src/scripts/lazymoney-helpers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
import { debug, info, isEmptyObject, is_lazy_number, is_real_number, log, warn, getActorAsync } from "./lib/lib.js";
import {
debug,
info,
isEmptyObject,
is_lazy_number,
is_real_number,
log,
warn,
getActorAsync,
getActorSync,
} from "./lib/lib.js";
import CONSTANTS from "./constants/constants.js";
import { LazyMoneyCurrencyHelpers } from "./lazymoney-currencies-helpers.js";
import SETTINGS from "./constants/settings.js";
import API from "./api.js";

export class LazyMoneyHelpers {
async manageCurrency(actorOrActorUuid, currencyValue, currencyDenom) {
static async manageCurrency(actorOrActorUuid, currencyValue, currencyDenom) {
const actor = (await getActorAsync(actorOrActorUuid)) ?? undefined;
if (!actor) {
throw error(`No actor is been passed`, true);
}
return LazyMoneyHelpers._manageCurrencyCommon(actor, currencyValue, currencyDenom);
}

static manageCurrencySync(actorOrActorUuid, currencyValue, currencyDenom) {
const actor = getActorSync(actorOrActorUuid) ?? undefined;
if (!actor) {
throw error(`No actor is been passed`, true);
}
return LazyMoneyHelpers._manageCurrencyCommon(actor, currencyValue, currencyDenom);
}

static _manageCurrencyCommon(actor, currencyValue, currencyDenom) {
if (isEmptyObject(currencyValue)) {
throw error(`The currency value is empty or null`, true);
}
Expand Down Expand Up @@ -50,7 +71,18 @@ export class LazyMoneyHelpers {
if (!actor) {
throw error(`No actor is been passed`, true);
}
return LazyMoneyHelpers._addCurrencyCommon(actor, currencyValue, currencyDenom);
}

static addCurrencySync(actorOrActorUuid, currencyValue, currencyDenom) {
const actor = getActorSync(actorOrActorUuid) ?? undefined;
if (!actor) {
throw error(`No actor is been passed`, true);
}
return LazyMoneyHelpers._addCurrencyCommon(actor, currencyValue, currencyDenom);
}

static _addCurrencyCommon(actor, currencyValue, currencyDenom) {
if (isEmptyObject(currencyValue)) {
throw error(`The currency value is empty or null`, true);
}
Expand Down Expand Up @@ -85,7 +117,18 @@ export class LazyMoneyHelpers {
if (!actor) {
throw error(`No actor is been passed`, true);
}
return LazyMoneyHelpers._subtractCurrencyCommon(actor, currencyValue, currencyDenom);
}

static subtractCurrencySync(actorOrActorUuid, currencyValue, currencyDenom) {
const actor = getActorSync(actorOrActorUuid) ?? undefined;
if (!actor) {
throw error(`No actor is been passed`, true);
}
return LazyMoneyHelpers._subtractCurrencyCommon(actor, currencyValue, currencyDenom);
}

static _subtractCurrencyCommon(actor, currencyValue, currencyDenom) {
if (isEmptyObject(currencyValue)) {
throw error(`The currency value is empty or null`, true);
}
Expand Down Expand Up @@ -120,7 +163,18 @@ export class LazyMoneyHelpers {
if (!actor) {
throw error(`No actor is been passed`, true);
}
return LazyMoneyHelpers._hasEnoughCurrencyCommon(actor, currencyValue, currencyDenom);
}

static hasEnoughCurrencySync(actorOrActorUuid, currencyValue, currencyDenom) {
const actor = getActorSync(actorOrActorUuid) ?? undefined;
if (!actor) {
throw error(`No actor is been passed`, true);
}
return LazyMoneyHelpers._hasEnoughCurrencyCommon(actor, currencyValue, currencyDenom);
}

static _hasEnoughCurrencyCommon(actor, currencyValue, currencyDenom) {
if (isEmptyObject(currencyValue)) {
throw error(`The currency value is empty or null`, true);
}
Expand Down

0 comments on commit 894d0b7

Please sign in to comment.