game-village-politics-frontend/app/components/village/BuildForm.vue

56 lines
1.8 KiB
Vue
Raw Normal View History

<script setup lang="ts">
import type { BuildOption, BuildingType, Cost } from '~/types/game'
const props = defineProps<{
options: BuildOption[]
selected: { x: number; y: number } | null
canAfford: (cost: Cost) => boolean
busy: boolean
}>()
const emit = defineEmits<{ build: [type: BuildingType] }>()
const { t } = useI18n()
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>
<h2>{{ $t('village.build.title') }}</h2>
<p>
{{ $t('village.build.position') }}:
<template v-if="selected">{{ $t('village.build.at_cell') }} ({{ selected.x }}|{{ selected.y }})</template>
<template v-else>{{ $t('village.build.auto') }}</template>
</p>
<table>
<thead>
<tr>
<th>{{ $t('village.build.type') }}</th>
<th>{{ $t('village.build.size') }}</th>
<th>{{ $t('village.build.cost') }} ({{ $t('resources.wood') }} / {{ $t('resources.clay') }} / {{ $t('resources.iron') }})</th>
<th>{{ $t('village.build.time') }}</th>
<th>{{ $t('village.build.status') }}</th>
<th />
</tr>
</thead>
<tbody>
<tr v-for="o in options" :key="o.type">
<td>{{ $t(`buildings.${o.type}`) }}</td>
<td>{{ o.footprint[0] }}×{{ o.footprint[1] }}</td>
<td>{{ formatCost(o.cost) }}</td>
<td>{{ formatDuration(o.seconds) }}</td>
<td>{{ status(o) }}</td>
<td>
<button type="button" :disabled="busy || !!o.blocked || !canAfford(o.cost)" @click="emit('build', o.type)">
{{ $t('village.build.submit') }}
</button>
</td>
</tr>
</tbody>
</table>
</section>
</template>