feat: the open map reloads a second after village:updated pushes, so new barbarian villages show up

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-11-03 09:41:47 +01:00
parent c51f27fc17
commit 33a29bbc56
1 changed files with 15 additions and 0 deletions

View File

@ -1,5 +1,6 @@
<script setup lang="ts">
import type { DockItem } from '~/components/ui/Dock.vue'
import type { VillageUpdated } from '~/types/game'
import type { MapMovement, MapRelationKind, MapVillage } from '~/types/map'
definePageMeta({ layout: 'game' })
@ -241,6 +242,20 @@ watch(
if (before !== undefined && now !== before) reload()
},
)
// The server pushes village:updated to the player's villages when something changes round
// them, a wave of new barbarian villages settling nearby among others: reload the map and the
// minimap once, a second after a burst of pushes is over.
let pushed: ReturnType<typeof setTimeout> | undefined
ws.listenWhileMounted<VillageUpdated>('village:updated', null, () => {
clearTimeout(pushed)
pushed = setTimeout(() => {
reload()
const o = overview.view.value
if (o) overview.load(o.center, o.w, o.h)
}, 1000)
})
onBeforeUnmount(() => clearTimeout(pushed))
const LEGEND: MapRelationKind[] = ['own', 'tribe', 'ally', 'nap', 'enemy', 'none', 'barbarian']
const currentVillage = computed(() => useCurrentWorld().current.value?.villageId ?? null)