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

113 lines
4.1 KiB
Vue
Raw Normal View History

<script setup lang="ts">
const route = useRoute()
const v = useVillage(Number(route.params.id))
const { village, resources, error, busy } = v
/** Building selected in the diorama, by id; dropped when the building is gone. */
const selected = ref<number | null>(null)
const selectedBuilding = computed(() => village.value?.buildings.find((b) => b.id === selected.value) ?? null)
watch(selectedBuilding, (b) => {
if (!b) selected.value = null
})
const spaceShare = computed(() => (village.value ? village.value.space.used / village.value.space.max : 0))
v.refresh()
function showInVillage(id: number) {
selected.value = id
window.scrollTo({ top: 0, behavior: 'smooth' })
}
</script>
<template>
<div v-if="village && resources">
<VillageResourceBar class="sticky top-0 z-30" :village="village" :resources="resources" />
<section class="relative border-b border-parchment-300/70">
<div class="px-4 pt-4 sm:pointer-events-none sm:absolute sm:top-5 sm:left-6 sm:z-10 sm:p-0">
<div class="rounded-xl bg-white/85 px-4 py-3 shadow-sm ring-1 ring-parchment-300/70 backdrop-blur sm:pointer-events-auto">
<p class="text-xs font-medium tracking-wide text-ink-500 uppercase">{{ $t('village.title') }}</p>
<h1 class="font-display text-xl font-semibold sm:text-2xl">{{ village.name }}</h1>
<p class="mt-0.5 flex items-center gap-1 text-xs text-ink-500">
<IconUi name="pin" class="size-3.5" />
{{ village.x }}|{{ village.y }}
</p>
<div class="mt-2.5 sm:w-52">
<div class="mb-1 flex justify-between gap-3 text-xs">
<span class="text-ink-500">{{ $t('village.diorama.space') }}</span>
<span class="font-semibold tabular-nums">
{{ $t('village.diorama.space_value', { used: village.space.used, max: village.space.max }) }}
</span>
</div>
<UiBar :value="spaceShare" :tone="spaceShare >= 1 ? 'rose' : 'emerald'" />
</div>
</div>
</div>
<div class="h-[clamp(240px,74vw,440px)] sm:h-[clamp(320px,64vh,780px)]">
<VillageDiorama v-model:selected="selected" :village="village" />
</div>
<p
class="pointer-events-none absolute bottom-3 left-1/2 hidden -translate-x-1/2 rounded-full bg-white/75 px-3 py-1 text-xs text-ink-500 shadow-sm sm:block"
>
{{ $t('village.diorama.hint') }}
</p>
<VillageBuildingCard
v-if="selectedBuilding"
class="mx-4 mb-4 lg:absolute lg:top-5 lg:right-6 lg:z-10 lg:m-0 lg:w-80"
:building="selectedBuilding"
:resources="resources"
:can-afford="v.canAfford"
:busy="busy"
@upgrade="v.upgrade"
@demolish="v.demolish"
@priority="v.setPriority"
@close="selected = null"
/>
</section>
<div class="space-y-6 px-4 py-6 sm:px-6">
<p v-if="error" class="alert" role="alert">{{ error }}</p>
<div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]">
<VillageBuildForm
:options="village.buildable"
:space="village.space"
:resources="resources"
:can-afford="v.canAfford"
:busy="busy"
@build="v.build"
/>
<div class="space-y-6">
<VillageBuildQueue
:queue="village.queue"
:builders="village.builders"
:seconds-until="v.secondsUntil"
:busy="busy"
@cancel="v.cancel"
/>
<VillagePopulationPanel :population="village.population" />
</div>
</div>
<VillageBuildingTable
:buildings="village.buildings"
:resources="resources"
:can-afford="v.canAfford"
:busy="busy"
@select="showInVillage"
@upgrade="v.upgrade"
@demolish="v.demolish"
@priority="v.setPriority"
/>
</div>
</div>
<div v-else class="px-4 py-16 text-center">
<p v-if="error" class="alert inline-block" role="alert">{{ error }}</p>
<p v-else class="text-sm text-ink-500">{{ $t('common.loading') }}</p>
</div>
</template>