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"
>
<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
@ -12,8 +13,8 @@
>
<progress
class="absolute top-0 left-0 right-0 h-1 w-full"
:max="maxAgeValue"
:value="ageValue"
:max="$store.state.playerAgeMax"
:value="$store.state.playerAge"
/>
{{ ageText }}
</div>
@ -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

View File

@ -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
},
}