2026-10-28 16:57:44 +00:00
|
|
|
|
<script setup lang="ts">
|
2026-10-28 20:18:57 +00:00
|
|
|
|
import type { BuildOption, Building, BuildingType, Cost, Offer, 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 20:18:57 +00:00
|
|
|
|
const emit = defineEmits<{
|
|
|
|
|
|
build: [type: BuildingType]
|
|
|
|
|
|
upgrade: [buildingId: number]
|
|
|
|
|
|
demolish: [buildingId: number]
|
|
|
|
|
|
select: [buildingId: number]
|
|
|
|
|
|
}>()
|
2026-10-28 16:57:44 +00:00
|
|
|
|
const { t } = useI18n()
|
|
|
|
|
|
|
2026-10-28 20:18:57 +00:00
|
|
|
|
// 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 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
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
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 }
|
2026-10-28 20:01:23 +00:00
|
|
|
|
|
2026-10-28 20:18:57 +00:00
|
|
|
|
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
|
2026-10-28 20:01:23 +00:00
|
|
|
|
})
|
|
|
|
|
|
|
2026-10-28 20:18:57 +00:00
|
|
|
|
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')
|
2026-10-28 16:57:44 +00:00
|
|
|
|
return ''
|
|
|
|
|
|
}
|
2026-10-28 20:18:57 +00:00
|
|
|
|
|
|
|
|
|
|
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}`),
|
|
|
|
|
|
})),
|
|
|
|
|
|
)
|
2026-10-28 16:57:44 +00:00
|
|
|
|
</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">
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<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>
|
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
|
|
|
|
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<div v-if="tab === 'construct'" class="overflow-x-auto">
|
|
|
|
|
|
<table class="w-full min-w-[36rem] border-collapse text-sm">
|
2026-10-28 20:01:23 +00:00
|
|
|
|
<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>
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<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">
|
2026-10-28 20:01:23 +00:00
|
|
|
|
<div class="flex items-center gap-2">
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<IconBuildingTile :type="row.type" class="size-7" :class="row.kind === 'build' ? 'opacity-70' : ''" />
|
2026-10-28 20:01:23 +00:00
|
|
|
|
<div class="min-w-0 leading-tight">
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<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>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<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="!reason(row.offer)"
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
class="btn btn-primary min-w-[5.5rem] px-2.5 py-1"
|
|
|
|
|
|
:disabled="busy"
|
|
|
|
|
|
@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">{{ reason(row.option) }}</span>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</template>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
2026-10-28 20:18:57 +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">
|
|
|
|
|
|
<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">
|
|
|
|
|
|
<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 18:04:21 +00:00
|
|
|
|
</div>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<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>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
<tbody>
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<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>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</td>
|
2026-10-28 20:18:57 +00:00
|
|
|
|
<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>
|
2026-10-28 20:01:23 +00:00
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
2026-10-28 20:18:57 +00:00
|
|
|
|
</div>
|
2026-10-28 16:57:44 +00:00
|
|
|
|
</section>
|
|
|
|
|
|
</template>
|