Skip to content

Commit

Permalink
fix currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
AngryBeaver committed Oct 9, 2022
1 parent fb073d4 commit 95ea113
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/Crafting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Crafting {
return new Crafting(actor, item);
}

async craft() {
async craft():Promise<Result> {
const result = await this.checkSkill();
RecipeCompendium.validateRecipeToItemList(this.recipe,this.actor.items,result);
this.checkCurrency(result);
Expand Down Expand Up @@ -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;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions templates/crafting-chat.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
</div>
<div class="action" style="flex:0 0 20px;">
{{#if result.currencies}}
<i class="fas fa-times"></i>
{{else}}
<i class="fas fa-check"></i>
{{else}}
<i class="fas fa-times"></i>
{{/if}}
</div>
</div>
Expand Down

0 comments on commit 95ea113

Please sign in to comment.