From 929d0a6668b3b70e402307353bd033e9bfb33641 Mon Sep 17 00:00:00 2001 From: Made Baruna Date: Wed, 24 Aug 2022 00:12:41 +0700 Subject: [PATCH] Sort calculation result --- src/routes/calculator/_character.svelte | 8 ++++++-- src/routes/calculator/_weapon.svelte | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/routes/calculator/_character.svelte b/src/routes/calculator/_character.svelte index b95a24da..f2c24b7c 100644 --- a/src/routes/calculator/_character.svelte +++ b/src/routes/calculator/_character.svelte @@ -70,6 +70,8 @@ let moraNeeded = 0; let changed = false; + let calcResult = []; + let currentTalentLevel = { first: 1, second: 1, @@ -223,7 +225,7 @@ } if (items[item.item.id] === undefined) { - items[item.item.id] = { ...item.item, amount: 0 }; + items[item.item.id] = { ...item.item, amount: 0, order: i }; } items[item.item.id].amount += item.amount; } @@ -424,6 +426,8 @@ } } + calcResult = Object.entries(ascensionResouce).sort((a, b) => a[1].order - b[1].order); + changed = false; } @@ -650,7 +654,7 @@ {/if} {/each} - {#each Object.entries(ascensionResouce) as [id, item]} + {#each calcResult as [id, item]} {#if item.amount > 0} diff --git a/src/routes/calculator/_weapon.svelte b/src/routes/calculator/_weapon.svelte index 708c9d16..578a7824 100644 --- a/src/routes/calculator/_weapon.svelte +++ b/src/routes/calculator/_weapon.svelte @@ -96,6 +96,8 @@ let moraNeeded = 0; let changed = false; + let calcResult = []; + let numberFormat = Intl.NumberFormat(); $: usedResource = resources.filter((e) => e.selected).sort((a, b) => b.value - a.value); @@ -198,7 +200,7 @@ } if (items[item.item.id] === undefined) { - items[item.item.id] = { ...item.item, amount: 0 }; + items[item.item.id] = { ...item.item, amount: 0, order: i }; } items[item.item.id].amount += item.amount; } @@ -287,6 +289,8 @@ calculateAscension(); } + calcResult = Object.entries(ascensionResouce).sort((a, b) => a[1].order - b[1].order); + changed = false; } @@ -459,7 +463,7 @@ {/if} {/each} - {#each Object.entries(ascensionResouce) as [id, item]} + {#each calcResult as [id, item]} {#if item.amount > 0}