feat: dense TW-style construct table with a not-yet-available list

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-28 21:01:23 +01:00
parent b7b3c173d1
commit 1db4eb28a9
5 changed files with 99 additions and 40 deletions

View File

@ -1,8 +1,9 @@
<script setup lang="ts"> <script setup lang="ts">
import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game' import type { BuildOption, Building, BuildingType, Cost, Resources } from '~/types/game'
const props = defineProps<{ const props = defineProps<{
options: BuildOption[] options: BuildOption[]
buildings: Building[]
space: { used: number; max: number } space: { used: number; max: number }
resources: Resources resources: Resources
canAfford: (cost: Cost) => boolean canAfford: (cost: Cost) => boolean
@ -11,6 +12,17 @@ const props = defineProps<{
const emit = defineEmits<{ build: [type: BuildingType] }>() const emit = defineEmits<{ build: [type: BuildingType] }>()
const { t } = useI18n() 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'))
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
})
function status(o: BuildOption) { function status(o: BuildOption) {
if (o.blocked) return t(`village.blocked.${o.blocked}`) if (o.blocked) return t(`village.blocked.${o.blocked}`)
if (!props.canAfford(o.cost)) return t('village.blocked.resources') if (!props.canAfford(o.cost)) return t('village.blocked.resources')
@ -19,49 +31,85 @@ function status(o: BuildOption) {
</script> </script>
<template> <template>
<section class="panel"> <section class="panel overflow-hidden">
<div class="panel-head"> <div class="panel-head">
<h2 class="panel-title">{{ $t('village.build.title') }}</h2> <h2 class="panel-title">{{ $t('village.build.title') }}</h2>
<span class="badge badge-plain"> <span class="badge badge-plain">
{{ $t('village.build.free_space', { free: space.max - space.used }) }} {{ $t('village.build.free_space', { free: space.max - space.used }) }}
</span> </span>
</div> </div>
<div class="panel-body grid gap-3 sm:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4">
<article <div class="overflow-x-auto">
v-for="o in options" <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.cost') }}</th>
<th class="px-2 py-1.5 text-right">{{ $t('village.build.space_col') }}</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.construct') }}</th>
</tr>
</thead>
<tbody>
<tr
v-for="o in available"
:key="o.type" :key="o.type"
class="flex flex-col gap-2.5 rounded-sm border-2 border-parchment-300 bg-parchment-100 p-3" class="border-b border-parchment-300 last:border-b-0 even:bg-parchment-100"
:class="o.blocked ? 'opacity-60' : ''" :class="o.blocked ? 'text-ink-500' : ''"
> >
<div class="flex items-center gap-2.5"> <td class="px-3 py-1.5">
<IconBuildingTile :type="o.type" class="size-10" /> <div class="flex items-center gap-2">
<div class="min-w-0"> <IconBuildingTile :type="o.type" class="size-7" />
<h3 class="truncate font-medium">{{ $t(`buildings.${o.type}`) }}</h3> <div class="min-w-0 leading-tight">
<p class="flex flex-wrap items-center gap-x-1.5 text-xs text-ink-500"> <p class="truncate font-semibold">{{ $t(`buildings.${o.type}`) }}</p>
<span class="whitespace-nowrap"> <p v-if="built[o.type]" class="text-xs text-ink-500">{{ $t('village.build.built', { count: built[o.type] }) }}</p>
{{ o.space ? $t('village.build.space', { space: o.space }) : $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>
</div> </div>
</div> </div>
<UiCost :cost="o.cost" :have="resources" /> </td>
<div class="mt-auto flex items-center justify-between gap-2"> <td class="px-2 py-1.5"><UiCost :cost="o.cost" :have="resources" /></td>
<span class="text-xs font-semibold text-blood-700">{{ status(o) }}</span> <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">
<button <button
v-if="!status(o)"
type="button" type="button"
class="btn btn-primary" class="btn btn-primary px-2.5 py-1"
:disabled="busy || !!o.blocked || !canAfford(o.cost)" :disabled="busy"
@click="emit('build', o.type)" @click="emit('build', o.type)"
> >
<IconUi name="hammer" class="size-3.5" /> <IconUi name="hammer" class="size-3.5" />
{{ $t('village.build.submit') }} {{ $t('village.build.submit') }}
</button> </button>
<span v-else class="text-xs font-semibold text-blood-700">{{ status(o) }}</span>
</td>
</tr>
</tbody>
</table>
</div> </div>
</article>
<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">
{{ $t('village.build.not_available') }}
</h3>
<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">
<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> </div>
</td>
<td class="px-2 py-1.5">
<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" />
{{ $t('village.build.requirement', { type: $t(`buildings.${r.type}`), level: r.level }) }}
</span>
</td>
</tr>
</tbody>
</table>
</template>
</section> </section>
</template> </template>

View File

@ -261,7 +261,7 @@ function buildOptions(v: MockVillage): BuildOption[] {
: !spaceFits(v, type) : !spaceFits(v, type)
? 'no_space' ? 'no_space'
: null : null
return { type, space: entry.space, target_level: 0, cost, seconds: levelSeconds(type, 0), blocked } return { type, space: entry.space, target_level: 0, cost, seconds: levelSeconds(type, 0), blocked, requires: [] }
}) })
} }

View File

@ -90,6 +90,7 @@ function showInVillage(id: number) {
<div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]"> <div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]">
<VillageBuildForm <VillageBuildForm
:options="village.buildable" :options="village.buildable"
:buildings="village.buildings"
:space="village.space" :space="village.space"
:resources="resources" :resources="resources"
:can-afford="v.canAfford" :can-afford="v.canAfford"

View File

@ -107,6 +107,8 @@ export interface Offer {
export interface BuildOption extends Offer { export interface BuildOption extends Offer {
type: BuildingType type: BuildingType
space: number space: number
/** Requirements no building meets yet; only advanced buildings have any. */
requires: { type: BuildingType; level: number }[]
} }
export interface BuildOrder { export interface BuildOrder {

View File

@ -48,10 +48,18 @@ export default {
space_value: '{used} / {max}', space_value: '{used} / {max}',
}, },
build: { build: {
title: 'New building', title: 'Construct',
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})',
space: 'Space {space}', space: 'Space {space}',
free_space: '{free} space free', free_space: '{free} space free',
surrounds: 'Around the village',
submit: 'Build', submit: 'Build',
}, },
queue: { queue: {