2026-10-28 16:57:44 +00:00
|
|
|
|
<script setup lang="ts">
|
2026-10-28 20:01:23 +00:00
|
|
|
|
import type { BuildOption, Building, BuildingType, Cost, Resources } from '~/types/game'
|
2026-10-28 16:57:44 +00:00
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
|
options: BuildOption[]
|
2026-10-28 20:01:23 +00:00
|
|
|
|
buildings: Building[]
|
2026-10-28 18:54:29 +00:00
|
|
|
|
space: { used: number; max: number }
|
2026-10-28 18:04:21 +00:00
|
|
|
|
resources: Resources
|
2026-10-28 16:57:44 +00:00
|
|
|
|
canAfford: (cost: Cost) => boolean
|
|
|
|
|
|
busy: boolean
|
|
|
|
|
|
}>()
|
2026-10-28 18:54:29 +00:00
|
|
|
|
const emit = defineEmits<{ build: [type: BuildingType] }>()
|
2026-10-28 16:57:44 +00:00
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
2026-10-28 20:01:23 +00:00
|
|
|
|
// 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
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-10-28 16:57:44 +00:00
|
|
|
|
function status(o: BuildOption) {
|
|
|
|
|
|
if (o.blocked) return t(`village.blocked.${o.blocked}`)
|
|
|
|
|
|
if (!props.canAfford(o.cost)) return t('village.blocked.resources')
|
|
|
|
|
|
return ''
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
<section class="panel overflow-hidden">
|
2026-10-28 18:04:21 +00:00
|
|
|
|
<div class="panel-head">
|
|
|
|
|
|
<h2 class="panel-title">{{ $t('village.build.title') }}</h2>
|
2026-10-28 19:22:53 +00:00
|
|
|
|
<span class="badge badge-plain">
|
2026-10-28 18:54:29 +00:00
|
|
|
|
{{ $t('village.build.free_space', { free: space.max - space.used }) }}
|
|
|
|
|
|
</span>
|
2026-10-28 18:04:21 +00:00
|
|
|
|
</div>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
<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.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"
|
|
|
|
|
|
class="border-b border-parchment-300 last:border-b-0 even:bg-parchment-100"
|
|
|
|
|
|
:class="o.blocked ? 'text-ink-500' : ''"
|
2026-10-28 18:04:21 +00:00
|
|
|
|
>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
<td class="px-3 py-1.5">
|
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
|
<IconBuildingTile :type="o.type" class="size-7" />
|
|
|
|
|
|
<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>
|
|
|
|
|
|
</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">
|
|
|
|
|
|
<button
|
|
|
|
|
|
v-if="!status(o)"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
class="btn btn-primary px-2.5 py-1"
|
|
|
|
|
|
:disabled="busy"
|
|
|
|
|
|
@click="emit('build', o.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>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
2026-10-28 18:04:21 +00:00
|
|
|
|
</div>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
</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>
|
2026-10-28 16:57:44 +00:00
|
|
|
|
</section>
|
|
|
|
|
|
</template>
|