From e19621e1247233e4b214ca54c49661771493f89e Mon Sep 17 00:00:00 2001 From: John McCardle Date: Mon, 10 Jan 2022 18:19:34 -0500 Subject: [PATCH] feat: Issue #50, run game clock in months --- components/TimeHeader.vue | 25 +++++++----------- store/index.js | 53 ++++++++++----------------------------- 2 files changed, 22 insertions(+), 56 deletions(-) diff --git a/components/TimeHeader.vue b/components/TimeHeader.vue index 66b31a5..1390e75 100644 --- a/components/TimeHeader.vue +++ b/components/TimeHeader.vue @@ -4,7 +4,8 @@ :class="colorClasses" >
- {{ $store.getters.gameMonth }} {{ $store.state.gameDate.year }} + {{ $store.getters.gameMonth }} + {{ Math.floor($store.state.gameDate / 12) }}
{{ ageText }}
@@ -26,25 +27,17 @@ export default { computed: { ageText() { - const { year, month } = this.$store.state.playerAge + const year = Math.floor(this.$store.state.playerAge / 12) + const month = this.$store.state.playerAge % 12 - return `${year}y${month}m max` - }, - ageValue() { - const { year, month } = this.$store.state.playerAge - - return year * 12 + month + return `${year}y${month}m` }, maxAgeText() { - const { year, month } = this.$store.state.playerAgeMax + const year = Math.floor(this.$store.state.playerAgeMax / 12) + const month = this.$store.state.playerAgeMax % 12 return `${year}y${month}m max` }, - maxAgeValue() { - const { year, month } = this.$store.state.playerAgeMax - - return year * 12 + month - }, colorClasses() { const { lightColor, darkColor } = this.$store.getters.activeTab diff --git a/store/index.js b/store/index.js index 3c85faa..2db9c33 100644 --- a/store/index.js +++ b/store/index.js @@ -150,22 +150,10 @@ export const state = () => ({ complete: false, }, ], - gameDate: { - month: 12, - year: 1990, - }, - playerAge: { - month: 0, - year: 34, - }, - playerAgeMax: { - month: 0, - year: 80, - }, - playerLivedTotal: { - month: 0, - year: 0, - }, + gameDate: 1991 * 12, + playerAge: 34 * 12, + playerAgeMax: 80 * 12, + playerLivedTotal: 0, wisdomGained: 0, // wisdom gained so far on this run, not applied until player sends the book. wisdomApplied: 0, // wisdom from previous runs totalLifetimes: 1, @@ -197,7 +185,10 @@ export const getters = { 10: 'Oct.', 11: 'Nov.', 12: 'Dec.', - }[state.gameDate.month] + }[(state.gameDate % 12) + 1] + }, + gameYear: (state) => { + return Math.floor(state.gameDate / 12) }, currencySpent: (state) => { return Decimal.subtract(state.currencyTotal, state.currency) @@ -243,29 +234,11 @@ export const mutations = { ) }, tickGameDate: (state) => { - let gameYear = state.gameDate.year - let gameMonth = state.gameDate.month + 1 - // Intentional: Months are 1 through 12, ages are 0 through 11. - if (gameMonth > 12) { - gameMonth = 1 - gameYear = gameYear + 1 - } - let ageYear = state.playerAge.year - let ageMonth = state.playerAge.month + 1 - let wisdomGained = 0 - if (ageMonth >= 12) { - ageMonth = 0 - ageYear = ageYear + 1 - wisdomGained += 1 - } - Vue.set(state.gameDate, 'year', gameYear) - Vue.set(state.gameDate, 'month', gameMonth) - Vue.set(state.playerAge, 'year', ageYear) - Vue.set(state.playerAge, 'month', ageMonth) - state.wisdomGained = state.wisdomGained + wisdomGained + state.gameDate += 1 + state.playerAge += 1 + if (!(state.playerAge % 12)) state.wisdomGained++ }, - travelGameDate: (state, { month, year }) => { - Vue.set(state.gameDate, 'month', month) - Vue.set(state.gameDate, 'year', year) + travelGameDate: (state, month) => { + state.gameDate = month }, }