87 lines
3.6 KiB
Vue
87 lines
3.6 KiB
Vue
<script setup lang="ts">
|
|
import type { UnitType } from '~/types/game'
|
|
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
const v = useVillageContext()
|
|
const { t } = useI18n()
|
|
const village = computed(() => v.village.value!)
|
|
|
|
/** `?x=&y=` from the map fills in the target. */
|
|
const initialTarget = computed(() => (route.query.x && route.query.y ? { x: Number(route.query.x), y: Number(route.query.y) } : null))
|
|
const rallyPoint = computed(() => village.value.buildings.find((b) => b.type === 'rally_point') ?? null)
|
|
|
|
// Like the rally point in Die Stämme, its parts are tabs: commands, troops, simulator.
|
|
type Tab = 'commands' | 'troops' | 'simulator'
|
|
const tab = computed<Tab>({
|
|
get: () => (['troops', 'simulator'].includes(String(route.query.tab)) ? (route.query.tab as Tab) : 'commands'),
|
|
set: (value) => router.replace({ query: { ...route.query, tab: value === 'commands' ? undefined : value } }),
|
|
})
|
|
const incoming = computed(() => village.value.movements.filter((m) => m.direction === 'in').length)
|
|
const tabs = computed(() => [
|
|
{ key: 'commands' as const, label: t('village.rally.tabs.commands'), icon: 'attack' as const, count: incoming.value },
|
|
{ key: 'troops' as const, label: t('village.rally.tabs.troops'), icon: 'users' as const },
|
|
{ key: 'simulator' as const, label: t('village.rally.tabs.simulator'), icon: 'support' as const },
|
|
])
|
|
const home = computed(() => unitRows(village.value.troops))
|
|
</script>
|
|
|
|
<!-- The rally point: send troops and follow them, see where the troops are, and simulate battles. -->
|
|
<template>
|
|
<div class="space-y-3 p-2.5">
|
|
<VillageScreenHeader type="rally_point" :level="rallyPoint?.level ?? null" :title="$t('buildings.rally_point')" :description="$t('village.about.rally')" />
|
|
<UiSubTabs v-model="tab" :tabs="tabs" />
|
|
|
|
<div v-if="tab === 'commands'" class="grid gap-3 @4xl:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
|
|
<VillageSendTroops
|
|
:key="`${route.query.x}|${route.query.y}`"
|
|
class="self-start"
|
|
:village="village"
|
|
:busy="v.busy.value"
|
|
:initial-target="initialTarget"
|
|
:now="v.now.value"
|
|
:preview="v.preview"
|
|
:send="v.send"
|
|
/>
|
|
<VillageMovements
|
|
class="self-start"
|
|
:movements="village.movements"
|
|
:world-id="village.world_id"
|
|
:now="v.now.value"
|
|
:seconds-until="v.secondsUntil"
|
|
:busy="v.busy.value"
|
|
@cancel="v.cancelMovement"
|
|
/>
|
|
</div>
|
|
|
|
<div v-else-if="tab === 'troops'" class="grid gap-3 @4xl:grid-cols-[18rem_minmax(0,1fr)]">
|
|
<section class="panel self-start">
|
|
<div class="panel-head">
|
|
<h2 class="panel-title">{{ $t('village.rally.at_home') }}</h2>
|
|
</div>
|
|
<div class="panel-body">
|
|
<ul v-if="home.length" class="divide-y divide-parchment-300 text-sm">
|
|
<li v-for="[unit, count] in home" :key="unit" class="flex items-center gap-2 py-1">
|
|
<IconUnit :unit="unit as UnitType" 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="text-sm text-ink-500">{{ $t('village.troops.none') }}</p>
|
|
</div>
|
|
</section>
|
|
<VillageSupportPanel
|
|
class="self-start"
|
|
:here="village.support.here"
|
|
:away="village.support.away"
|
|
:world-id="village.world_id"
|
|
:busy="v.busy.value"
|
|
@send-home="v.sendHome"
|
|
@withdraw="v.withdraw"
|
|
/>
|
|
</div>
|
|
|
|
<VillageSimulator v-else :world-id="village.world_id" :troops="village.troops" open />
|
|
</div>
|
|
</template>
|