summaryrefslogtreecommitdiff
path: root/resources/js/ui.js
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/ui.js')
-rw-r--r--resources/js/ui.js49
1 files changed, 48 insertions, 1 deletions
diff --git a/resources/js/ui.js b/resources/js/ui.js
index bfd9204..92ca313 100644
--- a/resources/js/ui.js
+++ b/resources/js/ui.js
@@ -684,7 +684,10 @@ const UI = {
drawStatus () {
const currentArea = Memory.state.currentArea;
- UI.elements.status.querySelector('[data-template-slot="money"]').textContent = `${Memory.state.money} €`;
+ UI.elements.status.querySelector('[data-template-slot="money"]').textContent =
+ `${Memory.state.money.toFixed(DB.currencies.map[Memory.state.Settings.currency].decimals)}` +
+ ' ' +
+ `${DB.currencies.map[Memory.state.Settings.currency].symbol}`;
UI.elements.status.querySelector('[data-template-slot="monsterProgress"]').textContent = `${currentArea.monsterProgress} / ${currentArea.requiredEncounters}`;
UI.elements.status.querySelector('[data-template-slot="trainerProgress"]').textContent = `${currentArea.trainerProgress} / ${currentArea.trainers.length}`;
@@ -943,6 +946,50 @@ const UI = {
});
+ /* Currency */
+
+ const currencySelectNode = template.querySelector('[data-template-slot="currency"]');
+ const currencyCodeMap = Object.keys(DB.currencies.map).sort((a, b) => {
+ const nameA = DB.currencies.map[a].name;
+ const nameB = DB.currencies.map[b].name;
+
+ return nameA > nameB ? 1 : -1;
+ });
+
+ for (const currencyCode of currencyCodeMap) {
+ const currency = DB.currencies.map[currencyCode];
+ const currencyOptionNode = document.createElement('option');
+
+ currencyOptionNode.value = currencyCode,
+ currencyOptionNode.textContent = `${currency.symbol} - ${currency.name}`;
+
+ if (currencyCode === Memory.state.Settings.currency) {
+ currencyOptionNode.selected = true;
+ }
+
+ currencySelectNode.appendChild(currencyOptionNode);
+ }
+
+ currencySelectNode.addEventListener('change', async () => {
+ const selected = [...currencySelectNode.children].find((node) => node.selected === true);
+ const previousCurrencyCode = Memory.state.Settings.currency;
+ const newCurrencyCode = selected.value;
+
+ Memory.state.Settings.currency = newCurrencyCode;
+
+ // re-calculate money
+ const previousCurrency = DB.currencies.map[previousCurrencyCode];
+ const newCurrency = DB.currencies.map[newCurrencyCode];
+ const baseRateMoney = Memory.state.money / previousCurrency.rate;
+ const exchangedMoney = baseRateMoney * newCurrency.rate;
+ Memory.state.money = Number(exchangedMoney.toFixed(newCurrency.decimals));
+
+ UI.drawStatus();
+ });
+
+ template.querySelector('[data-template-slot="currency.lastUpdated"]').textContent = DB.currencies.last_updated;
+
+
popup.querySelector('.popup').appendChild(template);
UI.drawPopup(popup);
},