From e164f61f681060a5bcde665c9083606e86dfc5fc Mon Sep 17 00:00:00 2001 From: John McCardle Date: Fri, 7 Jan 2022 16:10:23 -0500 Subject: [PATCH] refactor: reduce to one currency, eliminate store module --- store/incremental.js | 63 -------------------------------------------- store/index.js | 45 +++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 63 deletions(-) delete mode 100644 store/incremental.js diff --git a/store/incremental.js b/store/incremental.js deleted file mode 100644 index e6878ef..0000000 --- a/store/incremental.js +++ /dev/null @@ -1,63 +0,0 @@ -import Decimal from 'break_infinity.js' -import { currencies } from './const.js' - -export const state = () => ({ - // use currencies from const as keys; initialize all values to zero - currency: Object.keys(currencies).reduce(function (obj, x) { - obj[x] = new Decimal(0) - return obj - }, {}), - - processes: [ - { - device: 'Star Chart', - worker: 'Shaman', - boughtWith: null, - produces: currencies.seasons, - buyWorkersWith: currencies.months, - deviceCount: new Decimal(0), - workerCount: new Decimal(0), - unlockThreshold: { [currencies.seasons]: 0, tech: null }, - }, - { - device: 'Stone Calendar', - worker: 'Stonecarver', - boughtWith: currencies.seasons, - produces: currencies.months, - buyWorkersWith: currencies.days, - deviceCount: new Decimal(0), - workerCount: new Decimal(0), - unlockThreshold: { [currencies.seasons]: 1, tech: null }, - }, - { - device: 'Astrolabes', - worker: 'Mathematician', - boughtWith: currencies.months, - buyWorkersWith: currencies.hours, - produces: currencies.days, - deviceCount: new Decimal(0), - workerCount: new Decimal(0), - unlockThreshold: { [currencies.days]: 10, tech: 0 }, - }, - ], - - upgrades: [ - { - name: 'Mathematics', - boughtWith: currencies.seasons, - price: 100, - purchased: false, - }, - ], -}) - -export const mutations = { - add(state, { key, value }) { - console.log(state.currency.keys()) - state.currency[key] = Decimal.add(state.currency[key], value) - }, - - set(state, { key, value }) { - state.currency[key] = value - }, -} diff --git a/store/index.js b/store/index.js index 039ecf3..09e9653 100644 --- a/store/index.js +++ b/store/index.js @@ -1,3 +1,6 @@ +import Decimal from 'break_infinity.js' +import { currencies } from './const.js' + export const state = () => ({ activeTabIndex: 0, tabs: [ @@ -44,6 +47,40 @@ export const state = () => ({ lightColor: 'teal-200', }, ], + currency: new Decimal(0), + currencyTotal: new Decimal(0), + processes: [ + { + device: 'Star Chart', + worker: 'Shaman', + deviceCount: new Decimal(0), + workerCount: 0, + unlockThreshold: { tech: null, currency: 0 }, + }, + { + device: 'Stone Calendar', + worker: 'Stonecarver', + deviceCount: new Decimal(0), + workerCount: 0, + unlockThreshold: { tech: null, currency: 10000 }, + }, + { + device: 'Astrolabes', + worker: 'Mathematician', + deviceCount: new Decimal(0), + workerCount: 0, + unlockThreshold: { tech: 0, currency: new Decimal(10e5) }, + }, + ], + + upgrades: [ + { + name: 'Mathematics', + boughtWith: currencies.seasons, + price: 100, + purchased: false, + }, + ], }) export const getters = { @@ -67,4 +104,12 @@ export const mutations = { setActiveTab: (state, index) => { state.activeTabIndex = index }, + addCurrency: (state, value) => { + state.currency = Decimal.add(state.currency, value) + state.currencyTotal = Decimal.add(state.currencyTotal, value) + }, + spendCurrency: (state, value) => { + value = Decimal.mul(value, -1) + state.currency = Decimal.add(state.currency, value) + } }