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

57 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!)
/** Show a building in the village overview, with its card open. */
const hq = computed(() => village.value.buildings.find((b) => b.type === 'headquarters') ?? null)
const { t } = useI18n()
/** A building's name opens its own screen. */
function showBuilding(id: number) {
const b = village.value.buildings.find((x) => x.id === id)
if (b) navigateTo(buildingRoute(village.value, b))
}
</script>
<!-- The headquarters screen: every building to construct, upgrade or tear down, and the queue. -->
<template>
<div class="space-y-3 p-2.5">
<VillageBuildingHeader
v-if="hq"
:building="hq"
:title="buildingName(village, hq, t)"
:resources="v.resources.value!"
:can-afford="v.canAfford"
:busy="v.busy.value"
@upgrade="v.upgrade"
@demolish="v.demolish"
@priority="v.setPriority"
/>
<VillageScreenHeader v-else type="headquarters" :level="null" :title="$t('buildings.headquarters')" :description="$t('village.about.build')" />
<div class="grid gap-3 @4xl:grid-cols-[minmax(0,1fr)_18rem]">
<VillageBuildForm
:options="village.buildable"
:buildings="village.buildings"
:space="village.space"
:resources="resources"
:can-afford="v.canAfford"
:busy="v.busy.value"
:hint="typeof route.query.hint === 'string' ? route.query.hint : null"
@build="v.build"
@upgrade="v.upgrade"
@demolish="v.demolish"
@select="showBuilding"
/>
<VillageBuildQueue
:queue="village.queue"
:builders="village.builders"
:seconds-until="v.secondsUntil"
:busy="v.busy.value"
@cancel="v.cancel"
/>
</div>
</div>
</template>