162 lines
8.0 KiB
Vue
162 lines
8.0 KiB
Vue
<script setup lang="ts">
|
||
import type { BuildOrder, UnitType, VillageRole, 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)
|
||
const incoming = computed(() => props.village.movements.filter((m) => m.direction === 'in' && m.type === 'attack'))
|
||
const commands = computed(() => props.village.movements.filter((m) => m.direction !== 'in').length)
|
||
const spec = computed(() => props.village.specialisation)
|
||
const roleSpace = computed(() => spec.value.roles.reduce((sum, r) => sum + (spec.value.space[r.role] ?? 0), 0))
|
||
const roleShare = (role: VillageRole) => (roleSpace.value ? Math.round((100 * (spec.value.space[role] ?? 0)) / roleSpace.value) : 0)
|
||
const bonuses = computed(() => Object.entries(spec.value.roles.find((r) => r.role === spec.value.role)?.bonuses ?? {}))
|
||
|
||
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-2 p-2 text-sm">
|
||
<section v-if="incoming.length" class="side-box border-blood-700">
|
||
<h2 class="panel-head panel-title side-alarm">{{ $t('village.side.incoming') }}</h2>
|
||
<ul class="side-body">
|
||
<li v-for="m in incoming" :key="m.id" class="flex items-center gap-2 text-blood-700">
|
||
<IconUi name="attack" class="size-4" />
|
||
<span class="min-w-0 flex-1 truncate">{{ m.raid ? $t('village.side.raiders', { from: `(${m.from.x}|${m.from.y})` }) : villageLabel(m.from) }}</span>
|
||
<span class="font-semibold tabular-nums">{{ formatDuration(secondsUntil(m.arrives_at)) }}</span>
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
|
||
<section class="side-box">
|
||
<h2 class="panel-head panel-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="panel-head panel-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>
|
||
<p v-if="commands" class="text-xs text-ink-500">{{ $t('village.side.commands') }}: {{ commands }}</p>
|
||
<div class="side-actions">
|
||
<NuxtLink :to="`${base}/recruit`" class="btn btn-outline">{{ $t('village.side.recruit') }}</NuxtLink>
|
||
<NuxtLink :to="`${base}/rally`" class="btn btn-outline">{{ $t('village.side.rally') }}</NuxtLink>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="side-box">
|
||
<h2 class="panel-head panel-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="panel-head panel-title">{{ $t('village.role.title') }}</h2>
|
||
<div class="side-body">
|
||
<p class="font-semibold">{{ spec.role ? $t(`village.role.${spec.role}`) : $t('village.role.none') }}</p>
|
||
<ul v-if="spec.role" class="text-moss-700">
|
||
<li v-for="[key, value] in bonuses" :key="key">{{ $t(`village.role.bonus.${key}`, { value: Math.round(value * 100) }) }}</li>
|
||
</ul>
|
||
<ul>
|
||
<li v-for="r in spec.roles" :key="r.role" class="flex items-center gap-2">
|
||
<span class="flex-1">{{ $t(`village.role.kinds.${r.role}`) }}</span>
|
||
<span class="tabular-nums">{{ $t('village.role.space', { space: spec.space[r.role] ?? 0, share: roleShare(r.role) }) }}</span>
|
||
</li>
|
||
</ul>
|
||
<p v-if="!spec.role" class="text-xs text-ink-500">{{ $t('village.role.hint', { min: spec.min_space, share: Math.round(spec.share * 100) }) }}</p>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="side-box">
|
||
<h2 class="panel-head panel-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>
|
||
<div class="side-actions">
|
||
<NuxtLink :to="`${base}/build`" class="btn btn-outline">{{ $t('village.screens.build') }}</NuxtLink>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</aside>
|
||
</template>
|
||
|
||
<style scoped>
|
||
@reference "~/assets/css/main.css";
|
||
|
||
/* The same panel as everywhere; the column around them is the frame. */
|
||
.side-box {
|
||
@apply border border-wood-700 bg-parchment-50;
|
||
background-image: var(--pat-parchment-50);
|
||
}
|
||
/* Incoming attacks: the band in oxblood, no cloth texture. */
|
||
.side-alarm {
|
||
@apply border-blood-800 bg-blood-700 text-parchment-50;
|
||
background-image: none;
|
||
}
|
||
.side-body {
|
||
@apply space-y-0.5 px-1.5 py-1;
|
||
}
|
||
/* Links to the screens as small buttons on one line, never wrapped. */
|
||
.side-actions {
|
||
@apply flex flex-nowrap gap-1 pt-1 whitespace-nowrap;
|
||
}
|
||
</style>
|