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

71 lines
2.6 KiB
Vue

<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)
const shownBuilding = computed(() => village.value.buildings.find((b) => b.id === shown.value?.building_id) ?? null)
const { t } = useI18n()
</script>
<!-- Recruiting at every military building, the troops at home and the levy. -->
<template>
<div class="space-y-3 p-2.5">
<VillageBuildingHeader
v-if="shownBuilding"
:building="shownBuilding"
:title="buildingName(village, shownBuilding, t)"
:resources="v.resources.value!"
:can-afford="v.canAfford"
:busy="v.busy.value"
@upgrade="v.upgrade"
@demolish="v.demolish"
@priority="v.setPriority"
/>
<VillageScreenHeader
v-else
: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-3 @4xl:grid-cols-[minmax(0,1fr)_18rem]">
<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>
<div class="space-y-3">
<VillageCoinPanel v-if="shown?.type === 'academy'" :conquest="village.conquest" :resources="resources" :busy="v.busy.value" @mint="v.mint" />
<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>
</div>
</template>