feat: one construction table for upgrades and new buildings, demolition tab, dense workforce table

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-28 21:18:57 +01:00
parent d8d752c202
commit 0c02723b00
6 changed files with 296 additions and 182 deletions

View File

@ -5,13 +5,15 @@ defineProps<{
cost: Cost
/** Projected stock; amounts the village lacks show in red. */
have?: Resources | null
/** Keep the three amounts on one line, for table cells. */
nowrap?: boolean
}>()
const list = ['wood', 'clay', 'iron'] as const
</script>
<template>
<span class="inline-flex flex-wrap items-center gap-x-2.5 gap-y-1 text-xs tabular-nums">
<span class="inline-flex items-center gap-x-2.5 gap-y-1 text-xs tabular-nums" :class="nowrap ? 'whitespace-nowrap' : 'flex-wrap'">
<span
v-for="r in list"
:key="r"

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import type { BuildOption, Building, BuildingType, Cost, Resources } from '~/types/game'
import type { BuildOption, Building, BuildingType, Cost, Offer, Resources } from '~/types/game'
const props = defineProps<{
options: BuildOption[]
@ -9,38 +9,103 @@ const props = defineProps<{
canAfford: (cost: Cost) => boolean
busy: boolean
}>()
const emit = defineEmits<{ build: [type: BuildingType] }>()
const emit = defineEmits<{
build: [type: BuildingType]
upgrade: [buildingId: number]
demolish: [buildingId: number]
select: [buildingId: number]
}>()
const { t } = useI18n()
// One row per type, like the Die Stämme headquarters: what is possible now on top,
// types still waiting for requirements in their own list below.
const available = computed(() => props.options.filter((o) => o.blocked !== 'requires'))
const locked = computed(() => props.options.filter((o) => o.blocked === 'requires'))
// Like the Die Stämme headquarters: one table where every building upgrades in its own
// row, and building one more of a type is the row below its instances. Demolition is
// the second tab; types still waiting for requirements are listed at the bottom.
const tab = ref<'construct' | 'demolish'>('construct')
const built = computed(() => {
const counts: Partial<Record<BuildingType, number>> = {}
for (const b of props.buildings) counts[b.type] = (counts[b.type] ?? 0) + 1
return counts
const byType = computed(() => {
const map = new Map<BuildingType, Building[]>()
for (const b of props.buildings) map.set(b.type, [...(map.get(b.type) ?? []), b])
return map
})
function status(o: BuildOption) {
if (o.blocked) return t(`village.blocked.${o.blocked}`)
if (!props.canAfford(o.cost)) return t('village.blocked.resources')
type Row =
| { kind: 'upgrade'; key: string; type: BuildingType; name: string; building: Building; offer: Offer | null }
| { kind: 'build'; key: string; type: BuildingType; name: string; option: BuildOption }
const rows = computed<Row[]>(() => {
const out: Row[] = []
for (const o of props.options) {
if (o.blocked === 'requires') continue
const instances = byType.value.get(o.type) ?? []
const numbered = instances.length > 1 || (instances.length > 0 && o.blocked !== 'max_per_village')
instances.forEach((b, i) => {
out.push({
kind: 'upgrade',
key: `b${b.id}`,
type: b.type,
name: numbered ? t('village.build.nth', { name: t(`buildings.${b.type}`), n: i + 1 }) : t(`buildings.${b.type}`),
building: b,
offer: b.upgrade,
})
})
// A unique type that already stands has nothing more to build.
if (o.blocked === 'max_per_village' && instances.length) continue
out.push({
kind: 'build',
key: `new-${o.type}`,
type: o.type,
name: instances.length ? t('village.build.nth', { name: t(`buildings.${o.type}`), n: instances.length + 1 }) : t(`buildings.${o.type}`),
option: o,
})
}
return out
})
const locked = computed(() => props.options.filter((o) => o.blocked === 'requires'))
/** Why a row can't be built now, or '' when its button shows. */
function reason(offer: Offer | null) {
if (!offer) return t('village.blocked.max_level')
if (offer.blocked) return t(`village.blocked.${offer.blocked}`)
if (!props.canAfford(offer.cost)) return t('village.blocked.resources')
return ''
}
const demolishable = computed(() =>
props.buildings.map((b) => ({
b,
name: (byType.value.get(b.type)?.length ?? 0) > 1
? t('village.build.nth', { name: t(`buildings.${b.type}`), n: byType.value.get(b.type)!.indexOf(b) + 1 })
: t(`buildings.${b.type}`),
})),
)
</script>
<template>
<section class="panel overflow-hidden">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.build.title') }}</h2>
<div class="flex items-center gap-1" role="tablist">
<button
v-for="name in ['construct', 'demolish'] as const"
:key="name"
type="button"
role="tab"
:aria-selected="tab === name"
class="rounded-sm border px-3 py-1 font-display text-base font-semibold"
:class="tab === name ? 'border-wood-700 bg-parchment-50 text-wood-900' : 'border-transparent text-ink-500 hover:text-wood-900'"
style="font-variant: small-caps"
@click="tab = name"
>
{{ $t(`village.build.tab_${name}`) }}
</button>
</div>
<span class="badge badge-plain">
{{ $t('village.build.free_space', { free: space.max - space.used }) }}
</span>
</div>
<div class="overflow-x-auto">
<table class="w-full min-w-[34rem] border-collapse text-sm">
<div v-if="tab === 'construct'" class="overflow-x-auto">
<table class="w-full min-w-[36rem] border-collapse text-sm">
<thead>
<tr class="border-b-2 border-wood-700 bg-parchment-100 text-left text-xs font-semibold text-ink-700">
<th class="px-3 py-1.5">{{ $t('village.build.building') }}</th>
@ -51,41 +116,66 @@ function status(o: BuildOption) {
</tr>
</thead>
<tbody>
<tr
v-for="o in available"
:key="o.type"
class="border-b border-parchment-300 last:border-b-0 even:bg-parchment-100"
:class="o.blocked ? 'text-ink-500' : ''"
>
<td class="px-3 py-1.5">
<tr v-for="row in rows" :key="row.key" class="border-b border-parchment-300 last:border-b-0 even:bg-parchment-100">
<td class="px-3 py-1">
<div class="flex items-center gap-2">
<IconBuildingTile :type="o.type" class="size-7" />
<IconBuildingTile :type="row.type" class="size-7" :class="row.kind === 'build' ? 'opacity-70' : ''" />
<div class="min-w-0 leading-tight">
<p class="truncate font-semibold">{{ $t(`buildings.${o.type}`) }}</p>
<p v-if="built[o.type]" class="text-xs text-ink-500">{{ $t('village.build.built', { count: built[o.type] }) }}</p>
<button
v-if="row.kind === 'upgrade'"
type="button"
class="block max-w-full truncate text-left font-semibold hover:text-blood-700 hover:underline"
:title="$t('village.buildings.show')"
@click="emit('select', row.building.id)"
>
{{ row.name }}
</button>
<p v-else class="truncate font-semibold">{{ row.name }}</p>
<p class="text-xs text-ink-500">
{{ row.kind === 'upgrade' ? $t('village.buildings.level_n', { level: row.building.level }) : $t('village.build.not_built') }}
</p>
</div>
</div>
</td>
<td class="px-2 py-1.5"><UiCost :cost="o.cost" :have="resources" /></td>
<td class="px-2 py-1.5 text-right tabular-nums">{{ o.space || '–' }}</td>
<td class="px-2 py-1.5 text-right tabular-nums whitespace-nowrap">{{ formatDuration(o.seconds) }}</td>
<td class="px-3 py-1.5 text-right">
<template v-if="row.kind === 'upgrade'">
<td class="px-2 py-1"><UiCost v-if="row.offer" :cost="row.offer.cost" :have="resources" nowrap /></td>
<td class="px-2 py-1 text-right text-ink-400">–</td>
<td class="px-2 py-1 text-right tabular-nums whitespace-nowrap">{{ row.offer ? formatDuration(row.offer.seconds) : '' }}</td>
<td class="px-3 py-1 text-right">
<button
v-if="!status(o)"
v-if="!reason(row.offer)"
type="button"
class="btn btn-primary px-2.5 py-1"
class="btn btn-primary min-w-[5.5rem] px-2.5 py-1"
:disabled="busy"
@click="emit('build', o.type)"
@click="emit('upgrade', row.building.id)"
>
<IconUi name="up" class="size-3.5" />
{{ $t('village.build.level_button', { level: row.offer!.target_level }) }}
</button>
<span v-else class="text-xs font-semibold text-blood-700">{{ reason(row.offer) }}</span>
</td>
</template>
<template v-else>
<td class="px-2 py-1"><UiCost :cost="row.option.cost" :have="resources" nowrap /></td>
<td class="px-2 py-1 text-right tabular-nums">{{ row.option.space || '–' }}</td>
<td class="px-2 py-1 text-right tabular-nums whitespace-nowrap">{{ formatDuration(row.option.seconds) }}</td>
<td class="px-3 py-1 text-right">
<button
v-if="!reason(row.option)"
type="button"
class="btn btn-outline min-w-[5.5rem] border-blood-700 px-2.5 py-1 text-blood-700"
:disabled="busy"
@click="emit('build', row.type)"
>
<IconUi name="hammer" class="size-3.5" />
{{ $t('village.build.submit') }}
</button>
<span v-else class="text-xs font-semibold text-blood-700">{{ status(o) }}</span>
<span v-else class="text-xs font-semibold text-blood-700">{{ reason(row.option) }}</span>
</td>
</template>
</tr>
</tbody>
</table>
</div>
<template v-if="locked.length">
<h3 class="border-y-2 border-wood-700 bg-parchment-200 px-3 py-1.5 font-display text-sm font-semibold text-wood-900" style="font-variant: small-caps">
@ -94,13 +184,13 @@ function status(o: BuildOption) {
<table class="w-full border-collapse text-sm">
<tbody>
<tr v-for="o in locked" :key="o.type" class="border-b border-parchment-300 text-ink-500 last:border-b-0">
<td class="w-1/3 px-3 py-1.5">
<td class="w-1/3 px-3 py-1">
<div class="flex items-center gap-2 opacity-70">
<IconBuildingTile :type="o.type" class="size-7" />
<span class="font-semibold">{{ $t(`buildings.${o.type}`) }}</span>
</div>
</td>
<td class="px-2 py-1.5">
<td class="px-2 py-1">
<span class="mr-2 text-xs">{{ $t('village.build.requires') }}</span>
<span v-for="r in o.requires" :key="r.type" class="mr-3 inline-flex items-center gap-1 whitespace-nowrap">
<IconBuildingTile :type="r.type" class="size-5" />
@ -111,5 +201,50 @@ function status(o: BuildOption) {
</tbody>
</table>
</template>
</div>
<div v-else class="overflow-x-auto">
<table class="w-full min-w-[34rem] border-collapse text-sm">
<thead>
<tr class="border-b-2 border-wood-700 bg-parchment-100 text-left text-xs font-semibold text-ink-700">
<th class="px-3 py-1.5">{{ $t('village.build.building') }}</th>
<th class="px-2 py-1.5">{{ $t('village.build.refund') }}</th>
<th class="px-2 py-1.5 text-right">{{ $t('village.build.time') }}</th>
<th class="px-3 py-1.5 text-right">{{ $t('village.build.tab_demolish') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="{ b, name } in demolishable" :key="b.id" class="border-b border-parchment-300 last:border-b-0 even:bg-parchment-100">
<td class="px-3 py-1">
<div class="flex items-center gap-2">
<IconBuildingTile :type="b.type" class="size-7" />
<div class="min-w-0 leading-tight">
<p class="truncate font-semibold">{{ name }}</p>
<p class="text-xs text-ink-500">{{ $t('village.buildings.level_n', { level: b.level }) }}</p>
</div>
</div>
</td>
<td class="px-2 py-1"><UiCost v-if="b.demolish" :cost="b.demolish.refund" nowrap /></td>
<td class="px-2 py-1 text-right tabular-nums whitespace-nowrap">{{ b.demolish ? formatDuration(b.demolish.seconds) : '' }}</td>
<td class="px-3 py-1 text-right">
<button
v-if="b.demolish"
type="button"
class="btn btn-outline min-w-[5.5rem] border-blood-700 px-2.5 py-1 text-blood-700"
:disabled="busy"
@click="emit('demolish', b.id)"
>
{{
b.demolish.target_level < 0
? $t('village.build.remove')
: $t('village.build.level_button', { level: b.demolish.target_level })
}}
</button>
<span v-else class="text-xs font-semibold text-ink-500">{{ $t('village.build.core') }}</span>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</template>

View File

@ -1,71 +1,80 @@
<script setup lang="ts">
import type { Building, Cost, Resources } from '~/types/game'
import type { Building, BuildingType } from '~/types/game'
defineProps<{
const props = defineProps<{
buildings: Building[]
resources: Resources
canAfford: (cost: Cost) => boolean
busy: boolean
}>()
const emit = defineEmits<{
select: [buildingId: number]
upgrade: [buildingId: number]
demolish: [buildingId: number]
priority: [buildingId: number, priority: number]
}>()
const { t } = useI18n()
const demolishTitle = (b: Building) =>
b.demolish ? `${t('village.buildings.refund')} ${formatCost(b.demolish.refund)}, ${formatDuration(b.demolish.seconds)}` : ''
// Who works where: building and upgrading live in the construction table above.
const named = computed(() => {
const seen = new Map<BuildingType, number>()
const totals = new Map<BuildingType, number>()
for (const b of props.buildings) totals.set(b.type, (totals.get(b.type) ?? 0) + 1)
return props.buildings.map((b) => {
const n = (seen.get(b.type) ?? 0) + 1
seen.set(b.type, n)
return {
b,
name: (totals.get(b.type) ?? 0) > 1 ? t('village.build.nth', { name: t(`buildings.${b.type}`), n }) : t(`buildings.${b.type}`),
}
})
})
</script>
<template>
<section class="panel">
<section class="panel overflow-hidden">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.buildings.title') }}</h2>
<span class="badge badge-plain">{{ 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">
<div class="overflow-x-auto">
<table class="w-full min-w-[34rem] border-collapse text-sm">
<thead>
<tr class="border-b-2 border-wood-700 bg-parchment-100 text-left text-xs font-semibold text-ink-700">
<th class="px-3 py-1.5">{{ $t('village.buildings.type') }}</th>
<th class="px-2 py-1.5 text-right">{{ $t('village.buildings.level') }}</th>
<th class="w-40 px-2 py-1.5">{{ $t('village.buildings.workers') }}</th>
<th class="px-2 py-1.5">{{ $t('village.buildings.output') }}</th>
<th class="px-3 py-1.5 text-right">{{ $t('village.buildings.priority') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="{ b, name } in named" :key="b.id" class="border-b border-parchment-300 last:border-b-0 even:bg-parchment-100">
<td class="px-3 py-1">
<div class="flex items-center gap-2">
<IconBuildingTile :type="b.type" class="size-7" />
<button
type="button"
class="block max-w-full truncate text-left font-medium hover:text-blood-700 hover:underline"
class="truncate text-left font-semibold hover:text-blood-700 hover:underline"
:title="$t('village.buildings.show')"
@click="emit('select', b.id)"
>
{{ $t(`buildings.${b.type}`) }}
{{ name }}
</button>
<p class="text-xs text-ink-500">
{{ $t('village.buildings.level_n', { level: b.level }) }}
<template v-if="b.space"> · {{ $t('village.build.space', { space: b.space }) }}</template>
</p>
</div>
</td>
<td class="px-2 py-1 text-right font-semibold tabular-nums">{{ b.level }}</td>
<td class="px-2 py-1">
<div class="flex items-center gap-2">
<span class="w-12 shrink-0 text-xs tabular-nums">{{ b.workers.assigned }}/{{ b.workers.required }}</span>
<UiBar :value="b.staffing" :tone="b.staffing < 1 ? 'rose' : 'emerald'" />
</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">
</td>
<td class="px-2 py-1">
<span v-if="b.production" class="flex items-center gap-1 tabular-nums whitespace-nowrap">
<IconResource :resource="b.production.resource" class="size-4" />
{{ $t('village.resources.per_hour', { rate: formatRate(b.production.per_hour) }) }}
</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-sm border border-wood-600 bg-parchment-50">
</span>
<span v-else class="text-ink-400">–</span>
</td>
<td class="px-3 py-1 text-right">
<div class="inline-flex items-center rounded-sm border border-wood-600 bg-parchment-50">
<button
type="button"
class="btn btn-ghost rounded-r-none p-1"
@ -86,40 +95,10 @@ const demolishTitle = (b: Building) =>
<IconUi name="plus" class="size-3.5" />
</button>
</div>
</td>
</tr>
</tbody>
</table>
</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 }) }}
</button>
<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>
</div>
</li>
</ul>
</section>
</template>

View File

@ -96,6 +96,9 @@ function showInVillage(id: number) {
:can-afford="v.canAfford"
:busy="busy"
@build="v.build"
@upgrade="v.upgrade"
@demolish="v.demolish"
@select="showInVillage"
/>
<div class="space-y-6">
<VillageBuildQueue
@ -109,16 +112,7 @@ function showInVillage(id: number) {
</div>
</div>
<VillageBuildingTable
:buildings="village.buildings"
:resources="resources"
:can-afford="v.canAfford"
:busy="busy"
@select="showInVillage"
@upgrade="v.upgrade"
@demolish="v.demolish"
@priority="v.setPriority"
/>
<VillageBuildingTable :buildings="village.buildings" :busy="busy" @select="showInVillage" @priority="v.setPriority" />
</div>
</div>
<div v-else class="px-4 py-16 text-center">

View File

@ -93,7 +93,7 @@ export interface Building {
/** Next level after everything already queued; null at max level. */
upgrade: Offer | null
/** null when the building cannot go lower (core buildings at level 0). */
demolish: { refund: Cost; seconds: number } | null
demolish: { target_level: number; refund: Cost; seconds: number } | null
}
/** Whether it is affordable is left to the client, which compares the cost to projected resources. */

View File

@ -23,14 +23,12 @@ export default {
food_per_hour: '{value} food/h',
},
buildings: {
title: 'Buildings',
title: 'Workforce',
type: 'Building',
level: 'Level',
workers: 'Workers',
staffing: 'Staffing',
output: 'Output',
priority: 'Priority',
actions: 'Actions',
level_n: 'Level {level}',
priority_down: 'Lower priority',
priority_up: 'Raise priority',
@ -48,13 +46,19 @@ export default {
space_value: '{used} / {max}',
},
build: {
title: 'Construct',
tab_construct: 'Construct',
tab_demolish: 'Demolition',
nth: '{name} {n}',
not_built: 'Not built yet',
level_button: 'Level {level}',
refund: 'Refund',
remove: 'Remove',
core: 'Stays',
building: 'Building',
cost: 'Cost',
space_col: 'Space',
time: 'Duration',
construct: 'Build',
built: '{count} built',
not_available: 'Not yet available',
requires: 'Requires',
requirement: '{type} (level {level})',