game-village-politics-frontend/app/pages/village/[id]/building/[bid].vue

51 lines
1.9 KiB
Vue

<script setup lang="ts">
const route = useRoute()
const v = useVillageContext()
const village = computed(() => v.village.value!)
const resources = computed(() => v.resources.value!)
const { t } = useI18n()
const building = computed(() => village.value.buildings.find((b) => b.id === Number(route.params.bid)) ?? null)
// Torn down or taken away: back to the village.
watch(building, (b) => {
if (!b) navigateTo(`/village/${route.params.id}`)
})
</script>
<!-- Inside one building: the close-up, what it does and what can be done with it. -->
<template>
<VillageScreenLayout v-if="building">
<template #side>
<VillageBuildingHeader
:building="building"
:title="buildingName(village, building, t)"
:resources="resources"
:can-afford="v.canAfford"
:busy="v.busy.value"
@upgrade="v.upgrade"
@demolish="v.demolish"
@priority="v.setPriority"
/>
</template>
<!-- The wounded lie in all hospitals together. -->
<VillageHospitalPanel v-if="building.type === 'hospital'" :hospital="village.hospital" :seconds-until="v.secondsUntil" />
<!-- The market trades: its tabs instead of the list, since a village has one market. -->
<VillageMarket v-if="building.type === 'market'" />
<!-- Every building of this type, and one more: the headquarters list for just this type. -->
<VillageBuildForm
v-else
:options="village.buildable.filter((o) => o.type === building!.type)"
:buildings="village.buildings.filter((b) => b.type === building!.type)"
:space="village.space"
:resources="resources"
:can-afford="v.canAfford"
:busy="v.busy.value"
:idle="village.population.idle"
@build="v.build"
@upgrade="v.upgrade"
@demolish="v.demolish"
@select="(id: number) => navigateTo(`/village/${route.params.id}/building/${id}`)"
/>
</VillageScreenLayout>
</template>