From 6eef67d5daab3aeb9be4cc5c7f3c98879e10d7ff Mon Sep 17 00:00:00 2001 From: fadhlu Date: Fri, 19 Mar 2021 13:44:04 +0700 Subject: [PATCH 1/5] Add desired resin input --- src/locales/en.json | 8 ++++-- src/locales/id.json | 8 ++++-- src/routes/calculator/_resin.svelte | 41 ++++++++++++++++++++++------- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index d204a47b..e3f36dc5 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -206,11 +206,15 @@ "mora": "Mora Cost" }, "resin": { - "inputCurrentResin": "Input Current Resin...", + "currentResin": "Current Resin", + "desiredResin": "Desired Resin", + "or": "or", + "inputCurrentResin": "Input current resin...", + "inputDesireResin": "Input how many resin you want to wait...", "timeFormat": "en", "calculate": "Calculate", "currentTime": "Current Time", - "fullTime": "Resin Will Be Replenished At" + "fullTime": "Will be replenished at" } }, "items": { diff --git a/src/locales/id.json b/src/locales/id.json index 6e549827..999b3dad 100644 --- a/src/locales/id.json +++ b/src/locales/id.json @@ -206,11 +206,15 @@ "mora": "Jumlah Mora" }, "resin": { - "inputCurrentResin": "Masukkan Jumlah Resin Sekarang...", + "currentResin": "Resin Saat Ini", + "desiredResin": "Resin Yang Diinginkan", + "or": "atau", + "inputCurrentResin": "Masukkan jumlah resin sekarang...", + "inputDesireResin": "Masukkan jumlah resin yang diinginkan...", "timeFormat": "id", "calculate": "Hitung", "currentTime": "Waktu Sekarang", - "fullTime": "Resin Akan Penuh Pada" + "fullTime": "Akan terisi pada" } }, "items": { diff --git a/src/routes/calculator/_resin.svelte b/src/routes/calculator/_resin.svelte index fddf1bb3..bdac34f9 100644 --- a/src/routes/calculator/_resin.svelte +++ b/src/routes/calculator/_resin.svelte @@ -9,10 +9,14 @@ let changed = false; let currentResin = ''; + let desiredResin = ''; let maxResin = 160; let millisecondsToWait; let fullTime = null; let missingResin = 160; + let showResult = false; + let resinTypeOutput = ''; + let resinOutput = ''; let originalResin = { id: 'original_resin', @@ -21,7 +25,7 @@ value: 8, }; - // 8 menit per resin * 60 seconds * 1000 millisec + // 8 minute per resin * 60 seconds * 1000 millisec let minutePerResin = originalResin.value * 60 * 1000; let dateTimeOptions = { @@ -31,33 +35,50 @@ weekday: 'long', }; - $: canCalculate = currentResin !== '' && currentResin >= 0 && currentResin < 160; + $: isCurrentResin = currentResin >= 0 && currentResin < 160 && currentResin !== ''; + $: isDesiredResin = desiredResin <= 160 && desiredResin >= 1 && desiredResin === ''; + $: canCalculate = isCurrentResin || isDesiredResin; function calculate() { missingResin = maxResin - currentResin; - millisecondsToWait = missingResin * minutePerResin; + resinOutput = resinTypeOutput === 'maxResin' ? missingResin : desiredResin; + millisecondsToWait = resinTypeOutput === 'maxResin' ? missingResin * minutePerResin : desiredResin * minutePerResin; fullTime = new Date($time.getTime() + millisecondsToWait); + showResult = true; } - function onChange() { + function onChange(type) { changed = true; + showResult = false; + resinTypeOutput = type; }
-
+
+

+ {$t('calculator.resin.currentResin')} +

onChange('maxResin')} type="number" min={0} max={160} bind:value={currentResin} placeholder={$t('calculator.resin.inputCurrentResin')} /> -

+

{$t('calculator.resin.or')} {$t('calculator.resin.desiredResin')}

+ onChange('desiredResin')} + type="number" + min={1} + max={160} + bind:value={desiredResin} + placeholder={$t('calculator.resin.inputDesireResin')} + /> +

