81 lines
3.0 KiB
Vue
81 lines
3.0 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()
|
|
|
|
/** Building picked in the village (by id), or an empty plot (by type); `?b=` opens one. */
|
|
const selected = ref<number | null>(Number(route.query.b) || null)
|
|
const plot = ref<BuildingType | null>(null)
|
|
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>
|
|
|
|
<!-- The village overview, laid out like Die Stämme's: the village, and a narrow column beside it. -->
|
|
<template>
|
|
<div class="lg:grid lg:grid-cols-[minmax(0,1fr)_17rem] xl:grid-cols-[minmax(0,1fr)_19rem]">
|
|
<div class="relative">
|
|
<div class="h-[clamp(260px,82vw,460px)] sm:h-[clamp(380px,calc(100dvh-9rem),880px)]">
|
|
<VillageDiorama v-model:selected="selected" v-model:plot="plot" :village="village" :seconds-until="v.secondsUntil" />
|
|
</div>
|
|
|
|
<VillageBuildingCard
|
|
v-if="selectedBuilding"
|
|
class="mx-4 my-4 lg:absolute lg:top-4 lg:right-4 lg:z-10 lg:m-0 lg:w-80"
|
|
: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"
|
|
class="mx-4 my-4 lg:absolute lg:top-4 lg:right-4 lg:z-10 lg:m-0 lg:w-80"
|
|
: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"
|
|
/>
|
|
</div>
|
|
|
|
<VillageOverviewSidebar
|
|
class="border-t-2 border-wood-700 lg:border-t-0 lg:border-l-2"
|
|
:village="village"
|
|
:base="base"
|
|
:seconds-until="v.secondsUntil"
|
|
/>
|
|
</div>
|
|
</template>
|