feat: Display year/month durations via getters

This commit is contained in:
John McCardle 2022-01-10 21:09:32 -05:00
parent 915b91c624
commit 5332f6035a
5 changed files with 40 additions and 25 deletions

View File

@ -4,6 +4,7 @@
:description="mission.description" :description="mission.description"
:max="max" :max="max"
:value="value" :value="value"
:unit="unit"
@click="complete" @click="complete"
/> />
</template> </template>
@ -24,6 +25,9 @@ export default {
? this.mission.completionCriteria.cost ? this.mission.completionCriteria.cost
: this.$store.state.playerAgeMax : this.$store.state.playerAgeMax
}, },
unit() {
return 'cost' in this.mission.completionCriteria ? 'spareTime' : 'age'
},
}, },
methods: { methods: {
complete() { complete() {

View File

@ -13,8 +13,8 @@
/> />
<span class="absolute top-3 right-3 font-semibold text-sm"> <span class="absolute top-3 right-3 font-semibold text-sm">
{{ cappedValue }} / {{ max }} {{ cappedValueText }} / {{ maxText }}
<span class="fas fa-hourglass-half" /> <span v-if="unit === 'spareTime'" class="fas fa-hourglass-half" />
</span> </span>
<span <span
@ -41,7 +41,7 @@ export default {
description: { type: String, default: null }, description: { type: String, default: null },
max: { type: Number, required: true }, max: { type: Number, required: true },
value: { type: [Number, Decimal], required: true }, value: { type: [Number, Decimal], required: true },
unit: { type: String, default: null }, unit: { type: String, default: 'spareTime' },
current: { type: String, default: null }, current: { type: String, default: null },
next: { type: String, default: null }, next: { type: String, default: null },
}, },
@ -49,6 +49,16 @@ export default {
cappedValue() { cappedValue() {
return this.value > this.max ? this.max : this.value return this.value > this.max ? this.max : this.value
}, },
cappedValueText() {
return this.unit === 'spareTime'
? this.cappedValue
: this.$store.getters.ageText
},
maxText() {
return this.unit === 'spareTime'
? this.max
: this.$store.getters.ageMaxText
},
clickable() { clickable() {
return this.value >= this.max return this.value >= this.max
}, },

View File

@ -16,28 +16,19 @@
:max="$store.state.playerAgeMax" :max="$store.state.playerAgeMax"
:value="$store.state.playerAge" :value="$store.state.playerAge"
/> />
{{ ageText }} {{ $store.getters.ageText }}
</div> </div>
<div class="text-center pt-2 pb-1 select-none" v-text="maxAgeText" /> <div
class="text-center pt-2 pb-1 select-none"
v-text="$store.getters.ageMaxText"
/>
</header> </header>
</template> </template>
<script> <script>
export default { export default {
computed: { computed: {
ageText() {
const year = Math.floor(this.$store.state.playerAge / 12)
const month = this.$store.state.playerAge % 12
return `${year}y${month}m`
},
maxAgeText() {
const year = Math.floor(this.$store.state.playerAgeMax / 12)
const month = this.$store.state.playerAgeMax % 12
return `${year}y${month}m max`
},
colorClasses() { colorClasses() {
const { lightColor, darkColor } = this.$store.getters.activeTab const { lightColor, darkColor } = this.$store.getters.activeTab

View File

@ -1,12 +1,9 @@
<template> <template>
<responsive-grid> <responsive-grid>
<progress-button <mission-button
v-for="(mission, index) in $store.state.missions" v-for="(mission, index) in $store.state.missions"
:key="index" :key="index"
:label="mission.name" :mission="mission"
:description="mission.description"
:max="mission.completionCriteria.cost"
:value="$store.state.currency"
/> />
</responsive-grid> </responsive-grid>
</template> </template>

View File

@ -143,7 +143,7 @@ export const state = () => ({
age: 100, age: 100,
}, },
completionCriteria: { completionCriteria: {
cost: 150000, maxAge: true,
}, },
available: true, available: true,
viewed: false, viewed: false,
@ -193,6 +193,18 @@ export const getters = {
currencySpent: (state) => { currencySpent: (state) => {
return Decimal.subtract(state.currencyTotal, state.currency) return Decimal.subtract(state.currencyTotal, state.currency)
}, },
ageText: (state) => {
const year = Math.floor(state.playerAge / 12)
const month = state.playerAge % 12
return `${year}y${month}m`
},
ageMaxText: (state) => {
const year = Math.floor(state.playerAgeMax / 12)
const month = state.playerAgeMax % 12
return `${year}y${month}m`
},
} }
export const mutations = { export const mutations = {
@ -217,8 +229,9 @@ export const mutations = {
setMissionViewed: (state, missionIndex) => { setMissionViewed: (state, missionIndex) => {
Vue.set(state.missions[missionIndex], 'viewed', true) Vue.set(state.missions[missionIndex], 'viewed', true)
}, },
completeMission: (state, missionIndex) => { completeMission: (state, mission) => {
state.missions[missionIndex].complete = true const index = state.missions.findIndex((m) => m.name === mission.name)
Vue.set(state.missions[index], 'complete', true)
}, },
levelUpApprentice: (state, process) => { levelUpApprentice: (state, process) => {
if (process.nextWorkerCost > state.currency) { if (process.nextWorkerCost > state.currency) {