{$t('calculator.resin.currentTime')}: {new Intl.DateTimeFormat( $t('calculator.resin.timeFormat'), dateTimeOptions, @@ -68,12 +89,12 @@ - {#if fullTime} + {#if showResult}

{missingResin} + >{resinOutput} From 5041cc7a2c00fff6c450634ab6ea7e3abf12131b Mon Sep 17 00:00:00 2001 From: fadhlu Date: Fri, 19 Mar 2021 17:28:01 +0700 Subject: [PATCH 2/5] Remove unused var and fix button ui margin --- src/routes/calculator/_resin.svelte | 10 ++++------ src/routes/calculator/index.svelte | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/routes/calculator/_resin.svelte b/src/routes/calculator/_resin.svelte index bdac34f9..a0eb1e8f 100644 --- a/src/routes/calculator/_resin.svelte +++ b/src/routes/calculator/_resin.svelte @@ -7,14 +7,13 @@ import Input from '../../components/Input.svelte'; import { time } from '../../stores/time'; - let changed = false; + let changed = true; let currentResin = ''; let desiredResin = ''; let maxResin = 160; let millisecondsToWait; let fullTime = null; let missingResin = 160; - let showResult = false; let resinTypeOutput = ''; let resinOutput = ''; @@ -36,7 +35,7 @@ }; $: isCurrentResin = currentResin >= 0 && currentResin < 160 && currentResin !== ''; - $: isDesiredResin = desiredResin <= 160 && desiredResin >= 1 && desiredResin === ''; + $: isDesiredResin = desiredResin <= 160 && desiredResin >= 1 && desiredResin !== ''; $: canCalculate = isCurrentResin || isDesiredResin; function calculate() { @@ -44,12 +43,11 @@ resinOutput = resinTypeOutput === 'maxResin' ? missingResin : desiredResin; millisecondsToWait = resinTypeOutput === 'maxResin' ? missingResin * minutePerResin : desiredResin * minutePerResin; fullTime = new Date($time.getTime() + millisecondsToWait); - showResult = true; + changed = false; } function onChange(type) { changed = true; - showResult = false; resinTypeOutput = type; } @@ -89,7 +87,7 @@ - {#if showResult} + {#if !changed}
diff --git a/src/routes/calculator/index.svelte b/src/routes/calculator/index.svelte index 62645bc0..30c4a40e 100644 --- a/src/routes/calculator/index.svelte +++ b/src/routes/calculator/index.svelte @@ -92,7 +92,7 @@ {$t('calculator.goto')} {$t('calculator.titleWeapon')} -
diff --git a/src/routes/calculator/_resinTable.svelte b/src/routes/calculator/_resinTable.svelte new file mode 100644 index 00000000..563acc46 --- /dev/null +++ b/src/routes/calculator/_resinTable.svelte @@ -0,0 +1,61 @@ + + +
+
+
+ + + + + + {#each rows as _, i} + + + + + {/each} +
{$t('calculator.resinTable.quantity')}{$t('calculator.resinTable.time')}
{step[0]}{step[i + 1]} + {originalResin.label} + +
+
+
+
+ + diff --git a/src/routes/calculator/index.svelte b/src/routes/calculator/index.svelte index 30c4a40e..e2b5bc96 100644 --- a/src/routes/calculator/index.svelte +++ b/src/routes/calculator/index.svelte @@ -8,16 +8,13 @@ import CharacterCalculator from './_character.svelte'; import LevelUpTable from './_characterTable.svelte'; import ResinCalculator from './_resin.svelte'; + import ResinTable from './_resinTable.svelte'; import Button from '../../components/Button.svelte'; import Icon from '../../components/Icon.svelte'; import HowToModal from '../../components/CalculatorHowToModal.svelte'; const { open: openModal } = getContext('simple-modal'); - let weaponCalc; - let characterCalc; - let resinCalc; - function openHowTo() { openModal( HowToModal, @@ -120,6 +117,8 @@
-
- +
+ + +
diff --git a/yarn.lock b/yarn.lock index 15786df2..5f64e6da 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1314,7 +1314,7 @@ cssesc@^3.0.0: resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee" integrity sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg== -dayjs@^1.9.4: +dayjs@^1.10.4, dayjs@^1.8.25, dayjs@^1.9.4: version "1.10.4" resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.4.tgz#8e544a9b8683f61783f570980a8a80eaf54ab1e2" integrity sha512-RI/Hh4kqRc1UKLOAf/T5zdMMX5DQIlDxwUe3wSyMMnEbGunnpENCdbUgM+dW7kXidZqCttBrmw7BhN4TMddkCw== @@ -2460,6 +2460,13 @@ supports-color@^7.0.0, supports-color@^7.1.0: dependencies: has-flag "^4.0.0" +svelte-countdown@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/svelte-countdown/-/svelte-countdown-1.0.0.tgz#8551e6ee2279211f08b8e8e426c5380394fae598" + integrity sha512-RuaRjnWPrH7xuwPQwb9b+Ek4mtv3knMTytEqOY2mha152edwDfejjSL+/HvtCbIyuAXPOndaut46dIoeAlPh4A== + dependencies: + dayjs "^1.8.25" + svelte-i18n@^3.3.6: version "3.3.6" resolved "https://registry.yarnpkg.com/svelte-i18n/-/svelte-i18n-3.3.6.tgz#5d2a9f598b6e4999964afafad023c7f2f42c2e1f" @@ -2486,6 +2493,13 @@ svelte-simple-modal@^0.6.1: resolved "https://registry.yarnpkg.com/svelte-simple-modal/-/svelte-simple-modal-0.6.1.tgz#5e984f384dda16bc50f00846314dc140ad89864b" integrity sha512-GJGYj+jymzuar105fwkZ73dtcSFCordpbHqt53iE1N1GdqhvEmSs24idRzyIcO7TrTD/V/287X1icFXp88RQHQ== +svelte-time@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/svelte-time/-/svelte-time-0.3.0.tgz#64e90c4c2c9ac5966ef6e4732d32803bdc8c6fe8" + integrity sha512-9IpXTo6zo0oPe7cCuXZMQZrwfqh+nzR/gSyK7DRmjed6HB0zxUjUfwDmJ6roFSZ3bft6cFSx5vrlkdjz0psh1Q== + dependencies: + dayjs "^1.10.4" + svelte@^3.17.3: version "3.31.2" resolved "https://registry.yarnpkg.com/svelte/-/svelte-3.31.2.tgz#d2ddf6cacbb95e4cc3796207510b660a25586324" From 443f30dff508850cea8bfb4a1ed97678e4368661 Mon Sep 17 00:00:00 2001 From: fadhlu Date: Sun, 21 Mar 2021 18:23:16 +0800 Subject: [PATCH 4/5] Remove necessary package --- package.json | 2 - src/routes/calculator/_resin.svelte | 130 +++++++++++++++-------- src/routes/calculator/_resinTable.svelte | 22 +++- src/stores/time.js | 11 -- yarn.lock | 16 +-- 5 files changed, 102 insertions(+), 79 deletions(-) delete mode 100644 src/stores/time.js diff --git a/package.json b/package.json index 9bc703c4..12dd0ef6 100644 --- a/package.json +++ b/package.json @@ -39,11 +39,9 @@ "rollup-plugin-terser": "^7.0.0", "sapper": "^0.28.0", "svelte": "^3.17.3", - "svelte-countdown": "^1.0.0", "svelte-i18n": "^3.3.6", "svelte-preprocess": "^4.5.1", "svelte-simple-modal": "^0.6.1", - "svelte-time": "^0.3.0", "tailwindcss": "^1.9.5" } } diff --git a/src/routes/calculator/_resin.svelte b/src/routes/calculator/_resin.svelte index d519e142..28c648a2 100644 --- a/src/routes/calculator/_resin.svelte +++ b/src/routes/calculator/_resin.svelte @@ -1,12 +1,18 @@
@@ -78,10 +118,12 @@ placeholder={$t('calculator.resin.inputDesireResin')} />

- {$t('calculator.resin.currentTime')}: {new Intl.DateTimeFormat( - $t('calculator.resin.timeFormat'), - dateTimeOptions, - ).format($time)} + {$t('calculator.resin.currentTime')}: + {#if $t('calculator.resin.timeFormat') === 'en'} + {currentTime.locale('en').format('dddd HH:mm:ss')} + {:else} + {currentTime.locale('id').format('dddd HH:mm:ss')} + {/if}

@@ -90,38 +132,34 @@ > {#if !changed}
- - - {resinOutput} - - - - - - {originalResin.label} - - {originalResin.label} - - - - - - - {$t('calculator.resin.fullTime')}: - - - {new Intl.DateTimeFormat($t('calculator.resin.timeFormat'), dateTimeOptions).format(fullTime)} - ({remaining.hours != 0 ? `${remaining.hours} ${$t('calculator.resin.hours')}` : ''} - {remaining.minutes != 0 ? `${remaining.minutes} ${$t('calculator.resin.minutes')}` : ''} - {remaining.seconds != 0 ? `${remaining.seconds} ${$t('calculator.resin.seconds')}` : ''}) - - - + + + + +
+ + {$t('calculator.resin.fullTime')}: + {#if $t('calculator.resin.timeFormat') === 'en'} + {fullTime.locale('en').format('dddd HH:mm:ss')} ({fullTime.locale('en').fromNow()}) + {:else} + {fullTime.locale('id').format('dddd HH:mm:ss')} ({fullTime.locale('id').fromNow()}) + {/if} +
{/if}
+ + diff --git a/src/routes/calculator/_resinTable.svelte b/src/routes/calculator/_resinTable.svelte index 563acc46..f1433ba3 100644 --- a/src/routes/calculator/_resinTable.svelte +++ b/src/routes/calculator/_resinTable.svelte @@ -1,8 +1,13 @@