feat: Issue #50, run game clock in months

This commit is contained in:
John McCardle 2022-01-10 18:19:34 -05:00
parent a7ac60c0fa
commit e19621e124
2 changed files with 22 additions and 56 deletions

View File

@ -4,7 +4,8 @@
:class="colorClasses" :class="colorClasses"
> >
<div class="text-center pt-2 pb-1 border-r border-gray-600 select-none"> <div class="text-center pt-2 pb-1 border-r border-gray-600 select-none">
{{ $store.getters.gameMonth }} {{ $store.state.gameDate.year }} {{ $store.getters.gameMonth }}
{{ Math.floor($store.state.gameDate / 12) }}
</div> </div>
<div <div
@ -12,8 +13,8 @@
> >
<progress <progress
class="absolute top-0 left-0 right-0 h-1 w-full" class="absolute top-0 left-0 right-0 h-1 w-full"
:max="maxAgeValue" :max="$store.state.playerAgeMax"
:value="ageValue" :value="$store.state.playerAge"
/> />
{{ ageText }} {{ ageText }}
</div> </div>
@ -26,25 +27,17 @@
export default { export default {
computed: { computed: {
ageText() { 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` return `${year}y${month}m`
},
ageValue() {
const { year, month } = this.$store.state.playerAge
return year * 12 + month
}, },
maxAgeText() { 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` return `${year}y${month}m max`
}, },
maxAgeValue() {
const { year, month } = this.$store.state.playerAgeMax
return year * 12 + month
},
colorClasses() { colorClasses() {
const { lightColor, darkColor } = this.$store.getters.activeTab const { lightColor, darkColor } = this.$store.getters.activeTab

View File

@ -150,22 +150,10 @@ export const state = () => ({
complete: false, complete: false,
}, },
], ],
gameDate: { gameDate: 1991 * 12,
month: 12, playerAge: 34 * 12,
year: 1990, playerAgeMax: 80 * 12,
}, playerLivedTotal: 0,
playerAge: {
month: 0,
year: 34,
},
playerAgeMax: {
month: 0,
year: 80,
},
playerLivedTotal: {
month: 0,
year: 0,
},
wisdomGained: 0, // wisdom gained so far on this run, not applied until player sends the book. wisdomGained: 0, // wisdom gained so far on this run, not applied until player sends the book.
wisdomApplied: 0, // wisdom from previous runs wisdomApplied: 0, // wisdom from previous runs
totalLifetimes: 1, totalLifetimes: 1,
@ -197,7 +185,10 @@ export const getters = {
10: 'Oct.', 10: 'Oct.',
11: 'Nov.', 11: 'Nov.',
12: 'Dec.', 12: 'Dec.',
}[state.gameDate.month] }[(state.gameDate % 12) + 1]
},
gameYear: (state) => {
return Math.floor(state.gameDate / 12)
}, },
currencySpent: (state) => { currencySpent: (state) => {
return Decimal.subtract(state.currencyTotal, state.currency) return Decimal.subtract(state.currencyTotal, state.currency)
@ -243,29 +234,11 @@ export const mutations = {
) )
}, },
tickGameDate: (state) => { tickGameDate: (state) => {
let gameYear = state.gameDate.year state.gameDate += 1
let gameMonth = state.gameDate.month + 1 state.playerAge += 1
// Intentional: Months are 1 through 12, ages are 0 through 11. if (!(state.playerAge % 12)) state.wisdomGained++
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
}, },
travelGameDate: (state, { month, year }) => { travelGameDate: (state, month) => {
Vue.set(state.gameDate, 'month', month) state.gameDate = month
Vue.set(state.gameDate, 'year', year)
}, },
} }