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"> <script setup lang="ts">
import type { BuildOption, BuildingType, Cost } from '~/types/game' import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game'
const props = defineProps<{ const props = defineProps<{
options: BuildOption[] options: BuildOption[]
selected: { x: number; y: number } | null selected: { x: number; y: number } | null
resources: Resources
canAfford: (cost: Cost) => boolean canAfford: (cost: Cost) => boolean
busy: boolean busy: boolean
}>() }>()
const emit = defineEmits<{ build: [type: BuildingType] }>() const emit = defineEmits<{ build: [type: BuildingType]; clear: [] }>()
const { t } = useI18n() const { t } = useI18n()
function status(o: BuildOption) { function status(o: BuildOption) {
@ -18,38 +19,65 @@ function status(o: BuildOption) {
</script> </script>
<template> <template>
<section> <section class="panel">
<h2>{{ $t('village.build.title') }}</h2> <div class="panel-head">
<p> <h2 class="panel-title">{{ $t('village.build.title') }}</h2>
{{ $t('village.build.position') }}: <div class="flex items-center gap-1.5 text-sm">
<template v-if="selected">{{ $t('village.build.at_cell') }} ({{ selected.x }}|{{ selected.y }})</template> <span class="text-ink-500">{{ $t('village.build.position') }}</span>
<template v-else>{{ $t('village.build.auto') }}</template> <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> </p>
<table> </div>
<thead> </div>
<tr> <UiCost :cost="o.cost" :have="resources" />
<th>{{ $t('village.build.type') }}</th> <div class="mt-auto flex items-center justify-between gap-2">
<th>{{ $t('village.build.size') }}</th> <span class="text-xs text-rose-700">{{ status(o) }}</span>
<th>{{ $t('village.build.cost') }} ({{ $t('resources.wood') }} / {{ $t('resources.clay') }} / {{ $t('resources.iron') }})</th> <button
<th>{{ $t('village.build.time') }}</th> type="button"
<th>{{ $t('village.build.status') }}</th> class="btn btn-primary"
<th /> :disabled="busy || !!o.blocked || !canAfford(o.cost)"
</tr> @click="emit('build', o.type)"
</thead> >
<tbody> <IconUi name="hammer" class="size-3.5" />
<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)">
{{ $t('village.build.submit') }} {{ $t('village.build.submit') }}
</button> </button>
</td> </div>
</tr> </article>
</tbody> </div>
</table>
</section> </section>
</template> </template>

View File

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

View File

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

View File

@ -3,39 +3,52 @@ import type { BuildingType, VillageState } from '~/types/game'
const props = defineProps<{ village: VillageState }>() const props = defineProps<{ village: VillageState }>()
const selected = defineModel<{ x: number; y: number } | null>('selected', { default: null }) const selected = defineModel<{ x: number; y: number } | null>('selected', { default: null })
const { t } = useI18n()
interface Item { interface Tile {
key: string key: string
type: BuildingType type: BuildingType
level: number level: number
x: number
y: number
w: number w: number
h: number h: number
planned: boolean 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 // Buildings and queued new buildings as tiles spanning their footprint. The wall takes
// show as planned, and the remaining cells can be picked as the next build position. // no cells; it shows as the frame around the grid instead.
const rows = computed(() => { const tiles = computed<Tile[]>(() => [
const { w, h } = props.village.grid
const slots: (Item | 'covered' | null)[][] = Array.from({ length: h }, () => Array(w).fill(null))
const items = [
...props.village.buildings.map((b) => ({ ...b, key: `b${b.id}`, planned: false })), ...props.village.buildings.map((b) => ({ ...b, key: `b${b.id}`, planned: false })),
...props.village.queue ...props.village.queue
.filter((o) => o.action === 'build') .filter((o) => o.action === 'build')
.map((o) => ({ ...o, key: `o${o.id}`, level: 0, planned: true })), .map((o) => ({ ...o, key: `o${o.id}`, level: 0, planned: true })),
] ].flatMap((it) => {
for (const it of items) { const [w, h] = it.footprint
const [fw, fh] = 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 }] : []
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 } const freeCells = computed(() => {
} const taken = new Set<string>()
return slots.map((row, y) => for (const t of tiles.value)
row.flatMap((slot, x): Cell[] => for (let dy = 0; dy < t.h; dy++) for (let dx = 0; dx < t.w; dx++) taken.add(`${t.x + dx},${t.y + dy}`)
slot === 'covered' ? [] : slot ? [{ key: slot.key, item: slot }] : [{ key: `${x},${y}`, item: null, x, y }], 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 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) { function toggle(x: number, y: number) {
selected.value = isSelected(x, y) ? null : { x, y } 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> </script>
<template> <template>
<section> <section class="panel">
<h2>{{ $t('village.grid.title') }}</h2> <div class="panel-head">
<p><small>{{ $t('village.grid.hint') }}</small></p> <h2 class="panel-title">{{ $t('village.grid.title') }}</h2>
<table class="grid"> <p class="text-xs text-ink-500">{{ $t('village.grid.hint') }}</p>
<tbody> </div>
<tr v-for="(row, y) in rows" :key="y"> <div class="panel-body">
<template v-for="cell in row" :key="cell.key"> <div
<td v-if="cell.item" :colspan="cell.item.w" :rowspan="cell.item.h" :class="{ planned: cell.item.planned }"> class="rounded-xl bg-[#e6d6b5] p-1.5 sm:p-2"
{{ $t(`buildings.${cell.item.type}`) }} :class="hasWall ? 'ring-[6px] ring-stone-400' : 'ring-1 ring-parchment-300'"
<template v-if="cell.item.planned">({{ $t('village.grid.planned') }})</template> :title="hasWall ? $t('buildings.wall') : undefined"
<template v-else>{{ cell.item.level }}</template> >
</td> <div class="grid gap-1" :style="gridStyle">
<td v-else class="free" :class="{ selected: isSelected(cell.x, cell.y) }" @click="toggle(cell.x, cell.y)"> <button
{{ cell.x }}|{{ cell.y }} v-for="c in freeCells"
</td> :key="`${c.x},${c.y}`"
</template> type="button"
</tr> class="group grid place-items-center rounded-md border transition-colors"
</tbody> :class="
</table> 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> </section>
</template> </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"> <script setup lang="ts">
import type { Population } from '~/types/game' 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> </script>
<template> <template>
<section> <section class="panel">
<h2>{{ $t('village.population.title') }}</h2> <div class="panel-head">
<table> <h2 class="panel-title">{{ $t('village.population.title') }}</h2>
<tbody> <IconUi name="users" class="size-5 text-ink-400" />
<tr> </div>
<th>{{ $t('village.population.food_budget') }}</th> <div class="panel-body space-y-4">
<td>{{ $t('village.population.food_per_hour', { value: population.food_budget }) }}</td> <div class="grid grid-cols-2 gap-3">
</tr> <div class="rounded-lg bg-parchment-50 p-3 ring-1 ring-parchment-200">
<tr> <p class="text-xs text-ink-500">{{ $t('village.population.food_budget') }}</p>
<th>{{ $t('village.population.upkeep') }}</th> <p class="mt-0.5 flex items-center gap-1 font-semibold tabular-nums">
<td>{{ $t('village.population.food_per_hour', { value: population.upkeep }) }}</td> <IconResource resource="food" class="size-4" />
</tr> {{ $t('village.population.food_per_hour', { value: population.food_budget }) }}
<tr> </p>
<th>{{ $t('village.population.villagers') }}</th> </div>
<td>{{ population.villagers }}</td> <div class="rounded-lg bg-parchment-50 p-3 ring-1 ring-parchment-200">
</tr> <p class="text-xs text-ink-500">{{ $t('village.population.upkeep') }}</p>
<tr> <p class="mt-0.5 flex items-center gap-1 font-semibold tabular-nums">
<th>{{ $t('village.population.workers') }}</th> <IconResource resource="food" class="size-4" />
<td>{{ population.workers }}</td> {{ $t('village.population.food_per_hour', { value: population.upkeep }) }}
</tr> </p>
<tr> </div>
<th>{{ $t('village.population.idle') }}</th> </div>
<td>{{ population.villagers - population.workers }}</td>
</tr> <dl class="grid grid-cols-4 gap-2 text-center">
<tr> <div v-for="s in stats" :key="s.key">
<th>{{ $t('village.population.soldiers') }}</th> <dd class="text-lg font-semibold tabular-nums">{{ s.value }}</dd>
<td>{{ population.soldiers }}</td> <dt class="text-xs text-ink-500">{{ $t(`village.population.${s.key}`) }}</dt>
</tr> </div>
</tbody> </dl>
</table>
<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> </section>
</template> </template>

View File

@ -6,25 +6,43 @@ defineProps<{ village: VillageState; resources: Resources }>()
const list: Resource[] = ['wood', 'clay', 'iron', 'food'] const list: Resource[] = ['wood', 'clay', 'iron', 'food']
</script> </script>
<!-- Projected stock per resource, its rate, and how full storage is. -->
<template> <template>
<section> <div class="border-b border-parchment-300/70 bg-parchment-50/95 shadow-sm backdrop-blur">
<h2>{{ $t('village.resources.title') }}</h2> <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">
<table> <div
<thead> v-for="r in list"
<tr> :key="r"
<th v-for="r in list" :key="r">{{ $t(`resources.${r}`) }}</th> class="flex min-w-0 items-center gap-2"
<th>{{ $t('village.resources.cap') }}</th> :title="`${$t(`resources.${r}`)}, ${$t('village.resources.cap')} ${village.storage_cap}`"
</tr> >
</thead> <IconResource :resource="r" class="hidden size-7 sm:block" />
<tbody> <div class="min-w-0 flex-1">
<tr> <div class="flex flex-wrap items-baseline justify-between gap-x-1">
<td v-for="r in list" :key="r"> <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]) }} {{ formatAmount(resources[r]) }}
<small>({{ $t('village.resources.per_hour', { rate: formatRate(village.rates[r]) }) }})</small> </span>
</td> <span
<td>{{ village.storage_cap }}</td> class="text-[11px] tabular-nums sm:text-xs"
</tr> :class="village.rates[r] < 0 ? 'text-rose-700' : village.rates[r] > 0 ? 'text-emerald-700' : 'text-ink-400'"
</tbody> >
</table> {{ $t('village.resources.per_hour', { rate: formatRate(village.rates[r]) }) }}
</section> </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> </template>

View File

@ -17,12 +17,37 @@ async function build(type: BuildingType) {
</script> </script>
<template> <template>
<section v-if="village && resources"> <div v-if="village && resources">
<h1>{{ village.name }} ({{ village.x }}|{{ village.y }})</h1> <VillageResourceBar class="sticky top-0 z-30" :village="village" :resources="resources" />
<p v-if="error" role="alert">{{ error }}</p>
<VillageResourceBar :village="village" :resources="resources" /> <div class="mx-auto max-w-6xl space-y-6 px-4 py-6">
<VillagePopulationPanel :population="village.population" /> <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 <VillageBuildQueue
:queue="village.queue" :queue="village.queue"
:builders="village.builders" :builders="village.builders"
@ -30,23 +55,23 @@ async function build(type: BuildingType) {
:busy="busy" :busy="busy"
@cancel="v.cancel" @cancel="v.cancel"
/> />
<VillageGrid v-model:selected="selected" :village="village" /> <VillagePopulationPanel :population="village.population" />
<VillageBuildForm </div>
:options="village.buildable" </div>
:selected="selected"
:can-afford="v.canAfford"
:busy="busy"
@build="build"
/>
<VillageBuildingTable <VillageBuildingTable
:buildings="village.buildings" :buildings="village.buildings"
:resources="resources"
:can-afford="v.canAfford" :can-afford="v.canAfford"
:busy="busy" :busy="busy"
@upgrade="v.upgrade" @upgrade="v.upgrade"
@demolish="v.demolish" @demolish="v.demolish"
@priority="v.setPriority" @priority="v.setPriority"
/> />
</section> </div>
<p v-else-if="error" role="alert">{{ error }}</p> </div>
<p v-else>{{ $t('common.loading') }}</p> <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> </template>

View File

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