refactor: reduce to one currency, eliminate store module
This commit is contained in:
parent
109db41d96
commit
e164f61f68
|
@ -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
|
|
||||||
},
|
|
||||||
}
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import Decimal from 'break_infinity.js'
|
||||||
|
import { currencies } from './const.js'
|
||||||
|
|
||||||
export const state = () => ({
|
export const state = () => ({
|
||||||
activeTabIndex: 0,
|
activeTabIndex: 0,
|
||||||
tabs: [
|
tabs: [
|
||||||
|
@ -44,6 +47,40 @@ export const state = () => ({
|
||||||
lightColor: 'teal-200',
|
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 = {
|
export const getters = {
|
||||||
|
@ -67,4 +104,12 @@ export const mutations = {
|
||||||
setActiveTab: (state, index) => {
|
setActiveTab: (state, index) => {
|
||||||
state.activeTabIndex = 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue