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

View File

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

View File

@ -16,28 +16,19 @@
:max="$store.state.playerAgeMax"
:value="$store.state.playerAge"
/>
{{ ageText }}
{{ $store.getters.ageText }}
</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>
</template>
<script>
export default {
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() {
const { lightColor, darkColor } = this.$store.getters.activeTab

View File

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

View File

@ -143,7 +143,7 @@ export const state = () => ({
age: 100,
},
completionCriteria: {
cost: 150000,
maxAge: true,
},
available: true,
viewed: false,
@ -193,6 +193,18 @@ export const getters = {
currencySpent: (state) => {
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 = {
@ -217,8 +229,9 @@ export const mutations = {
setMissionViewed: (state, missionIndex) => {
Vue.set(state.missions[missionIndex], 'viewed', true)
},
completeMission: (state, missionIndex) => {
state.missions[missionIndex].complete = true
completeMission: (state, mission) => {
const index = state.missions.findIndex((m) => m.name === mission.name)
Vue.set(state.missions[index], 'complete', true)
},
levelUpApprentice: (state, process) => {
if (process.nextWorkerCost > state.currency) {