111 lines
4.7 KiB
Vue
111 lines
4.7 KiB
Vue
<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 new name while the village is being renamed. */
|
|
const renaming = ref<string | null>(null)
|
|
async function rename() {
|
|
if (renaming.value !== null && (await v.rename(renaming.value))) renaming.value = null
|
|
}
|
|
|
|
const incomingAttacks = computed(() => village.value?.movements.filter((m) => m.direction === 'in' && m.type === 'attack') ?? [])
|
|
|
|
// 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: 'rally', path: '/rally', icon: 'rally_point' },
|
|
{ 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">
|
|
<form v-if="renaming !== null" class="flex items-center gap-1.5" @submit.prevent="rename">
|
|
<input
|
|
v-model="renaming"
|
|
type="text"
|
|
maxlength="32"
|
|
class="input w-44 px-2 py-0.5"
|
|
:aria-label="$t('village.rename')"
|
|
@keydown.esc="renaming = null"
|
|
/>
|
|
<button type="submit" class="btn btn-primary px-2 py-0.5" :disabled="v.busy.value || !renaming.trim()">{{ $t('village.rename_save') }}</button>
|
|
<button type="button" class="btn btn-ghost px-2 py-0.5" @click="renaming = null">{{ $t('village.rename_cancel') }}</button>
|
|
</form>
|
|
<template v-else>
|
|
<h1 class="truncate font-display text-lg font-semibold text-wood-900" style="font-variant: small-caps">{{ village.name }}</h1>
|
|
<button type="button" class="self-center text-ink-500 hover:text-blood-700" :title="$t('village.rename')" @click="renaming = village.name">
|
|
<IconUi name="edit" class="size-3.5" />
|
|
<span class="sr-only">{{ $t('village.rename') }}</span>
|
|
</button>
|
|
</template>
|
|
<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>
|
|
<NuxtLink
|
|
v-if="incomingAttacks.length"
|
|
:to="`/village/${id}/rally`"
|
|
class="badge badge-blood"
|
|
:title="$t('village.incoming', { count: incomingAttacks.length })"
|
|
>
|
|
<IconUi name="attack" class="size-3.5" />
|
|
{{ incomingAttacks.length }}
|
|
</NuxtLink>
|
|
<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>
|