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

68 lines
3.1 KiB
Vue

<script setup lang="ts">
import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game'
const props = defineProps<{
option: BuildOption
resources: Resources
canAfford: (cost: Cost) => boolean
busy: boolean
/** One of this type already stands; this plot is for another. */
another: boolean
/** The headquarters screen with every building. */
allLink: string
}>()
const emit = defineEmits<{ build: [type: BuildingType]; close: [] }>()
const { t } = useI18n()
/** Why it can't be built now, or '' when the button shows. */
const reason = computed(() => {
if (props.option.blocked) return t(`village.blocked.${props.option.blocked}`)
if (!props.canAfford(props.option.cost)) return t('village.blocked.resources')
return ''
})
</script>
<!-- An empty plot picked in the village: what would stand there, and building it. -->
<template>
<section class="panel" :aria-label="$t(`buildings.${option.type}`)">
<div class="flex items-center gap-3 border-b-2 border-wood-700 bg-parchment-200 px-4 py-3">
<IconBuildingTile :type="option.type" class="size-11 opacity-70" />
<div class="min-w-0 flex-1">
<h2 class="truncate font-display text-lg font-semibold text-wood-900" style="font-variant: small-caps">{{ $t(`buildings.${option.type}`) }}</h2>
<p class="text-xs text-ink-500">
{{ another ? $t('village.plot.another') : $t('village.build.not_built') }}
<template v-if="option.space"> · {{ $t('village.build.space', { space: option.space }) }}</template>
</p>
</div>
<button type="button" class="btn btn-ghost p-1.5" :aria-label="$t('common.close')" :title="$t('common.close')" @click="emit('close')">
<IconUi name="close" class="size-4" />
</button>
</div>
<div class="space-y-3 px-4 py-3">
<div v-if="option.requires.length" class="space-y-1 text-sm">
<p class="text-xs text-ink-500">{{ $t('village.build.requires') }}</p>
<p v-for="r in option.requires" :key="r.type" class="flex items-center gap-1.5">
<IconBuildingTile :type="r.type" class="size-5" />
{{ $t('village.build.requirement', { type: $t(`buildings.${r.type}`), level: r.level }) }}
</p>
</div>
<div v-else class="space-y-1.5 rounded-sm border border-wood-600/50 bg-parchment-100 p-3">
<div class="flex items-center justify-between gap-2 text-xs text-ink-500">
<UiCost :cost="option.cost" :have="resources" />
<span class="flex items-center gap-1 tabular-nums">
<IconUi name="clock" class="size-3" />
{{ formatDuration(option.seconds) }}
</span>
</div>
<button v-if="!reason" type="button" class="btn btn-primary w-full" :disabled="busy" @click="emit('build', option.type)">
<IconUi name="hammer" class="size-3.5" />
{{ $t('village.build.submit') }}
</button>
<p v-else class="text-center text-xs font-semibold text-blood-700">{{ reason }}</p>
</div>
<NuxtLink :to="allLink" class="block text-sm font-semibold text-blood-700 hover:underline">» {{ $t('village.plot.all') }}</NuxtLink>
</div>
</section>
</template>