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

84 lines
3.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script setup lang="ts">
import type { BuildOption, BuildingType, Cost, Resources } from '~/types/game'
const props = defineProps<{
options: BuildOption[]
selected: { x: number; y: number } | null
resources: Resources
canAfford: (cost: Cost) => boolean
busy: boolean
}>()
const emit = defineEmits<{ build: [type: BuildingType]; clear: [] }>()
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 class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.build.title') }}</h2>
<div class="flex items-center gap-1.5 text-sm">
<span class="text-ink-500">{{ $t('village.build.position') }}</span>
<template v-if="selected">
<span class="badge bg-amber-100 text-amber-800">
<IconUi name="pin" class="size-3.5" />
{{ selected.x }}|{{ selected.y }}
</span>
<button
type="button"
class="btn btn-ghost p-1"
:title="$t('common.clear')"
:aria-label="$t('common.clear')"
@click="emit('clear')"
>
<IconUi name="close" class="size-3.5" />
</button>
</template>
<span v-else class="badge bg-parchment-200 text-ink-700">{{ $t('village.build.auto') }}</span>
</div>
</div>
<div class="panel-body grid gap-3 sm:grid-cols-2 xl:grid-cols-3">
<article
v-for="o in options"
:key="o.type"
class="flex flex-col gap-2.5 rounded-lg bg-parchment-50 p-3 ring-1 ring-parchment-200"
:class="o.blocked ? 'opacity-60' : ''"
>
<div class="flex items-center gap-2.5">
<IconBuildingTile :type="o.type" class="size-10" />
<div class="min-w-0">
<h3 class="truncate font-medium">{{ $t(`buildings.${o.type}`) }}</h3>
<p class="flex flex-wrap items-center gap-x-1.5 text-xs text-ink-500">
<span class="whitespace-nowrap">
{{ o.footprint[0] ? `${o.footprint[0]}×${o.footprint[1]}` : $t('village.build.surrounds') }}
</span>
<span class="flex items-center gap-1 whitespace-nowrap tabular-nums">
<IconUi name="clock" class="size-3" />
{{ formatDuration(o.seconds) }}
</span>
</p>
</div>
</div>
<UiCost :cost="o.cost" :have="resources" />
<div class="mt-auto flex items-center justify-between gap-2">
<span class="text-xs text-rose-700">{{ status(o) }}</span>
<button
type="button"
class="btn btn-primary"
:disabled="busy || !!o.blocked || !canAfford(o.cost)"
@click="emit('build', o.type)"
>
<IconUi name="hammer" class="size-3.5" />
{{ $t('village.build.submit') }}
</button>
</div>
</article>
</div>
</section>
</template>