Skip to content

Commit

Permalink
version 1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
p4535992 committed Sep 14, 2023
1 parent 4ba300c commit 70b1281
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
## Changelog

### 1.1.4-1.1.5

- Bug fixing and update the api

### 1.1.3

- fix on "is lazy number" function
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lazymoney",
"title": "Lazy Money",
"description": "Easily add or remove currency with automatic conversion and no overdraft.",
"version": "1.1.4",
"version": "1.1.5",
"main": "module.js",
"license": "SEE LICENSE IN LICENSE",
"private": true,
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 (Dnd5e)",
"description": "Easily add or remove currency with automatic conversion and no overdraft.",
"version": "1.1.4",
"version": "1.1.5",
"authors": [
{
"name": "DeVelox",
Expand Down Expand Up @@ -73,8 +73,8 @@
},
"manifestPlusVersion": "1.2.1",
"url": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e",
"manifest": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.1.4/module.json",
"download": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.1.4/module.zip",
"manifest": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.1.5/module.json",
"download": "https://github.com/p4535992/foundryvtt-lazymoney-dnd5e/releases/download/1.1.5/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
44 changes: 33 additions & 11 deletions src/scripts/lazymoney-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,34 @@ export class LazyMoneyHelpers {
throw error(`The currency value is empty or null`, true);
}

let currencyValueS = "";
if (is_real_number(currencyValue)) {
if (currencyValue < 0) {
currencyValueS = "-" + String(currencyValue * -1);
} else {
currencyValueS = "+" + String(currencyValue);
}
} else {
if (!is_lazy_number(currencyValue)) {
currencyValueS = String(currencyValue);
if (!currencyValueS.startsWith("+")) {
currencyValueS = "+" + currencyValueS;
}
}
}

let sign = LazyMoneyHelpers.signCase.default;
for (const val of Object.values(LazyMoneyHelpers.signCase)) {
if (value.includes(val)) {
if (currencyValueS.includes(val)) {
sign = val;
break;
}
}

const newAmount = LazyMoneyHelpers.calculateNewAmount(actor, currencyValue, currencyDenom, sign);
actor.update({ "system.currency": newAmount });
const newAmount = LazyMoneyHelpers.calculateNewAmount(actor, currencyValueS, currencyDenom, sign);
if (newAmount) {
actor.update({ "system.currency": newAmount });
}
}

static async addCurrency(actorOrActorUuid, currencyValue, currencyDenom) {
Expand Down Expand Up @@ -52,11 +70,13 @@ export class LazyMoneyHelpers {
}
const newAmount = LazyMoneyHelpers.calculateNewAmount(
actor,
currencyValue,
currencyValueS,
currencyDenom,
LazyMoneyHelpers.signCase.add
);
actor.update({ "system.currency": newAmount });
if (newAmount) {
actor.update({ "system.currency": newAmount });
}
}

static async subtractCurrency(actorOrActorUuid, currencyValue, currencyDenom) {
Expand Down Expand Up @@ -86,11 +106,13 @@ export class LazyMoneyHelpers {
}
const newAmount = LazyMoneyHelpers.calculateNewAmount(
actor,
currencyValue,
currencyValueS,
currencyDenom,
LazyMoneyHelpers.signCase.subtract
);
actor.update({ "system.currency": newAmount });
if (newAmount) {
actor.update({ "system.currency": newAmount });
}
}

/* =============================================== */
Expand Down Expand Up @@ -284,7 +306,7 @@ export class LazyMoneyHelpers {
actor,
`${game.user?.name} on ${actor.name} has replaced ${money[denom]} ${denom} with ${delta} ${denom}.`
);
return;
// return;
}
let newAmount = {};
if (!(denom === "ep" && game.settings.get(CONSTANTS.MODULE_ID, "ignoreElectrum"))) {
Expand Down Expand Up @@ -661,9 +683,9 @@ export class LazyMoneyHelpers {
.reverse()
.forEach((v) => {
if (v.conversion !== undefined) {
total *= v.conversion.each;
if (cpValue[v.conversion.into]) {
cpValue[v.conversion.into].value = total;
total *= v.conversion * 100; // Changed from cp to gp with 2.3.1
if (cpValue[v.abbreviation]) {
cpValue[v.abbreviation].value = total;
}
}
});
Expand Down
3 changes: 3 additions & 0 deletions src/scripts/lib/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export function isEmptyObject(obj) {
if (obj === null || obj === undefined) {
return true;
}
if (is_real_number(obj)) {
return false;
}
const result =
obj && // null and undefined check
Object.keys(obj).length === 0; // || Object.getPrototypeOf(obj) === Object.prototype);
Expand Down
2 changes: 1 addition & 1 deletion wiki/backup/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function _onChangeCurrency(ev) {
} else {
delta = Number(splitVal[0]);
chatLog(actor, `${game.user?.name} on ${actor.name} has replaced ${money[denom]} ${denom} with ${delta} ${denom}.`);
return;
// return;
}
let newAmount = {};
if (!(denom === "ep" && game.settings.get(CONSTANTS.MODULE_NAME, "ignoreElectrum"))) {
Expand Down

0 comments on commit 70b1281

Please sign in to comment.