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

40 lines
1.6 KiB
Vue

<script setup lang="ts">
import type { MilitaryBuilding, UnitType } from '~/types/game'
const props = defineProps<{
troops: Partial<Record<UnitType, number>>
military: MilitaryBuilding[]
training: number
}>()
const emit = defineEmits<{ recruit: [] }>()
const home = computed(() => (Object.entries(props.troops) as [UnitType, number][]).filter(([, n]) => n > 0))
</script>
<!-- Own units in the village, like the Die Stämme overview's unit box. -->
<template>
<section class="panel">
<div class="panel-head">
<h2 class="panel-title">{{ $t('village.troops.title') }}</h2>
<span v-if="training" class="badge badge-plain">
<IconUi name="clock" class="size-3.5" />
{{ $t('village.troops.training', { count: training }) }}
</span>
</div>
<div class="panel-body">
<ul v-if="home.length" class="divide-y divide-parchment-300">
<li v-for="[unit, count] in home" :key="unit" class="flex items-center gap-2 py-1 text-sm">
<IconUnit :unit="unit" class="size-5 text-wood-800" />
<span class="flex-1">{{ $t(`units.${unit}`) }}</span>
<span class="font-semibold tabular-nums">{{ count }}</span>
</li>
</ul>
<p v-else class="py-2 text-center text-sm text-ink-500">{{ $t('village.troops.none') }}</p>
<button v-if="military.length" type="button" class="btn btn-outline mt-3 w-full" @click="emit('recruit')">
{{ $t('village.troops.recruit') }}
</button>
<p v-else class="mt-1 text-center text-xs text-ink-500">{{ $t('village.troops.hint') }}</p>
</div>
</section>
</template>