126 lines
6.2 KiB
Vue
126 lines
6.2 KiB
Vue
|
|
<script setup lang="ts">
|
||
|
|
import type { Resources, VillageState } from '~/types/game'
|
||
|
|
|
||
|
|
const props = defineProps<{ village: VillageState; resources: Resources }>()
|
||
|
|
const v = useVillageContext()
|
||
|
|
const route = useRoute()
|
||
|
|
|
||
|
|
const base = computed(() => `/village/${props.village.id}`)
|
||
|
|
const incoming = computed(() => props.village.movements.filter((m) => m.direction === 'in'))
|
||
|
|
const attacks = computed(() => incoming.value.filter((m) => m.type === 'attack'))
|
||
|
|
const nextAttack = computed(() => attacks.value[0] ?? null)
|
||
|
|
const support = computed(() => incoming.value.length - attacks.value.length)
|
||
|
|
const isActive = (path: string) => route.path === `${base.value}${path}`
|
||
|
|
|
||
|
|
/** 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
|
||
|
|
}
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<!--
|
||
|
|
The village bar under the menu, on every screen of the world: which village, its
|
||
|
|
stock with storage meters, incoming troops, and its screens as tabs (on phones the
|
||
|
|
tabs move to the bottom bar).
|
||
|
|
-->
|
||
|
|
<template>
|
||
|
|
<div class="sticky top-0 z-30 border-b-2 border-wood-700 bg-parchment-200">
|
||
|
|
<div class="mx-auto flex max-w-[96rem] flex-wrap items-center gap-x-6 gap-y-2 px-3 pt-2 pb-2 sm:px-6 md:pb-0">
|
||
|
|
<!-- Which village. -->
|
||
|
|
<div class="flex min-w-0 flex-1 items-center gap-2 md:flex-none md:pb-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>
|
||
|
|
<div class="min-w-0">
|
||
|
|
<div class="flex min-w-0 items-center gap-1.5">
|
||
|
|
<NuxtLink :to="base" class="truncate font-display text-lg leading-tight font-semibold text-wood-900 hover:text-blood-700" style="font-variant: small-caps">
|
||
|
|
{{ village.name }}
|
||
|
|
</NuxtLink>
|
||
|
|
<button type="button" class="shrink-0 text-ink-400 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>
|
||
|
|
</div>
|
||
|
|
<div class="flex items-center gap-2 text-xs text-ink-500">
|
||
|
|
<NuxtLink
|
||
|
|
:to="{ path: `/map/${village.world_id}`, query: { x: village.x, y: village.y } }"
|
||
|
|
class="tabular-nums hover:text-blood-700 hover:underline"
|
||
|
|
:title="$t('village.on_map')"
|
||
|
|
>
|
||
|
|
{{ village.x }}|{{ village.y }} {{ village.continent }}
|
||
|
|
</NuxtLink>
|
||
|
|
<span>·</span>
|
||
|
|
<span class="tabular-nums">{{ $t('village.points', { points: village.points }) }}</span>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- Incoming troops, red for attacks, with the next arrival. -->
|
||
|
|
<NuxtLink
|
||
|
|
v-if="incoming.length"
|
||
|
|
:to="`${base}/rally`"
|
||
|
|
class="order-2 flex items-center gap-2 rounded-sm border-2 px-2 py-1 text-sm font-semibold md:order-3 md:mb-2"
|
||
|
|
:class="attacks.length ? 'border-blood-800 bg-blood-700 text-parchment-50' : 'border-moss-700 bg-moss-600 text-parchment-50'"
|
||
|
|
:title="$t('village.incoming', { count: attacks.length })"
|
||
|
|
>
|
||
|
|
<span v-if="attacks.length" class="inline-flex items-center gap-1"><IconUi name="attack" class="size-4" />{{ attacks.length }}</span>
|
||
|
|
<span v-if="support" class="inline-flex items-center gap-1"><IconUi name="support" class="size-4" />{{ support }}</span>
|
||
|
|
<span v-if="nextAttack" class="hidden tabular-nums sm:inline">{{ formatDuration(v.secondsUntil(nextAttack.arrives_at)) }}</span>
|
||
|
|
</NuxtLink>
|
||
|
|
|
||
|
|
<!-- The stock: four resources with their storage meters, the storage cap and the villagers. -->
|
||
|
|
<div class="order-3 grid w-full grid-cols-[repeat(4,minmax(0,1fr))_auto] items-center gap-x-3 md:order-2 md:mb-2 md:ml-auto md:flex md:w-auto md:gap-x-4">
|
||
|
|
<GameResource
|
||
|
|
v-for="r in (['wood', 'clay', 'iron', 'food'] as const)"
|
||
|
|
:key="r"
|
||
|
|
:resource="r"
|
||
|
|
:amount="resources[r]"
|
||
|
|
:cap="village.storage_cap"
|
||
|
|
:rate="village.rates[r]"
|
||
|
|
/>
|
||
|
|
<span class="hidden items-center gap-1.5 text-sm text-ink-700 tabular-nums lg:inline-flex" :title="$t('village.resources.cap')">
|
||
|
|
<IconBuilding type="storage" class="size-4" />{{ village.storage_cap }}
|
||
|
|
</span>
|
||
|
|
<NuxtLink
|
||
|
|
:to="`${base}/workforce`"
|
||
|
|
class="inline-flex items-center gap-1.5 text-sm text-ink-700 tabular-nums hover:text-blood-700"
|
||
|
|
:title="`${$t('village.population.villagers')}: ${village.population.villagers} · ${$t('village.population.upkeep')}: ${village.population.upkeep}/${village.population.food_budget}`"
|
||
|
|
>
|
||
|
|
<IconUi name="users" class="size-4" />{{ village.population.villagers }}
|
||
|
|
</NuxtLink>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
<!-- The village's screens as tabs that sit on the page below. -->
|
||
|
|
<nav class="order-4 -mb-0.5 hidden w-full items-end gap-1 md:flex" :aria-label="$t('village.screens.label')">
|
||
|
|
<NuxtLink
|
||
|
|
v-for="s in VILLAGE_SCREENS"
|
||
|
|
:key="s.name"
|
||
|
|
:to="`${base}${s.path}`"
|
||
|
|
class="tab"
|
||
|
|
:class="{ 'tab-active': isActive(s.path) }"
|
||
|
|
:aria-current="isActive(s.path) ? 'page' : undefined"
|
||
|
|
>
|
||
|
|
<IconBuilding :type="s.icon" class="size-4" />
|
||
|
|
{{ $t(`village.screens.${s.name}`) }}
|
||
|
|
</NuxtLink>
|
||
|
|
</nav>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</template>
|
||
|
|
|
||
|
|
<style scoped>
|
||
|
|
@reference "~/assets/css/main.css";
|
||
|
|
|
||
|
|
.tab {
|
||
|
|
@apply inline-flex items-center gap-1.5 rounded-t-sm border-2 border-b-0 border-transparent px-3 pt-1.5 pb-2 text-sm font-semibold text-wood-800 hover:bg-parchment-100 hover:text-blood-700;
|
||
|
|
}
|
||
|
|
.tab-active {
|
||
|
|
@apply border-wood-700 bg-parchment-100 text-blood-700;
|
||
|
|
}
|
||
|
|
</style>
|