116 lines
4.8 KiB
Vue
116 lines
4.8 KiB
Vue
<script setup lang="ts">
|
||
import type { BuildOption, Building, BuildingType, Cost, Resources } from '~/types/game'
|
||
|
||
const props = defineProps<{
|
||
options: BuildOption[]
|
||
buildings: Building[]
|
||
space: { used: number; max: number }
|
||
resources: Resources
|
||
canAfford: (cost: Cost) => boolean
|
||
busy: boolean
|
||
}>()
|
||
const emit = defineEmits<{ build: [type: BuildingType] }>()
|
||
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) {
|
||
if (o.blocked) return t(`village.blocked.${o.blocked}`)
|
||
if (!props.canAfford(o.cost)) return t('village.blocked.resources')
|
||
return ''
|
||
}
|
||
</script>
|
||
|
||
<template>
|
||
<section class="panel overflow-hidden">
|
||
<div class="panel-head">
|
||
<h2 class="panel-title">{{ $t('village.build.title') }}</h2>
|
||
<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">
|
||
<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' : ''"
|
||
>
|
||
<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>
|
||
</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">
|
||
{{ $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>
|
||
</section>
|
||
</template>
|