72 lines
3.4 KiB
Vue
72 lines
3.4 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">
|
|
<VillagePortraitTile :type="option.type" :level="1" class="size-14" />
|
|
<div class="min-w-0 flex-1">
|
|
<h2 class="truncate font-display text-base font-bold text-wood-950">{{ $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>
|
|
<!-- A copy works at a share of the first and costs more: say so before the cost. -->
|
|
<p v-if="isCopy(option.instance_share)" class="border border-gold-600 bg-gold-400 px-2 py-0.5 text-xs text-ink-900">
|
|
{{ $t('village.copy.offer', { share: sharePercent(option.instance_share) }) }}
|
|
</p>
|
|
<div v-if="!option.requires.length" 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="btn btn-outline w-full">{{ $t('village.plot.all') }}</NuxtLink>
|
|
</div>
|
|
</section>
|
|
</template>
|