From 95ea113c801df0cce320b011d4873cf3922ffffa Mon Sep 17 00:00:00 2001 From: AngryBeaver Date: Sun, 9 Oct 2022 14:25:18 +0200 Subject: [PATCH] fix currencies --- module.json | 2 +- src/Crafting.ts | 4 ++-- src/Exchange.ts | 9 +++++++++ templates/crafting-chat.hbs | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/module.json b/module.json index bb3ae63..22cc397 100644 --- a/module.json +++ b/module.json @@ -2,7 +2,7 @@ "title": "Beaver's Crafting System", "description": "A Crafting Module for DnD", "id": "beavers-crafting", - "version": "0.0.3", + "version": "0.0.5", "authors": [ { "name": "angryBeaver", diff --git a/src/Crafting.ts b/src/Crafting.ts index 6d47eb1..e743fa4 100644 --- a/src/Crafting.ts +++ b/src/Crafting.ts @@ -24,7 +24,7 @@ export class Crafting { return new Crafting(actor, item); } - async craft() { + async craft():Promise { const result = await this.checkSkill(); RecipeCompendium.validateRecipeToItemList(this.recipe,this.actor.items,result); this.checkCurrency(result); @@ -127,7 +127,7 @@ export class Crafting { } await this.actor.createEmbeddedDocuments("Item", createItems) await this.actor.update({ - "system.currency": result.currencies + "system.currency": result.changes.currencies }); return result; } diff --git a/src/Exchange.ts b/src/Exchange.ts index 8d8684f..2aafd41 100644 --- a/src/Exchange.ts +++ b/src/Exchange.ts @@ -7,6 +7,7 @@ export const CONVERSION = "conversion"; export class Exchange { static pay(priceCurrency, actorCurrencies) { + this.fixCurrencies(actorCurrencies); let lowestActorCurrency = this.toLowestCurrency(actorCurrencies); const lowestPriceCurrency = this.toLowestCurrency(this.toCurrencies(priceCurrency)); const result = new DefaultCurrency(); @@ -19,6 +20,14 @@ export class Exchange { return this.toHighestCurrencies(exchangeCurrencies); } + static fixCurrencies(currencies){ + getCurrencies().forEach(c => { + if (Number.isNaN(currencies[ABBREVIATION])) { + currencies[ABBREVIATION] = 0; + } + }) + } + static toCurrencies(currency:Currency) { let currencies = {}; getCurrencies().forEach(c => { diff --git a/templates/crafting-chat.hbs b/templates/crafting-chat.hbs index 3a5ad25..1e3fa76 100644 --- a/templates/crafting-chat.hbs +++ b/templates/crafting-chat.hbs @@ -29,9 +29,9 @@
{{#if result.currencies}} - - {{else}} + {{else}} + {{/if}}