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

75 lines
2.9 KiB
Vue
Raw Normal View History

<script setup lang="ts">
const route = useRoute()
const id = Number(route.params.id)
const v = useVillage(id)
const { village, resources, error } = v
provideVillage(v)
const { enter } = useCurrentWorld()
watch(village, (state) => {
if (state) enter(state.world_id, state.id)
})
v.refresh()
// The screens of a village, like the building links along the top in Die Stämme.
const screens = [
{ name: 'overview', path: '', icon: 'headquarters' },
{ name: 'build', path: '/build', icon: 'storage' },
{ name: 'recruit', path: '/recruit', icon: 'barracks' },
{ name: 'workforce', path: '/workforce', icon: 'farm' },
] as const
</script>
<template>
<div v-if="village && resources">
<header class="sticky top-0 z-30 border-b-2 border-wood-700 bg-parchment-200">
<div class="flex flex-wrap items-center gap-x-5 gap-y-2 px-4 py-2 sm:px-6">
<div class="flex min-w-0 items-baseline gap-2">
<h1 class="truncate font-display text-lg font-semibold text-wood-900" style="font-variant: small-caps">{{ village.name }}</h1>
<NuxtLink
:to="{ path: `/map/${village.world_id}`, query: { x: village.x, y: village.y } }"
class="text-sm whitespace-nowrap text-ink-700 tabular-nums hover:text-blood-700 hover:underline"
:title="$t('village.on_map')"
>
({{ village.x }}|{{ village.y }}) {{ village.continent }}
</NuxtLink>
<span class="hidden text-xs whitespace-nowrap text-ink-500 sm:inline">{{ $t('village.points', { points: village.points }) }}</span>
</div>
<nav class="flex items-center gap-0.5" :aria-label="$t('village.screens.label')">
<NuxtLink
v-for="s in screens"
:key="s.name"
:to="`/village/${id}${s.path}`"
class="screen-link"
:class="{ 'screen-link-active': route.path === `/village/${id}${s.path}` }"
>
<IconBuilding :type="s.icon" class="size-4" />
<span :class="s.name === 'overview' ? 'hidden sm:inline' : ''">{{ $t(`village.screens.${s.name}`) }}</span>
</NuxtLink>
</nav>
<VillageResourceBar class="lg:ml-auto" :village="village" :resources="resources" />
</div>
<VillageFoodWarning :starvation="village.starvation" :levy="village.levy" :seconds-until="v.secondsUntil" />
</header>
<p v-if="error" class="alert mx-4 mt-3 sm:mx-6" role="alert">{{ error }}</p>
<NuxtPage />
</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>
<style scoped>
@reference "~/assets/css/main.css";
.screen-link {
@apply inline-flex items-center gap-1.5 rounded-sm border border-transparent px-2 py-1 text-sm font-semibold text-wood-900 hover:border-wood-600;
}
.screen-link-active {
@apply border-wood-700 bg-parchment-50 text-blood-700;
}
</style>