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

38 lines
1.2 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}`
// The village fills the screen behind (GameVillageFrame); buildings open their own
// screens. Here is only the build card of an empty plot picked in the village.
// An old `?b=` link opens that building's screen.
const linked = village.value.buildings.find((b) => b.id === Number(route.query.b))
if (linked) navigateTo(buildingRoute(village.value, linked), { replace: true })
const { plot } = useVillageSelection()
const plotOption = computed(() => village.value.buildable.find((o) => o.type === plot.value) ?? null)
async function build(type: BuildingType) {
await v.build(type)
if (!v.error.value) plot.value = null
}
</script>
<template>
<VillagePlotCard
v-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>