114 lines
5.0 KiB
Vue
114 lines
5.0 KiB
Vue
<script setup lang="ts">
|
||
import type { RouteLocationRaw } from 'vue-router'
|
||
import type { Building, Cost, Resources } from '~/types/game'
|
||
|
||
defineProps<{
|
||
building: Building
|
||
resources: Resources
|
||
canAfford: (cost: Cost) => boolean
|
||
busy: boolean
|
||
/** The building's own screen, e.g. construction for the headquarters, recruiting for a barracks. */
|
||
link?: { to: RouteLocationRaw; label: string } | null
|
||
}>()
|
||
const emit = defineEmits<{
|
||
upgrade: [buildingId: number]
|
||
demolish: [buildingId: number]
|
||
priority: [buildingId: number, priority: number]
|
||
close: []
|
||
}>()
|
||
</script>
|
||
|
||
<!-- Details of the building selected in the diorama, with its actions. -->
|
||
<template>
|
||
<section class="panel" :aria-label="$t(`buildings.${building.type}`)">
|
||
<div class="flex items-center gap-3 border-b-2 border-wood-700 bg-parchment-200 px-4 py-3">
|
||
<IconBuildingTile :type="building.type" class="size-11" />
|
||
<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.${building.type}`) }}</h2>
|
||
<p class="text-xs text-ink-500">
|
||
{{ $t('village.buildings.level_n', { level: building.level }) }}
|
||
<template v-if="building.space"> · {{ $t('village.build.space', { space: building.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-4 px-4 py-3">
|
||
<div class="grid grid-cols-2 gap-3 text-sm">
|
||
<div>
|
||
<p class="text-xs text-ink-500">{{ $t('village.buildings.workers') }}</p>
|
||
<p class="tabular-nums">{{ building.workers.assigned }}/{{ building.workers.required }}</p>
|
||
<UiBar class="mt-1" :value="building.staffing" :tone="building.staffing < 1 ? 'rose' : 'emerald'" />
|
||
</div>
|
||
<div>
|
||
<p class="text-xs text-ink-500">{{ $t('village.buildings.output') }}</p>
|
||
<p v-if="building.production" class="flex items-center gap-1 tabular-nums">
|
||
<IconResource :resource="building.production.resource" class="size-4" />
|
||
{{ $t('village.resources.per_hour', { rate: formatRate(building.production.per_hour) }) }}
|
||
</p>
|
||
<p v-else class="text-ink-400">–</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="flex items-center justify-between gap-3 text-sm">
|
||
<span class="text-ink-500">{{ $t('village.buildings.priority') }}</span>
|
||
<div class="inline-flex items-center rounded-sm border border-wood-600 bg-parchment-50">
|
||
<button
|
||
type="button"
|
||
class="btn btn-ghost rounded-r-none p-1"
|
||
:aria-label="$t('village.buildings.priority_down')"
|
||
:disabled="busy || building.priority <= 0"
|
||
@click="emit('priority', building.id, building.priority - 1)"
|
||
>
|
||
<IconUi name="minus" class="size-3.5" />
|
||
</button>
|
||
<span class="w-6 text-center font-semibold tabular-nums">{{ building.priority }}</span>
|
||
<button
|
||
type="button"
|
||
class="btn btn-ghost rounded-l-none p-1"
|
||
:aria-label="$t('village.buildings.priority_up')"
|
||
:disabled="busy || building.priority >= 9"
|
||
@click="emit('priority', building.id, building.priority + 1)"
|
||
>
|
||
<IconUi name="plus" class="size-3.5" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<NuxtLink v-if="link" :to="link.to" class="btn btn-outline w-full">{{ link.label }}</NuxtLink>
|
||
|
||
<div v-if="building.upgrade" 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="building.upgrade.cost" :have="resources" />
|
||
<span class="flex items-center gap-1 tabular-nums">
|
||
<IconUi name="clock" class="size-3" />
|
||
{{ formatDuration(building.upgrade.seconds) }}
|
||
</span>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
class="btn btn-primary w-full"
|
||
:disabled="busy || !canAfford(building.upgrade.cost)"
|
||
@click="emit('upgrade', building.id)"
|
||
>
|
||
<IconUi name="up" class="size-3.5" />
|
||
{{ $t('village.buildings.upgrade', { level: building.upgrade.target_level }) }}
|
||
</button>
|
||
</div>
|
||
<p v-else class="text-sm text-ink-500">{{ $t('village.blocked.max_level') }}</p>
|
||
|
||
<div v-if="building.demolish" class="flex items-center justify-between gap-2 text-xs text-ink-500">
|
||
<span class="flex flex-wrap items-center gap-1.5">
|
||
{{ $t('village.buildings.refund') }}
|
||
<UiCost :cost="building.demolish.refund" />
|
||
</span>
|
||
<button type="button" class="btn btn-danger" :disabled="busy" @click="emit('demolish', building.id)">
|
||
{{ $t('village.buildings.demolish') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</template>
|