feat: marching groups you can click: a card at the group with where from and to, troops, arrival and call-back; a village lists its groups in and out; groups leave the map when they arrive and the map reloads; own commands on the overview with call-back

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-30 11:24:02 +01:00
parent 62d9673eb6
commit 5415ea01ea
4 changed files with 118 additions and 6 deletions

File diff suppressed because one or more lines are too long

View File

@ -357,7 +357,7 @@ function onKey(e: KeyboardEvent) {
</line> </line>
<g <g
:transform="`translate(${g.x} ${g.y}) scale(${Math.max(0.6, field / 55)})`" :transform="`translate(${g.x} ${g.y}) scale(${Math.max(0.6, field / 55)})`"
class="pointer-events-auto cursor-pointer" class="pointer-events-auto cursor-pointer outline-none focus-visible:outline-2 focus-visible:outline-gold-500"
role="button" role="button"
tabindex="0" tabindex="0"
:aria-label="marchTitle(g.m)" :aria-label="marchTitle(g.m)"

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { DockItem } from '~/components/ui/Dock.vue' import type { DockItem } from '~/components/ui/Dock.vue'
import type { BuildOrder, UnitType, VillageRole, VillageState } from '~/types/game' import type { BuildOrder, Movement, UnitType, VillageRole, VillageState } from '~/types/game'
const props = defineProps<{ const props = defineProps<{
village: VillageState village: VillageState
@ -16,6 +16,14 @@ const idle = computed(() => props.village.population.villagers - props.village.p
const spaceShare = computed(() => props.village.space.used / props.village.space.max) const spaceShare = computed(() => props.village.space.used / props.village.space.max)
const incoming = computed(() => props.village.movements.filter((m) => m.direction === 'in' && m.type === 'attack')) const incoming = computed(() => props.village.movements.filter((m) => m.direction === 'in' && m.type === 'attack'))
const commands = computed(() => props.village.movements.filter((m) => m.direction !== 'in').length) const commands = computed(() => props.village.movements.filter((m) => m.direction !== 'in').length)
/** Own groups under way, out and home, soonest first; they can be called back for a while. */
const own = computed(() => props.village.movements.filter((m) => m.direction !== 'in'))
const v = useVillageContextOrNull()
const command = (m: Movement) =>
m.direction === 'home'
? t('village.movements.return_from', { from: villageLabel(m.from) })
: t(m.type === 'attack' ? 'village.movements.attack_on' : 'village.movements.support_for', { target: villageLabel(m.to) })
const canCancel = (m: Movement) => !!m.cancel_until && props.secondsUntil(m.cancel_until) > 0
const spec = computed(() => props.village.specialisation) const spec = computed(() => props.village.specialisation)
const season = computed(() => props.village.season) const season = computed(() => props.village.season)
const roleSpace = computed(() => spec.value.roles.reduce((sum, r) => sum + (spec.value.space[r.role] ?? 0), 0)) const roleSpace = computed(() => spec.value.roles.reduce((sum, r) => sum + (spec.value.space[r.role] ?? 0), 0))
@ -23,6 +31,7 @@ const roleShare = (role: VillageRole) => (roleSpace.value ? Math.round((100 * (s
// Every box folds and moves (UiDock); the incoming attacks only while there are any. // Every box folds and moves (UiDock); the incoming attacks only while there are any.
const cards = computed<DockItem[]>(() => [ const cards = computed<DockItem[]>(() => [
{ key: 'incoming', title: t('village.side.incoming'), alarm: true, show: incoming.value.length > 0 }, { key: 'incoming', title: t('village.side.incoming'), alarm: true, show: incoming.value.length > 0 },
{ key: 'commands', title: t('village.movements.own'), show: own.value.length > 0 },
{ key: 'production', title: t('village.side.production') }, { key: 'production', title: t('village.side.production') },
{ key: 'units', title: t('village.side.units') }, { key: 'units', title: t('village.side.units') },
{ key: 'population', title: t('village.population.title') }, { key: 'population', title: t('village.population.title') },
@ -53,6 +62,29 @@ function order(o: BuildOrder) {
</ul> </ul>
</template> </template>
<template #commands>
<ul class="side-body">
<li v-for="m in own" :key="m.id">
<div class="flex items-center gap-2">
<IconUi :name="m.type === 'return' ? 'return' : m.type" class="size-4 shrink-0" />
<NuxtLink
:to="{ path: `/map/${village.world_id}`, query: { x: (m.direction === 'home' ? m.from : m.to).x, y: (m.direction === 'home' ? m.from : m.to).y } }"
class="min-w-0 flex-1 truncate hover:underline"
:title="command(m)"
>
{{ command(m) }}
</NuxtLink>
<span class="font-semibold tabular-nums">{{ formatDuration(secondsUntil(m.arrives_at)) }}</span>
</div>
<div v-if="v && canCancel(m)" class="flex justify-end pb-0.5">
<button type="button" class="btn btn-outline px-1.5 py-0 text-xs tabular-nums" :disabled="v.busy.value" @click="v.cancelMovement(m.id)">
{{ $t('village.movements.cancel') }} · {{ formatDuration(secondsUntil(m.cancel_until!)) }}
</button>
</div>
</li>
</ul>
</template>
<template #production> <template #production>
<ul class="side-body"> <ul class="side-body">
<li v-for="{ r, rate } in production" :key="r" class="flex items-center gap-2"> <li v-for="{ r, rate } in production" :key="r" class="flex items-center gap-2">

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import type { DockItem } from '~/components/ui/Dock.vue' import type { DockItem } from '~/components/ui/Dock.vue'
import type { MapRelationKind, MapVillage } from '~/types/map' import type { MapMovement, MapRelationKind, MapVillage } from '~/types/map'
definePageMeta({ layout: 'game' }) definePageMeta({ layout: 'game' })
@ -178,6 +178,69 @@ function onDragEnd() {
} }
const clock = useNow() const clock = useNow()
// A group on the march, clicked on the map or in a village's list: its card floats at the
// group and moves with it. It keeps its id when it turns home, so the card follows it back.
const march = ref<number | null>(null)
const marchBusy = ref(false)
const marchError = ref<string | null>(null)
const selectedMarch = computed(() => (march.value === null ? null : (view.value?.movements.find((m) => m.id === march.value) ?? null)))
/** Where the group is now, in fields. */
const marchAt = computed(() => {
const m = selectedMarch.value
if (!m || !visible.value || dragging.value) return null
const start = Date.parse(m.sent_at)
const end = Date.parse(m.arrives_at)
if (clock.value >= end) return null
const p = end > start ? clamp((clock.value - start) / (end - start), 0, 1) : 1
return { x: m.from.x + (m.to.x - m.from.x) * p, y: m.from.y + (m.to.y - m.from.y) * p }
})
function pickMarch(id: number) {
selected.value = null
marchError.value = null
march.value = march.value === id ? null : id
}
function pickField(at: { x: number; y: number }) {
march.value = null
selected.value = at
}
const errorText = useErrorText()
async function cancelMarch(m: MapMovement) {
marchBusy.value = true
marchError.value = null
try {
await ws.send('rally.cancel', { village_id: m.from.id, movement_id: m.id })
reload()
if (bar?.village.value?.id === m.from.id) bar.refresh()
} catch (e) {
marchError.value = errorText(e)
} finally {
marchBusy.value = false
}
}
// Groups leave the map when they arrive. Reload then, and whenever the village bar learns
// of a change (a battle, a return), so the group's way home shows up.
function reload() {
const v = view.value
if (v) load(v.center, v.w, v.h)
}
const nextArrival = computed(() => {
const times = (view.value?.movements ?? []).map((m) => Date.parse(m.arrives_at))
return times.length ? Math.min(...times) : null
})
watch(
() => nextArrival.value !== null && clock.value >= nextArrival.value + 1500,
(due) => {
if (due) reload()
},
)
watch(
() => bar?.village.value?.movements.map((m) => `${m.id}:${m.type}:${m.arrives_at}`).join(),
(now, before) => {
if (before !== undefined && now !== before) reload()
},
)
const LEGEND: MapRelationKind[] = ['own', 'tribe', 'ally', 'nap', 'enemy', 'none', 'barbarian'] const LEGEND: MapRelationKind[] = ['own', 'tribe', 'ally', 'nap', 'enemy', 'none', 'barbarian']
const currentVillage = computed(() => useCurrentWorld().current.value?.villageId ?? null) const currentVillage = computed(() => useCurrentWorld().current.value?.villageId ?? null)
@ -234,7 +297,9 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
:selected="selected" :selected="selected"
:current="currentVillage" :current="currentVillage"
:now="clock" :now="clock"
@select="selected = $event" :march="march"
@select="pickField"
@march="pickMarch"
@hover="hovered = $event" @hover="hovered = $event"
@drag="onDragMove" @drag="onDragMove"
@dragend="onDragEnd" @dragend="onDragEnd"
@ -254,10 +319,25 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
:village="menu" :village="menu"
:from="from" :from="from"
actions actions
:movements="view?.movements ?? []"
:now="clock"
class="absolute z-20 -translate-x-1/2" class="absolute z-20 -translate-x-1/2"
:style="popupAt(menu.x, menu.y, true)" :style="popupAt(menu.x, menu.y, true)"
@center="goTo(menu)" @center="goTo(menu)"
@close="selected = null" @close="selected = null"
@march="pickMarch"
/>
<MapMarchCard
v-if="selectedMarch && marchAt"
:march="selectedMarch"
:now="clock"
:busy="marchBusy"
:error="marchError"
class="absolute z-20 -translate-x-1/2"
:style="popupAt(marchAt.x, marchAt.y, true)"
@close="march = null"
@cancel="cancelMarch(selectedMarch)"
@center="goTo"
/> />
<!-- Phones have no dock: home and zoom float over the map instead. --> <!-- Phones have no dock: home and zoom float over the map instead. -->
<div v-if="staged" class="float absolute bottom-16 left-2 z-20 flex border border-wood-900 bg-parchment-200 lg:hidden"> <div v-if="staged" class="float absolute bottom-16 left-2 z-20 flex border border-wood-900 bg-parchment-200 lg:hidden">
@ -309,7 +389,7 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
</template> </template>
<template #field> <template #field>
<MapInfoCard :village="shown" :at="selected" @center="goTo" /> <MapInfoCard :village="shown" :at="selected" :movements="view?.movements ?? []" :now="clock" @center="goTo" @march="pickMarch" />
</template> </template>
<template #legend> <template #legend>