65 lines
2.1 KiB
Vue
65 lines
2.1 KiB
Vue
<script setup lang="ts">
|
|
import type { BuildingType } from '~/types/game'
|
|
|
|
const route = useRoute()
|
|
const v = useVillageContext()
|
|
const village = computed(() => v.village.value!)
|
|
const resources = computed(() => v.resources.value!)
|
|
const base = `/village/${route.params.id}`
|
|
const { t } = useI18n()
|
|
|
|
// The village itself fills the screen behind (GameVillageFrame); here is only the card of
|
|
// what is picked in it, shown in the window. `?b=` opens a building's card.
|
|
const { selected, plot } = useVillageSelection()
|
|
if (Number(route.query.b)) selected.value = Number(route.query.b)
|
|
|
|
const selectedBuilding = computed(() => village.value.buildings.find((b) => b.id === selected.value) ?? null)
|
|
const plotOption = computed(() => village.value.buildable.find((o) => o.type === plot.value) ?? null)
|
|
watch(selectedBuilding, (b) => {
|
|
if (!b) selected.value = null
|
|
})
|
|
|
|
/** Where the card of the selected building leads: its own screen, if it has one. */
|
|
const screenLink = computed(() => {
|
|
const b = selectedBuilding.value
|
|
if (!b) return null
|
|
if (b.type === 'headquarters') return { to: `${base}/build`, label: t('village.screens.build') }
|
|
if (b.type === 'rally_point') return { to: `${base}/rally`, label: t('village.screens.rally') }
|
|
if (village.value.military.some((m) => m.building_id === b.id)) {
|
|
return { to: { path: `${base}/recruit`, query: { at: b.id } }, label: t('village.buildings.recruit') }
|
|
}
|
|
return null
|
|
})
|
|
|
|
async function build(type: BuildingType) {
|
|
await v.build(type)
|
|
if (!v.error.value) plot.value = null
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<VillageBuildingCard
|
|
v-if="selectedBuilding"
|
|
:building="selectedBuilding"
|
|
:resources="resources"
|
|
:can-afford="v.canAfford"
|
|
:busy="v.busy.value"
|
|
:link="screenLink"
|
|
@upgrade="v.upgrade"
|
|
@demolish="v.demolish"
|
|
@priority="v.setPriority"
|
|
@close="selected = null"
|
|
/>
|
|
<VillagePlotCard
|
|
v-else-if="plotOption"
|
|
:option="plotOption"
|
|
:resources="resources"
|
|
:can-afford="v.canAfford"
|
|
:busy="v.busy.value"
|
|
:another="village.buildings.some((b) => b.type === plotOption!.type)"
|
|
:all-link="`${base}/build`"
|
|
@build="build"
|
|
@close="plot = null"
|
|
/>
|
|
</template>
|