74 lines
2.6 KiB
Vue
74 lines
2.6 KiB
Vue
|
|
<script setup lang="ts">
|
|||
|
|
import type { Building, Cost } from '~/types/game'
|
|||
|
|
|
|||
|
|
defineProps<{
|
|||
|
|
buildings: Building[]
|
|||
|
|
canAfford: (cost: Cost) => boolean
|
|||
|
|
busy: boolean
|
|||
|
|
}>()
|
|||
|
|
const emit = defineEmits<{
|
|||
|
|
upgrade: [buildingId: number]
|
|||
|
|
demolish: [buildingId: number]
|
|||
|
|
priority: [buildingId: number, priority: number]
|
|||
|
|
}>()
|
|||
|
|
|
|||
|
|
function onPriority(b: Building, e: Event) {
|
|||
|
|
emit('priority', b.id, Number((e.target as HTMLInputElement).value))
|
|||
|
|
}
|
|||
|
|
</script>
|
|||
|
|
|
|||
|
|
<template>
|
|||
|
|
<section>
|
|||
|
|
<h2>{{ $t('village.buildings.title') }}</h2>
|
|||
|
|
<table>
|
|||
|
|
<thead>
|
|||
|
|
<tr>
|
|||
|
|
<th>{{ $t('village.buildings.type') }}</th>
|
|||
|
|
<th>{{ $t('village.buildings.level') }}</th>
|
|||
|
|
<th>{{ $t('village.buildings.position') }}</th>
|
|||
|
|
<th>{{ $t('village.buildings.size') }}</th>
|
|||
|
|
<th>{{ $t('village.buildings.workers') }}</th>
|
|||
|
|
<th>{{ $t('village.buildings.staffing') }}</th>
|
|||
|
|
<th>{{ $t('village.buildings.output') }}</th>
|
|||
|
|
<th>{{ $t('village.buildings.priority') }}</th>
|
|||
|
|
<th>{{ $t('village.buildings.actions') }}</th>
|
|||
|
|
</tr>
|
|||
|
|
</thead>
|
|||
|
|
<tbody>
|
|||
|
|
<tr v-for="b in buildings" :key="b.id">
|
|||
|
|
<td>{{ $t(`buildings.${b.type}`) }}</td>
|
|||
|
|
<td>{{ b.level }}</td>
|
|||
|
|
<td>{{ b.footprint[0] ? `${b.x}|${b.y}` : '–' }}</td>
|
|||
|
|
<td>{{ b.footprint[0] }}×{{ b.footprint[1] }}</td>
|
|||
|
|
<td>{{ b.workers.assigned }}/{{ b.workers.required }}</td>
|
|||
|
|
<td>{{ Math.round(b.staffing * 100) }}%</td>
|
|||
|
|
<td>
|
|||
|
|
<template v-if="b.production">
|
|||
|
|
{{ $t(`resources.${b.production.resource}`) }}
|
|||
|
|
{{ $t('village.resources.per_hour', { rate: formatRate(b.production.per_hour) }) }}
|
|||
|
|
</template>
|
|||
|
|
<template v-else>–</template>
|
|||
|
|
</td>
|
|||
|
|
<td>
|
|||
|
|
<input type="number" min="0" max="9" size="2" :value="b.priority" :disabled="busy" @change="onPriority(b, $event)" />
|
|||
|
|
</td>
|
|||
|
|
<td>
|
|||
|
|
<button
|
|||
|
|
v-if="b.upgrade"
|
|||
|
|
type="button"
|
|||
|
|
:disabled="busy || !canAfford(b.upgrade.cost)"
|
|||
|
|
@click="emit('upgrade', b.id)"
|
|||
|
|
>
|
|||
|
|
{{ $t('village.buildings.upgrade', { level: b.upgrade.target_level }) }}
|
|||
|
|
({{ formatCost(b.upgrade.cost) }}, {{ formatDuration(b.upgrade.seconds) }})
|
|||
|
|
</button>
|
|||
|
|
<button v-if="b.demolish" type="button" :disabled="busy" @click="emit('demolish', b.id)">
|
|||
|
|
{{ $t('village.buildings.demolish') }} ({{ $t('village.buildings.refund') }} {{ formatCost(b.demolish.refund) }})
|
|||
|
|
</button>
|
|||
|
|
</td>
|
|||
|
|
</tr>
|
|||
|
|
</tbody>
|
|||
|
|
</table>
|
|||
|
|
</section>
|
|||
|
|
</template>
|