2026-10-28 20:51:43 +00:00
|
|
|
<script setup lang="ts">
|
2026-10-28 21:14:56 +00:00
|
|
|
import type { Levy, UnitType } from '~/types/game'
|
2026-10-28 20:51:43 +00:00
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
troops: Partial<Record<UnitType, number>>
|
|
|
|
|
training: number
|
2026-10-28 20:58:09 +00:00
|
|
|
levy: Levy
|
|
|
|
|
/** Villagers a new levy can draft. */
|
|
|
|
|
villagers: number
|
|
|
|
|
secondsUntil: (iso: string) => number
|
|
|
|
|
busy: boolean
|
2026-10-28 20:51:43 +00:00
|
|
|
}>()
|
2026-10-28 21:14:56 +00:00
|
|
|
const emit = defineEmits<{ levy: [count: number]; endLevy: [] }>()
|
2026-10-28 20:51:43 +00:00
|
|
|
|
|
|
|
|
const home = computed(() => (Object.entries(props.troops) as [UnitType, number][]).filter(([, n]) => n > 0))
|
2026-10-28 20:58:09 +00:00
|
|
|
|
|
|
|
|
const draft = ref<number | null>(null)
|
|
|
|
|
const draftCount = computed(() => Math.min(props.villagers, Math.floor(Number(draft.value) || 0)))
|
|
|
|
|
|
|
|
|
|
function submitLevy() {
|
|
|
|
|
if (draftCount.value < 1) return
|
|
|
|
|
emit('levy', draftCount.value)
|
|
|
|
|
draft.value = null
|
|
|
|
|
}
|
2026-10-28 20:51:43 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-10-28 20:58:09 +00:00
|
|
|
<!-- Own units in the village, like the Die Stämme overview's unit box, and the levy. -->
|
2026-10-28 20:51:43 +00:00
|
|
|
<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">
|
2026-10-28 20:58:09 +00:00
|
|
|
<ul v-if="home.length || levy.militia" class="divide-y divide-parchment-300">
|
2026-10-28 20:51:43 +00:00
|
|
|
<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>
|
2026-10-28 20:58:09 +00:00
|
|
|
<li v-if="levy.militia" class="flex items-center gap-2 py-1 text-sm">
|
|
|
|
|
<IconUnit unit="militia" class="size-5 text-wood-800" />
|
|
|
|
|
<span class="flex-1">{{ $t('village.levy.militia') }}</span>
|
|
|
|
|
<span class="font-semibold tabular-nums">{{ levy.militia }}</span>
|
|
|
|
|
</li>
|
2026-10-28 20:51:43 +00:00
|
|
|
</ul>
|
|
|
|
|
<p v-else class="py-2 text-center text-sm text-ink-500">{{ $t('village.troops.none') }}</p>
|
2026-10-28 20:58:09 +00:00
|
|
|
|
|
|
|
|
<!-- Levy: draft villagers as militia for a fixed time. -->
|
|
|
|
|
<div class="mt-4 border-t-2 border-parchment-300 pt-3">
|
|
|
|
|
<div v-if="levy.militia && levy.until" class="flex items-center gap-2 text-sm">
|
|
|
|
|
<IconUi name="clock" class="size-3.5 text-ink-400" />
|
|
|
|
|
<span class="flex-1">
|
|
|
|
|
{{ $t('village.levy.returns_in') }}
|
|
|
|
|
<span class="font-semibold tabular-nums">{{ formatDuration(secondsUntil(levy.until)) }}</span>
|
|
|
|
|
</span>
|
|
|
|
|
<button type="button" class="btn btn-outline px-2.5 py-1" :disabled="busy" @click="emit('endLevy')">
|
|
|
|
|
{{ $t('village.levy.end') }}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<form v-else class="space-y-2" @submit.prevent="submitLevy">
|
|
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<label for="levy-count" class="flex-1 text-sm font-semibold">{{ $t('village.levy.title') }}</label>
|
|
|
|
|
<input
|
|
|
|
|
id="levy-count"
|
|
|
|
|
v-model.number="draft"
|
|
|
|
|
type="number"
|
|
|
|
|
min="0"
|
|
|
|
|
:max="villagers"
|
|
|
|
|
inputmode="numeric"
|
|
|
|
|
class="input w-16 px-1.5 py-0.5 text-right tabular-nums"
|
|
|
|
|
/>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-10-29 13:09:03 +00:00
|
|
|
class="btn-fill"
|
2026-10-28 20:58:09 +00:00
|
|
|
:title="$t('village.levy.all')"
|
|
|
|
|
:disabled="!villagers"
|
|
|
|
|
@click="draft = villagers"
|
|
|
|
|
>
|
|
|
|
|
({{ villagers }})
|
|
|
|
|
</button>
|
|
|
|
|
<button type="submit" class="btn btn-primary px-2.5 py-1" :disabled="busy || draftCount < 1">
|
|
|
|
|
{{ $t('village.levy.submit') }}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<p class="text-xs text-ink-500">{{ $t('village.levy.hint', { duration: formatDuration(levy.seconds) }) }}</p>
|
|
|
|
|
</form>
|
|
|
|
|
</div>
|
2026-10-28 20:51:43 +00:00
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</template>
|