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

105 lines
4.4 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 { Building, BuildingType } from '~/types/game'
const props = defineProps<{
buildings: Building[]
busy: boolean
}>()
const emit = defineEmits<{
select: [buildingId: number]
priority: [buildingId: number, priority: number]
}>()
const { t } = useI18n()
// Who works where: building and upgrading live in the construction table above.
const named = computed(() => {
const seen = new Map<BuildingType, number>()
const totals = new Map<BuildingType, number>()
for (const b of props.buildings) totals.set(b.type, (totals.get(b.type) ?? 0) + 1)
return props.buildings.map((b) => {
const n = (seen.get(b.type) ?? 0) + 1
seen.set(b.type, n)
return {
b,
name: (totals.get(b.type) ?? 0) > 1 ? t('village.build.nth', { name: t(`buildings.${b.type}`), n }) : t(`buildings.${b.type}`),
}
})
})
</script>
<template>
<section class="panel overflow-hidden">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.buildings.title') }}</h2>
<span class="badge badge-plain">{{ buildings.length }}</span>
</div>
<div class="overflow-x-auto">
<table class="w-full min-w-[34rem] border-collapse text-sm">
<thead>
<tr class="border-b-2 border-wood-700 bg-parchment-100 text-left text-xs font-semibold text-ink-700">
<th class="px-3 py-1.5">{{ $t('village.buildings.type') }}</th>
<th class="px-2 py-1.5 text-right">{{ $t('village.buildings.level') }}</th>
<th class="w-40 px-2 py-1.5">{{ $t('village.buildings.workers') }}</th>
<th class="px-2 py-1.5">{{ $t('village.buildings.output') }}</th>
<th class="px-3 py-1.5 text-right">{{ $t('village.buildings.priority') }}</th>
</tr>
</thead>
<tbody>
<tr v-for="{ b, name } in named" :key="b.id" class="border-b border-parchment-300 last:border-b-0 even:bg-parchment-100">
<td class="px-3 py-1">
<div class="flex items-center gap-2">
<IconBuildingTile :type="b.type" class="size-7" />
<button
type="button"
class="truncate text-left font-semibold hover:text-blood-700 hover:underline"
:title="$t('village.buildings.show')"
@click="emit('select', b.id)"
>
{{ name }}
</button>
</div>
</td>
<td class="px-2 py-1 text-right font-semibold tabular-nums">{{ b.level }}</td>
<td class="px-2 py-1">
<div class="flex items-center gap-2">
<span class="w-12 shrink-0 text-xs tabular-nums">{{ b.workers.assigned }}/{{ b.workers.required }}</span>
<UiBar :value="b.staffing" :tone="b.staffing < 1 ? 'rose' : 'emerald'" />
</div>
</td>
<td class="px-2 py-1">
<span v-if="b.production" class="flex items-center gap-1 tabular-nums whitespace-nowrap">
<IconResource :resource="b.production.resource" class="size-4" />
{{ $t('village.resources.per_hour', { rate: formatRate(b.production.per_hour) }) }}
</span>
<span v-else class="text-ink-400">–</span>
</td>
<td class="px-3 py-1 text-right">
<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 || b.priority <= 0"
@click="emit('priority', b.id, b.priority - 1)"
>
<IconUi name="minus" class="size-3.5" />
</button>
<span class="w-6 text-center font-semibold tabular-nums">{{ b.priority }}</span>
<button
type="button"
class="btn btn-ghost rounded-l-none p-1"
:aria-label="$t('village.buildings.priority_up')"
:disabled="busy || b.priority >= 9"
@click="emit('priority', b.id, b.priority + 1)"
>
<IconUi name="plus" class="size-3.5" />
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</template>