game-village-politics-frontend/app/pages/village/[id]/recruit.vue

54 lines
1.9 KiB
Vue
Raw Normal View History

<script setup lang="ts">
const route = useRoute()
const v = useVillageContext()
const village = computed(() => v.village.value!)
const resources = computed(() => v.resources.value!)
/** Military building whose tab is open; `?at=` picks one. */
const recruitAt = ref<number | null>(Number(route.query.at) || null)
watch(
() => route.query.at,
(at) => (recruitAt.value = Number(at) || recruitAt.value),
)
const shown = computed(() => village.value.military.find((m) => m.building_id === recruitAt.value) ?? village.value.military[0] ?? null)
</script>
<!-- Recruiting at every military building, the troops at home and the levy. -->
<template>
<div class="mx-auto max-w-[96rem] space-y-6 px-4 py-6 sm:px-6">
<VillageScreenHeader
:type="shown?.type ?? 'barracks'"
:level="shown?.level ?? null"
:title="shown ? $t(`buildings.${shown.type}`) : $t('village.screens.recruit')"
:description="$t('village.about.recruit')"
/>
<div class="grid gap-6 lg:grid-cols-[minmax(0,1fr)_22rem] 2xl:grid-cols-[minmax(0,1fr)_26rem]">
<VillageRecruit
v-if="village.military.length"
v-model:selected="recruitAt"
:military="village.military"
:troops="village.troops"
:villagers="village.population.villagers - village.levy.militia"
:resources="resources"
:seconds-until="v.secondsUntil"
:busy="v.busy.value"
:recruit="v.recruit"
@cancel="v.cancelRecruit"
/>
<section v-else class="panel">
<div class="panel-body py-8 text-center text-sm text-ink-500">{{ $t('village.troops.hint') }}</div>
</section>
<VillageTroopsPanel
:troops="village.troops"
:training="village.population.training"
:levy="village.levy"
:villagers="village.population.villagers"
:seconds-until="v.secondsUntil"
:busy="v.busy.value"
@levy="v.levy"
@end-levy="v.endLevy"
/>
</div>
</div>
</template>