game-village-politics-frontend/app/components/village/OverviewSidebar.vue

118 lines
5.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import type { BuildOrder, UnitType, VillageState } from '~/types/game'
const props = defineProps<{
village: VillageState
/** The village page path, for the links to its screens. */
base: string
secondsUntil: (iso: string) => number
}>()
const { t } = useI18n()
const production = computed(() => (['wood', 'clay', 'iron', 'food'] as const).map((r) => ({ r, rate: props.village.rates[r] })))
const troops = computed(() => (Object.entries(props.village.troops) as [UnitType, number][]).filter(([, n]) => n > 0))
const idle = computed(() => props.village.population.villagers - props.village.population.workers - props.village.levy.militia)
const spaceShare = computed(() => props.village.space.used / props.village.space.max)
function order(o: BuildOrder) {
const type = t(`buildings.${o.type}`)
if (o.action === 'build') return type
return `${type} ${o.target_level < 1 ? '×' : `→ ${o.target_level}`}`
}
</script>
<!-- The column beside the village: small boxes with the numbers that matter at a glance. -->
<template>
<aside class="space-y-3 bg-parchment-100 p-3 text-sm">
<section class="side-box">
<h2 class="side-title">{{ $t('village.side.production') }}</h2>
<ul class="side-body">
<li v-for="{ r, rate } in production" :key="r" class="flex items-center gap-2">
<IconResource :resource="r" class="size-4" />
<span class="flex-1">{{ $t(`resources.${r}`) }}</span>
<span class="font-semibold tabular-nums" :class="rate < 0 ? 'text-blood-700' : ''">
{{ $t('village.resources.per_hour', { rate: formatRate(rate) }) }}
</span>
</li>
</ul>
</section>
<section class="side-box">
<h2 class="side-title">{{ $t('village.side.units') }}</h2>
<div class="side-body">
<ul v-if="troops.length || village.levy.militia">
<li v-for="[unit, count] in troops" :key="unit" class="flex items-center gap-2">
<IconUnit :unit="unit" class="size-4 text-wood-800" />
<span class="font-semibold tabular-nums">{{ count }}</span>
<span class="truncate">{{ $t(`units.${unit}`) }}</span>
</li>
<li v-if="village.levy.militia" class="flex items-center gap-2">
<IconUnit unit="militia" class="size-4 text-wood-800" />
<span class="font-semibold tabular-nums">{{ village.levy.militia }}</span>
<span>{{ $t('village.levy.militia') }}</span>
</li>
</ul>
<p v-else class="text-ink-500">{{ $t('village.troops.none') }}</p>
<p v-if="village.population.training" class="text-xs text-ink-500">{{ $t('village.troops.training', { count: village.population.training }) }}</p>
<NuxtLink :to="`${base}/recruit`" class="side-link">» {{ $t('village.side.recruit') }}</NuxtLink>
</div>
</section>
<section class="side-box">
<h2 class="side-title">{{ $t('village.population.title') }}</h2>
<dl class="grid grid-cols-[1fr_auto] gap-x-2 gap-y-1 px-2.5 py-1.5">
<dt>{{ $t('village.population.villagers') }}</dt>
<dd class="text-right font-semibold tabular-nums">{{ village.population.villagers }}</dd>
<dt>{{ $t('village.population.workers') }}</dt>
<dd class="text-right tabular-nums">{{ village.population.workers }}</dd>
<dt>{{ $t('village.population.idle') }}</dt>
<dd class="text-right tabular-nums">{{ idle }}</dd>
<dt>{{ $t('village.population.upkeep') }}</dt>
<dd class="text-right tabular-nums">{{ village.population.upkeep }}/{{ village.population.food_budget }}</dd>
</dl>
</section>
<section class="side-box">
<h2 class="side-title">{{ $t('village.side.construction') }}</h2>
<div class="side-body">
<ol v-if="village.queue.length">
<li v-for="o in village.queue" :key="o.id" class="flex items-center gap-2">
<IconBuilding :type="o.type" class="size-4 text-wood-800" />
<span class="min-w-0 flex-1 truncate">{{ order(o) }}</span>
<span class="tabular-nums" :class="o.finishes_at ? 'font-semibold' : 'text-ink-500'">
{{ o.finishes_at ? formatDuration(secondsUntil(o.finishes_at)) : $t('village.queue.waiting') }}
</span>
</li>
</ol>
<p v-else class="text-ink-500">{{ $t('village.queue.empty') }}</p>
<div class="pt-1">
<div class="mb-1 flex justify-between text-xs text-ink-500">
<span>{{ $t('village.diorama.space') }}</span>
<span class="tabular-nums">{{ village.space.used }}/{{ village.space.max }}</span>
</div>
<UiBar :value="spaceShare" :tone="spaceShare >= 1 ? 'rose' : 'emerald'" />
</div>
<NuxtLink :to="`${base}/build`" class="side-link">» {{ $t('village.screens.build') }}</NuxtLink>
</div>
</section>
</aside>
</template>
<style scoped>
@reference "~/assets/css/main.css";
.side-box {
@apply rounded-sm border-2 border-wood-700 bg-parchment-50;
}
.side-title {
@apply border-b border-wood-700 bg-parchment-200 px-2.5 py-1 font-display text-sm font-semibold text-wood-900;
font-variant: small-caps;
}
.side-body {
@apply space-y-1 px-2.5 py-1.5;
}
.side-link {
@apply block pt-0.5 text-sm font-semibold text-blood-700 hover:underline;
}
</style>