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

45 lines
1.5 KiB
Vue
Raw Normal View History

<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>
<!-- Every building of this type, and one more: the headquarters list for just this type. -->
<VillageBuildForm
: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"
@build="v.build"
@upgrade="v.upgrade"
@demolish="v.demolish"
@select="(id: number) => navigateTo(`/village/${route.params.id}/building/${id}`)"
/>
</VillageScreenLayout>
</template>