feat: styled village view with resource bar, tile grid and build cards

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-28 19:04:21 +01:00
parent e5cdf43e37
commit 2fa5314b7d
8 changed files with 449 additions and 257 deletions

View File

@ -1,13 +1,14 @@
<script setup lang="ts">
import type { BuildOption, BuildingType, Cost } from '~/types/game'
import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game'
const props = defineProps<{
options: BuildOption[]
selected: { x: number; y: number } | null
resources: Resources
canAfford: (cost: Cost) => boolean
busy: boolean
}>()
const emit = defineEmits<{ build: [type: BuildingType] }>()
const emit = defineEmits<{ build: [type: BuildingType]; clear: [] }>()
const { t } = useI18n()
function status(o: BuildOption) {
@ -18,38 +19,65 @@ function status(o: BuildOption) {
</script>
<template>
<section>
<h2>{{ $t('village.build.title') }}</h2>
<p>
{{ $t('village.build.position') }}:
<template v-if="selected">{{ $t('village.build.at_cell') }} ({{ selected.x }}|{{ selected.y }})</template>
<template v-else>{{ $t('village.build.auto') }}</template>
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.build.title') }}</h2>
<div class="flex items-center gap-1.5 text-sm">
<span class="text-ink-500">{{ $t('village.build.position') }}</span>
<template v-if="selected">
<span class="badge bg-amber-100 text-amber-800">
<IconUi name="pin" class="size-3.5" />
{{ selected.x }}|{{ selected.y }}
</span>
<button
type="button"
class="btn btn-ghost p-1"
:title="$t('common.clear')"
:aria-label="$t('common.clear')"
@click="emit('clear')"
>
<IconUi name="close" class="size-3.5" />
</button>
</template>
<span v-else class="badge bg-parchment-200 text-ink-700">{{ $t('village.build.auto') }}</span>
</div>
</div>
<div class="panel-body grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
<article
v-for="o in options"
:key="o.type"
class="flex flex-col gap-2.5 rounded-lg bg-parchment-50 p-3 ring-1 ring-parchment-200"
:class="o.blocked ? 'opacity-60' : ''"
>
<div class="flex items-center gap-2.5">
<IconBuildingTile :type="o.type" class="size-10" />
<div class="min-w-0">
<h3 class="truncate font-medium">{{ $t(`buildings.${o.type}`) }}</h3>
<p class="flex flex-wrap items-center gap-x-1.5 text-xs text-ink-500">
<span class="whitespace-nowrap">
{{ o.footprint[0] ? `${o.footprint[0]}×${o.footprint[1]}` : $t('village.build.surrounds') }}
</span>
<span class="flex items-center gap-1 whitespace-nowrap tabular-nums">
<IconUi name="clock" class="size-3" />
{{ formatDuration(o.seconds) }}
</span>
</p>
<table>
<thead>
<tr>
<th>{{ $t('village.build.type') }}</th>
<th>{{ $t('village.build.size') }}</th>
<th>{{ $t('village.build.cost') }} ({{ $t('resources.wood') }} / {{ $t('resources.clay') }} / {{ $t('resources.iron') }})</th>
<th>{{ $t('village.build.time') }}</th>
<th>{{ $t('village.build.status') }}</th>
<th />
</tr>
</thead>
<tbody>
<tr v-for="o in options" :key="o.type">
<td>{{ $t(`buildings.${o.type}`) }}</td>
<td>{{ o.footprint[0] }}×{{ o.footprint[1] }}</td>
<td>{{ formatCost(o.cost) }}</td>
<td>{{ formatDuration(o.seconds) }}</td>
<td>{{ status(o) }}</td>
<td>
<button type="button" :disabled="busy || !!o.blocked || !canAfford(o.cost)" @click="emit('build', o.type)">
</div>
</div>
<UiCost :cost="o.cost" :have="resources" />
<div class="mt-auto flex items-center justify-between gap-2">
<span class="text-xs text-rose-700">{{ status(o) }}</span>
<button
type="button"
class="btn btn-primary"
:disabled="busy || !!o.blocked || !canAfford(o.cost)"
@click="emit('build', o.type)"
>
<IconUi name="hammer" class="size-3.5" />
{{ $t('village.build.submit') }}
</button>
</td>
</tr>
</tbody>
</table>
</div>
</article>
</div>
</section>
</template>

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
import type { BuildOrder } from '~/types/game'
defineProps<{
const props = defineProps<{
queue: BuildOrder[]
builders: number
secondsUntil: (iso: string) => number
@ -17,33 +17,59 @@ function describe(o: BuildOrder) {
if (o.target_level < 0) return t('village.queue.remove', { type })
return t('village.queue.demolish', { type, level: o.target_level })
}
/** Share of a running order that is done, from its server timestamps. */
function progress(o: BuildOrder) {
if (!o.starts_at || !o.finishes_at) return 0
const total = (Date.parse(o.finishes_at) - Date.parse(o.starts_at)) / 1000
return total > 0 ? 1 - props.secondsUntil(o.finishes_at) / total : 1
}
</script>
<template>
<section>
<h2>{{ $t('village.queue.title') }} <small>{{ $t('village.queue.builders', { count: builders }) }}</small></h2>
<p v-if="!queue.length">{{ $t('village.queue.empty') }}</p>
<table v-else>
<thead>
<tr>
<th>#</th>
<th>{{ $t('village.queue.order') }}</th>
<th>{{ $t('village.queue.builder') }}</th>
<th>{{ $t('village.queue.remaining') }}</th>
<th />
</tr>
</thead>
<tbody>
<tr v-for="o in queue" :key="o.id">
<td>{{ o.position }}</td>
<td>{{ describe(o) }}</td>
<td>{{ o.builder ?? '–' }}</td>
<td>{{ o.finishes_at ? formatDuration(secondsUntil(o.finishes_at)) : $t('village.queue.waiting') }}</td>
<td>
<button type="button" :disabled="busy" @click="emit('cancel', o.id)">{{ $t('village.queue.cancel') }}</button>
</td>
</tr>
</tbody>
</table>
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.queue.title') }}</h2>
<span class="badge bg-parchment-200 text-ink-700">
<IconUi name="hammer" class="size-3.5" />
{{ $t('village.queue.builders', { count: builders }) }}
</span>
</div>
<div class="panel-body">
<p v-if="!queue.length" class="py-4 text-center text-sm text-ink-500">{{ $t('village.queue.empty') }}</p>
<ol v-else class="space-y-2.5">
<li
v-for="o in queue"
:key="o.id"
class="rounded-lg p-3 ring-1"
:class="o.finishes_at ? 'bg-white ring-amber-200' : 'bg-parchment-50 ring-parchment-200'"
>
<div class="flex items-center gap-2.5">
<IconBuildingTile :type="o.type" class="size-9" />
<div class="min-w-0 flex-1">
<p class="text-sm leading-snug font-medium">{{ describe(o) }}</p>
<p class="text-xs text-ink-500">
{{ o.builder ? $t('village.queue.builder_n', { n: o.builder }) : $t('village.queue.waiting') }}
</p>
</div>
<span v-if="o.finishes_at" class="flex items-center gap-1 text-sm font-semibold tabular-nums">
<IconUi name="clock" class="size-3.5 text-ink-400" />
{{ formatDuration(secondsUntil(o.finishes_at)) }}
</span>
<button
type="button"
class="btn btn-danger p-1.5"
:title="$t('village.queue.cancel')"
:aria-label="$t('village.queue.cancel')"
:disabled="busy"
@click="emit('cancel', o.id)"
>
<IconUi name="close" class="size-4" />
</button>
</div>
<UiBar v-if="o.finishes_at" class="mt-2.5" :value="progress(o)" />
</li>
</ol>
</div>
</section>
</template>

View File

@ -1,8 +1,9 @@
<script setup lang="ts">
import type { Building, Cost } from '~/types/game'
import type { Building, Cost, Resources } from '~/types/game'
defineProps<{
buildings: Building[]
resources: Resources
canAfford: (cost: Cost) => boolean
busy: boolean
}>()
@ -11,63 +12,106 @@ const emit = defineEmits<{
demolish: [buildingId: number]
priority: [buildingId: number, priority: number]
}>()
const { t } = useI18n()
function onPriority(b: Building, e: Event) {
emit('priority', b.id, Number((e.target as HTMLInputElement).value))
}
const demolishTitle = (b: Building) =>
b.demolish ? `${t('village.buildings.refund')} ${formatCost(b.demolish.refund)}, ${formatDuration(b.demolish.seconds)}` : ''
</script>
<template>
<section>
<h2>{{ $t('village.buildings.title') }}</h2>
<table>
<thead>
<tr>
<th>{{ $t('village.buildings.type') }}</th>
<th>{{ $t('village.buildings.level') }}</th>
<th>{{ $t('village.buildings.position') }}</th>
<th>{{ $t('village.buildings.size') }}</th>
<th>{{ $t('village.buildings.workers') }}</th>
<th>{{ $t('village.buildings.staffing') }}</th>
<th>{{ $t('village.buildings.output') }}</th>
<th>{{ $t('village.buildings.priority') }}</th>
<th>{{ $t('village.buildings.actions') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="b in buildings" :key="b.id">
<td>{{ $t(`buildings.${b.type}`) }}</td>
<td>{{ b.level }}</td>
<td>{{ b.footprint[0] ? `${b.x}|${b.y}` : '–' }}</td>
<td>{{ b.footprint[0] }}×{{ b.footprint[1] }}</td>
<td>{{ b.workers.assigned }}/{{ b.workers.required }}</td>
<td>{{ Math.round(b.staffing * 100) }}%</td>
<td>
<template v-if="b.production">
{{ $t(`resources.${b.production.resource}`) }}
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.buildings.title') }}</h2>
<span class="badge bg-parchment-200 text-ink-700">{{ buildings.length }}</span>
</div>
<ul class="divide-y divide-parchment-200">
<li
v-for="b in buildings"
:key="b.id"
class="grid gap-3 px-4 py-3 md:grid-cols-[minmax(0,13rem)_minmax(0,1fr)_19rem] md:items-center"
>
<div class="flex min-w-0 items-center gap-3">
<IconBuildingTile :type="b.type" class="size-11" />
<div class="min-w-0">
<p class="truncate font-medium">{{ $t(`buildings.${b.type}`) }}</p>
<p class="text-xs text-ink-500">
{{ $t('village.buildings.level_n', { level: b.level }) }}
<template v-if="b.footprint[0]"> · {{ b.x }}|{{ b.y }}</template>
</p>
</div>
</div>
<div class="grid grid-cols-3 gap-3 text-sm">
<div class="min-w-0">
<p class="text-xs text-ink-500">{{ $t('village.buildings.workers') }}</p>
<p class="tabular-nums">{{ b.workers.assigned }}/{{ b.workers.required }}</p>
<UiBar class="mt-1" :value="b.staffing" :tone="b.staffing < 1 ? 'rose' : 'emerald'" />
</div>
<div class="min-w-0">
<p class="text-xs text-ink-500">{{ $t('village.buildings.output') }}</p>
<p v-if="b.production" class="flex items-center gap-1 tabular-nums">
<IconResource :resource="b.production.resource" class="size-4" />
{{ $t('village.resources.per_hour', { rate: formatRate(b.production.per_hour) }) }}
</template>
<template v-else>–</template>
</td>
<td>
<input type="number" min="0" max="9" size="2" :value="b.priority" :disabled="busy" @change="onPriority(b, $event)" />
</td>
<td>
</p>
<p v-else class="text-ink-400">–</p>
</div>
<div class="min-w-0">
<p class="text-xs text-ink-500">{{ $t('village.buildings.priority') }}</p>
<div class="mt-0.5 inline-flex items-center rounded-lg ring-1 ring-parchment-300">
<button
v-if="b.upgrade"
type="button"
class="btn btn-ghost rounded-r-none p-1"
:aria-label="$t('village.buildings.priority_down')"
:disabled="busy || b.priority <= 0"
@click="emit('priority', b.id, b.priority - 1)"
>
<IconUi name="minus" class="size-3.5" />
</button>
<span class="w-6 text-center font-semibold tabular-nums">{{ b.priority }}</span>
<button
type="button"
class="btn btn-ghost rounded-l-none p-1"
:aria-label="$t('village.buildings.priority_up')"
:disabled="busy || b.priority >= 9"
@click="emit('priority', b.id, b.priority + 1)"
>
<IconUi name="plus" class="size-3.5" />
</button>
</div>
</div>
</div>
<div class="flex flex-wrap items-center gap-x-3 gap-y-2 md:justify-end">
<div v-if="b.upgrade" class="flex flex-col items-start gap-1 md:items-end">
<button
type="button"
class="btn btn-primary"
:disabled="busy || !canAfford(b.upgrade.cost)"
@click="emit('upgrade', b.id)"
>
<IconUi name="up" class="size-3.5" />
{{ $t('village.buildings.upgrade', { level: b.upgrade.target_level }) }}
({{ formatCost(b.upgrade.cost) }}, {{ formatDuration(b.upgrade.seconds) }})
</button>
<button v-if="b.demolish" type="button" :disabled="busy" @click="emit('demolish', b.id)">
{{ $t('village.buildings.demolish') }} ({{ $t('village.buildings.refund') }} {{ formatCost(b.demolish.refund) }})
<span class="flex items-center gap-2 text-xs text-ink-500">
<UiCost :cost="b.upgrade.cost" :have="resources" />
<span class="flex items-center gap-1 tabular-nums">
<IconUi name="clock" class="size-3" />
{{ formatDuration(b.upgrade.seconds) }}
</span>
</span>
</div>
<button
v-if="b.demolish"
type="button"
class="btn btn-danger"
:title="demolishTitle(b)"
:disabled="busy"
@click="emit('demolish', b.id)"
>
{{ $t('village.buildings.demolish') }}
</button>
</td>
</tr>
</tbody>
</table>
</div>
</li>
</ul>
</section>
</template>

View File

@ -3,39 +3,52 @@ import type { BuildingType, VillageState } from '~/types/game'
const props = defineProps<{ village: VillageState }>()
const selected = defineModel<{ x: number; y: number } | null>('selected', { default: null })
const { t } = useI18n()
interface Item {
interface Tile {
key: string
type: BuildingType
level: number
x: number
y: number
w: number
h: number
planned: boolean
}
type Cell = { key: string; item: Item } | { key: string; item: null; x: number; y: number }
// A plain table: each building is one cell spanning its footprint, queued new buildings
// show as planned, and the remaining cells can be picked as the next build position.
const rows = computed(() => {
const { w, h } = props.village.grid
const slots: (Item | 'covered' | null)[][] = Array.from({ length: h }, () => Array(w).fill(null))
const items = [
// Buildings and queued new buildings as tiles spanning their footprint. The wall takes
// no cells; it shows as the frame around the grid instead.
const tiles = computed<Tile[]>(() => [
...props.village.buildings.map((b) => ({ ...b, key: `b${b.id}`, planned: false })),
...props.village.queue
.filter((o) => o.action === 'build')
.map((o) => ({ ...o, key: `o${o.id}`, level: 0, planned: true })),
]
for (const it of items) {
const [fw, fh] = it.footprint
if (fw === 0 || fh === 0) continue
for (let dy = 0; dy < fh; dy++) for (let dx = 0; dx < fw; dx++) slots[it.y + dy]![it.x + dx] = 'covered'
slots[it.y]![it.x] = { key: it.key, type: it.type, level: it.level, w: fw, h: fh, planned: it.planned }
}
return slots.map((row, y) =>
row.flatMap((slot, x): Cell[] =>
slot === 'covered' ? [] : slot ? [{ key: slot.key, item: slot }] : [{ key: `${x},${y}`, item: null, x, y }],
),
)
].flatMap((it) => {
const [w, h] = it.footprint
return w && h ? [{ key: it.key, type: it.type, level: it.level, x: it.x, y: it.y, w, h, planned: it.planned }] : []
}))
const freeCells = computed(() => {
const taken = new Set<string>()
for (const t of tiles.value)
for (let dy = 0; dy < t.h; dy++) for (let dx = 0; dx < t.w; dx++) taken.add(`${t.x + dx},${t.y + dy}`)
const cells: { x: number; y: number }[] = []
for (let y = 0; y < props.village.grid.h; y++)
for (let x = 0; x < props.village.grid.w; x++) if (!taken.has(`${x},${y}`)) cells.push({ x, y })
return cells
})
const hasWall = computed(() => props.village.buildings.some((b) => b.type === 'wall'))
const gridStyle = computed(() => ({
gridTemplateColumns: `repeat(${props.village.grid.w}, minmax(0, 1fr))`,
gridTemplateRows: `repeat(${props.village.grid.h}, minmax(0, 1fr))`,
aspectRatio: `${props.village.grid.w} / ${props.village.grid.h}`,
}))
const place = (x: number, y: number, w = 1, h = 1) => ({
gridColumn: `${x + 1} / span ${w}`,
gridRow: `${y + 1} / span ${h}`,
})
const isSelected = (x: number, y: number) => selected.value?.x === x && selected.value?.y === y
@ -43,50 +56,65 @@ const isSelected = (x: number, y: number) => selected.value?.x === x && selected
function toggle(x: number, y: number) {
selected.value = isSelected(x, y) ? null : { x, y }
}
function tileTitle(tile: Tile) {
const name = t(`buildings.${tile.type}`)
return tile.planned ? `${name} (${t('village.grid.planned')})` : `${name}, ${t('village.buildings.level_n', { level: tile.level })}`
}
</script>
<template>
<section>
<h2>{{ $t('village.grid.title') }}</h2>
<p><small>{{ $t('village.grid.hint') }}</small></p>
<table class="grid">
<tbody>
<tr v-for="(row, y) in rows" :key="y">
<template v-for="cell in row" :key="cell.key">
<td v-if="cell.item" :colspan="cell.item.w" :rowspan="cell.item.h" :class="{ planned: cell.item.planned }">
{{ $t(`buildings.${cell.item.type}`) }}
<template v-if="cell.item.planned">({{ $t('village.grid.planned') }})</template>
<template v-else>{{ cell.item.level }}</template>
</td>
<td v-else class="free" :class="{ selected: isSelected(cell.x, cell.y) }" @click="toggle(cell.x, cell.y)">
{{ cell.x }}|{{ cell.y }}
</td>
</template>
</tr>
</tbody>
</table>
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.grid.title') }}</h2>
<p class="text-xs text-ink-500">{{ $t('village.grid.hint') }}</p>
</div>
<div class="panel-body">
<div
class="rounded-xl bg-[#e6d6b5] p-1.5 sm:p-2"
:class="hasWall ? 'ring-[6px] ring-stone-400' : 'ring-1 ring-parchment-300'"
:title="hasWall ? $t('buildings.wall') : undefined"
>
<div class="grid gap-1" :style="gridStyle">
<button
v-for="c in freeCells"
:key="`${c.x},${c.y}`"
type="button"
class="group grid place-items-center rounded-md border transition-colors"
:class="
isSelected(c.x, c.y)
? 'border-amber-600 bg-amber-100 text-amber-700 ring-2 ring-amber-500'
: 'border-dashed border-[#cdb68c] bg-[#efe3c9] text-transparent hover:border-amber-500 hover:bg-amber-50 hover:text-amber-500'
"
:style="place(c.x, c.y)"
:title="`${$t('village.grid.free_cell')} ${c.x}|${c.y}`"
:aria-pressed="isSelected(c.x, c.y)"
@click="toggle(c.x, c.y)"
>
<IconUi name="pin" class="size-3/5 max-h-5 max-w-5" />
</button>
<div
v-for="tile in tiles"
:key="tile.key"
class="relative flex min-w-0 flex-col items-center justify-center gap-0.5 overflow-hidden rounded-lg border-2 p-1 text-center"
:class="tile.planned ? 'border-dashed opacity-60' : 'shadow-sm'"
:style="{ ...place(tile.x, tile.y, tile.w, tile.h), ...buildingTileStyle(tile.type) }"
:title="tileTitle(tile)"
>
<IconBuilding :type="tile.type" :class="tile.w > 1 ? 'size-6 sm:size-9' : 'size-4 sm:size-6'" />
<span v-if="tile.w > 1" class="hidden max-w-full truncate text-xs font-medium text-ink-700 sm:block">
{{ $t(`buildings.${tile.type}`) }}
</span>
<span
class="absolute top-0.5 right-0.5 rounded bg-white/85 px-1 text-[10px] leading-4 font-semibold text-ink-700 tabular-nums"
:class="tile.w > 1 ? '' : 'hidden sm:block'"
>
{{ tile.planned ? '…' : tile.level }}
</span>
</div>
</div>
</div>
</div>
</section>
</template>
<style scoped>
.grid {
border-collapse: collapse;
}
.grid td {
border: 1px solid;
width: 5em;
height: 2.5em;
text-align: center;
}
.free {
cursor: pointer;
opacity: 0.5;
}
.selected {
outline: 3px solid;
opacity: 1;
}
.planned {
font-style: italic;
}
</style>

View File

@ -1,39 +1,54 @@
<script setup lang="ts">
import type { Population } from '~/types/game'
defineProps<{ population: Population }>()
const props = defineProps<{ population: Population }>()
const stats = computed(() => [
{ key: 'villagers', value: props.population.villagers },
{ key: 'workers', value: props.population.workers },
{ key: 'idle', value: props.population.villagers - props.population.workers },
{ key: 'soldiers', value: props.population.soldiers },
])
</script>
<template>
<section>
<h2>{{ $t('village.population.title') }}</h2>
<table>
<tbody>
<tr>
<th>{{ $t('village.population.food_budget') }}</th>
<td>{{ $t('village.population.food_per_hour', { value: population.food_budget }) }}</td>
</tr>
<tr>
<th>{{ $t('village.population.upkeep') }}</th>
<td>{{ $t('village.population.food_per_hour', { value: population.upkeep }) }}</td>
</tr>
<tr>
<th>{{ $t('village.population.villagers') }}</th>
<td>{{ population.villagers }}</td>
</tr>
<tr>
<th>{{ $t('village.population.workers') }}</th>
<td>{{ population.workers }}</td>
</tr>
<tr>
<th>{{ $t('village.population.idle') }}</th>
<td>{{ population.villagers - population.workers }}</td>
</tr>
<tr>
<th>{{ $t('village.population.soldiers') }}</th>
<td>{{ population.soldiers }}</td>
</tr>
</tbody>
</table>
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.population.title') }}</h2>
<IconUi name="users" class="size-5 text-ink-400" />
</div>
<div class="panel-body space-y-4">
<div class="grid grid-cols-2 gap-3">
<div class="rounded-lg bg-parchment-50 p-3 ring-1 ring-parchment-200">
<p class="text-xs text-ink-500">{{ $t('village.population.food_budget') }}</p>
<p class="mt-0.5 flex items-center gap-1 font-semibold tabular-nums">
<IconResource resource="food" class="size-4" />
{{ $t('village.population.food_per_hour', { value: population.food_budget }) }}
</p>
</div>
<div class="rounded-lg bg-parchment-50 p-3 ring-1 ring-parchment-200">
<p class="text-xs text-ink-500">{{ $t('village.population.upkeep') }}</p>
<p class="mt-0.5 flex items-center gap-1 font-semibold tabular-nums">
<IconResource resource="food" class="size-4" />
{{ $t('village.population.food_per_hour', { value: population.upkeep }) }}
</p>
</div>
</div>
<dl class="grid grid-cols-4 gap-2 text-center">
<div v-for="s in stats" :key="s.key">
<dd class="text-lg font-semibold tabular-nums">{{ s.value }}</dd>
<dt class="text-xs text-ink-500">{{ $t(`village.population.${s.key}`) }}</dt>
</div>
</dl>
<div>
<div class="mb-1 flex justify-between text-xs text-ink-500">
<span>{{ $t('village.population.workforce') }}</span>
<span class="tabular-nums">{{ population.workers }}/{{ population.villagers }}</span>
</div>
<UiBar :value="population.villagers ? population.workers / population.villagers : 0" tone="sky" />
</div>
</div>
</section>
</template>

View File

@ -6,25 +6,43 @@ defineProps<{ village: VillageState; resources: Resources }>()
const list: Resource[] = ['wood', 'clay', 'iron', 'food']
</script>
<!-- Projected stock per resource, its rate, and how full storage is. -->
<template>
<section>
<h2>{{ $t('village.resources.title') }}</h2>
<table>
<thead>
<tr>
<th v-for="r in list" :key="r">{{ $t(`resources.${r}`) }}</th>
<th>{{ $t('village.resources.cap') }}</th>
</tr>
</thead>
<tbody>
<tr>
<td v-for="r in list" :key="r">
<div class="border-b border-parchment-300/70 bg-parchment-50/95 shadow-sm backdrop-blur">
<div class="mx-auto grid max-w-6xl grid-cols-4 gap-x-3 px-4 py-2 sm:grid-cols-[repeat(4,minmax(0,1fr))_auto] sm:gap-x-5">
<div
v-for="r in list"
:key="r"
class="flex min-w-0 items-center gap-2"
:title="`${$t(`resources.${r}`)}, ${$t('village.resources.cap')} ${village.storage_cap}`"
>
<IconResource :resource="r" class="hidden size-7 sm:block" />
<div class="min-w-0 flex-1">
<div class="flex flex-wrap items-baseline justify-between gap-x-1">
<span class="flex items-center gap-1 font-semibold tabular-nums">
<IconResource :resource="r" class="size-4 sm:hidden" />
<span class="sr-only">{{ $t(`resources.${r}`) }}</span>
{{ formatAmount(resources[r]) }}
<small>({{ $t('village.resources.per_hour', { rate: formatRate(village.rates[r]) }) }})</small>
</td>
<td>{{ village.storage_cap }}</td>
</tr>
</tbody>
</table>
</section>
</span>
<span
class="text-[11px] tabular-nums sm:text-xs"
:class="village.rates[r] < 0 ? 'text-rose-700' : village.rates[r] > 0 ? 'text-emerald-700' : 'text-ink-400'"
>
{{ $t('village.resources.per_hour', { rate: formatRate(village.rates[r]) }) }}
</span>
</div>
<UiBar
class="mt-1"
:value="resources[r] / village.storage_cap"
:tone="resources[r] >= village.storage_cap ? 'rose' : 'amber'"
/>
</div>
</div>
<div class="hidden items-center justify-end gap-1.5 text-xs text-ink-500 sm:flex">
<IconBuilding type="storage" class="size-4" />
{{ $t('village.resources.cap') }}
<span class="font-semibold text-ink-700 tabular-nums">{{ village.storage_cap }}</span>
</div>
</div>
</div>
</template>

View File

@ -17,12 +17,37 @@ async function build(type: BuildingType) {
</script>
<template>
<section v-if="village && resources">
<h1>{{ village.name }} ({{ village.x }}|{{ village.y }})</h1>
<p v-if="error" role="alert">{{ error }}</p>
<div v-if="village && resources">
<VillageResourceBar class="sticky top-0 z-30" :village="village" :resources="resources" />
<VillageResourceBar :village="village" :resources="resources" />
<VillagePopulationPanel :population="village.population" />
<div class="mx-auto max-w-6xl space-y-6 px-4 py-6">
<header class="flex flex-wrap items-end justify-between gap-2">
<div class="min-w-0">
<p class="text-xs font-medium tracking-wide text-ink-500 uppercase">{{ $t('village.title') }}</p>
<h1 class="truncate font-display text-2xl font-semibold sm:text-3xl">{{ village.name }}</h1>
</div>
<span class="badge bg-parchment-200 text-ink-700">
<IconUi name="pin" class="size-3.5" />
{{ village.x }}|{{ village.y }}
</span>
</header>
<p v-if="error" class="alert" role="alert">{{ error }}</p>
<div class="grid gap-6 lg:grid-cols-3">
<div class="space-y-6 lg:col-span-2">
<VillageGrid v-model:selected="selected" :village="village" />
<VillageBuildForm
:options="village.buildable"
:selected="selected"
:resources="resources"
:can-afford="v.canAfford"
:busy="busy"
@build="build"
@clear="selected = null"
/>
</div>
<div class="space-y-6">
<VillageBuildQueue
:queue="village.queue"
:builders="village.builders"
@ -30,23 +55,23 @@ async function build(type: BuildingType) {
:busy="busy"
@cancel="v.cancel"
/>
<VillageGrid v-model:selected="selected" :village="village" />
<VillageBuildForm
:options="village.buildable"
:selected="selected"
:can-afford="v.canAfford"
:busy="busy"
@build="build"
/>
<VillagePopulationPanel :population="village.population" />
</div>
</div>
<VillageBuildingTable
:buildings="village.buildings"
:resources="resources"
:can-afford="v.canAfford"
:busy="busy"
@upgrade="v.upgrade"
@demolish="v.demolish"
@priority="v.setPriority"
/>
</section>
<p v-else-if="error" role="alert">{{ error }}</p>
<p v-else>{{ $t('common.loading') }}</p>
</div>
</div>
<div v-else class="mx-auto max-w-6xl 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>

View File

@ -3,6 +3,7 @@ import type { TranslationFile } from '@blax-software/i18n'
export default {
en: {
village: {
title: 'Village',
resources: {
title: 'Resources',
cap: 'Storage cap',
@ -16,6 +17,7 @@ export default {
workers: 'Working',
idle: 'Idle',
soldiers: 'Soldiers',
workforce: 'Villagers at work',
food_per_hour: '{value} food/h',
},
buildings: {
@ -29,14 +31,18 @@ export default {
output: 'Output',
priority: 'Priority',
actions: 'Actions',
level_n: 'Level {level}',
priority_down: 'Lower priority',
priority_up: 'Raise priority',
upgrade: 'Upgrade to {level}',
demolish: 'Demolish',
refund: 'refund',
refund: 'Refund',
},
grid: {
title: 'Village grid',
hint: 'Click a free cell to choose where the next building goes.',
planned: 'planned',
free_cell: 'Free cell',
},
build: {
title: 'New building',
@ -48,6 +54,7 @@ export default {
position: 'Position',
auto: 'First free slot',
at_cell: 'Selected cell',
surrounds: 'Around the village',
submit: 'Build',
},
queue: {
@ -56,6 +63,7 @@ export default {
empty: 'Nothing queued.',
order: 'Order',
builder: 'Builder',
builder_n: 'Builder {n}',
remaining: 'Done in',
waiting: 'Waiting',
cancel: 'Cancel',