feat: map colours by relation (own, current, tribe, allies, NAP, enemies, others, barbarians) and marching groups on lines from origin to target, sized by tier

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-30 11:07:31 +01:00
parent de06778071
commit 0ba6c6026c
10 changed files with 230 additions and 22 deletions

File diff suppressed because one or more lines are too long

View File

@ -18,7 +18,13 @@ const { current } = useCurrentWorld()
<dt class="text-ink-500">{{ $t('map.info.coordinates') }}</dt>
<dd class="font-semibold tabular-nums">{{ village.x }}|{{ village.y }} <span class="text-ink-500">{{ village.continent }}</span></dd>
<dt class="text-ink-500">{{ $t('map.info.owner') }}</dt>
<dd>{{ village.player?.name ?? $t('map.barbarian') }}</dd>
<dd>
{{ village.player?.name ?? $t('map.barbarian') }}<span v-if="village.player?.tribe" class="ml-1 text-ink-500">[{{ village.player.tribe.tag }}]</span>
</dd>
<dt class="text-ink-500">{{ $t('map.info.relation') }}</dt>
<dd class="inline-flex items-center gap-1.5">
<span class="size-3 border border-wood-900" :style="{ background: RELATION_COLOURS[village.relation] }" />{{ $t(`map.legend.${village.relation}`) }}
</dd>
<dt class="text-ink-500">{{ $t('map.info.points') }}</dt>
<dd class="tabular-nums">{{ village.points }}</dd>
</dl>

View File

@ -0,0 +1,57 @@
<script setup lang="ts">
import type { MapMovement } from '~/types/map'
const props = defineProps<{
size: MapMovement['size']
colour: string
/** Walking to the left. */
flip?: boolean
motion?: boolean
}>()
// One to five soldiers by the size tier, in a little column behind a banner bearer.
const COUNT = { tiny: 1, small: 2, medium: 3, large: 4, huge: 5 }
const soldiers = computed(() =>
Array.from({ length: COUNT[props.size] }, (_, i) => ({ x: -i * 9 + (i % 2) * 2, y: (i % 2) * 5, delay: `${-i * 0.18}s` })),
)
</script>
<!-- A group on the march, drawn round its position in a 100-unit box; each soldier steps in place. -->
<template>
<g :transform="flip ? 'scale(-1 1)' : undefined">
<ellipse :cx="-((COUNT[size] - 1) * 9) / 2" cy="12" :rx="10 + COUNT[size] * 5" ry="5" fill="#2b2118" opacity="0.35" />
<g v-for="(s, i) in soldiers" :key="i" :transform="`translate(${s.x} ${s.y})`">
<g :class="motion ? 'step' : ''" :style="{ animationDelay: s.delay }">
<rect x="-3" y="-8" width="6" height="11" :fill="i === 0 ? colour : '#57391f'" />
<rect x="-3" y="3" width="2.4" height="7" fill="#2b2118" class="leg" />
<rect x="0.6" y="3" width="2.4" height="7" fill="#2b2118" class="leg leg-b" />
<circle cy="-12" r="3.6" fill="#d9b48a" />
<line x1="5" y1="-20" x2="5" y2="6" stroke="#4a3b2e" stroke-width="1.6" />
<polygon v-if="i === 0" points="5,-20 16,-17 5,-13" :fill="colour" stroke="#2b2118" stroke-width="0.8" />
</g>
</g>
</g>
</template>
<style scoped>
/* Marching in place: a small bob, legs swapping. Off under reduced motion (no class then). */
.step {
animation: bob 0.55s steps(2) infinite;
}
.step .leg {
animation: swing 0.55s steps(2) infinite;
}
.step .leg-b {
animation-direction: reverse;
}
@keyframes bob {
to {
transform: translateY(-1.6px);
}
}
@keyframes swing {
to {
transform: translateY(-1.2px);
}
}
</style>

View File

@ -1,7 +1,7 @@
<script setup lang="ts">
export type MapRelation = 'own' | 'player' | 'barbarian'
import type { MarkerRelation } from '~/utils/relations'
const props = defineProps<{ tier: 1 | 2 | 3 | 4 | 5; relation: MapRelation; crown?: boolean }>()
const props = defineProps<{ tier: 1 | 2 | 3 | 4 | 5; relation: MarkerRelation; crown?: boolean }>()
// Low-poly settlements in a 100 × 100 box that grow with the village's points, like the
// five village sizes on the Die Stämme map: a hut, a hamlet, a village with a tower, a
@ -13,7 +13,7 @@ const tones = computed(() =>
: { wallLight: '#b5a486', wallDark: '#8b7c62', roofLight: '#7f4430', roofDark: '#5a3020' },
)
const STONE = { wallLight: '#9d988f', wallDark: '#77736c', roofLight: '#5a5f66', roofDark: '#45494f' }
const flag = computed(() => ({ own: '#d9b44a', player: '#962a1f', barbarian: '#8b9094' })[props.relation])
const flag = computed(() => RELATION_COLOURS[props.relation])
interface Block {
cx: number
@ -92,6 +92,8 @@ const pole = computed(() => {
<template>
<g>
<ellipse cx="50" cy="72" rx="42" ry="18" fill="#5f5640" />
<!-- The relation colour rings the village, so it reads at a glance. -->
<ellipse cx="50" cy="72" rx="44" ry="20" fill="none" :stroke="flag" stroke-width="6" />
<g v-for="(b, i) in blocks" :key="i">
<polygon :points="faces(b).left" :fill="faces(b).colors.wallDark" />
<polygon :points="faces(b).right" :fill="faces(b).colors.wallLight" />

View File

@ -1,5 +1,6 @@
<script setup lang="ts">
import type { MapVillage, MapView } from '~/types/map'
import type { MapMovement, MapVillage, MapView } from '~/types/map'
import type { MarkerRelation } from '~/utils/relations'
const props = defineProps<{
/** Loaded villages; fields outside it show plain land until the next load. */
@ -15,6 +16,10 @@ const props = defineProps<{
/** Field size in px. */
field: number
selected: { x: number; y: number } | null
/** The village the player is in now: drawn white. */
current?: number | null
/** The clock, for where groups on the march are. */
now: number
}>()
const emit = defineEmits<{
select: [at: { x: number; y: number }]
@ -118,7 +123,30 @@ const villageFields = computed(() => fields.value.filter((f) => f.village))
/** Five sizes by points, like the Die Stämme map. */
const tier = (points: number): 1 | 2 | 3 | 4 | 5 => (points < 150 ? 1 : points < 500 ? 2 : points < 1500 ? 3 : points < 5000 ? 4 : 5)
const relation = (v: MapVillage) => (v.own ? 'own' : v.player ? 'player' : 'barbarian')
const relation = (v: MapVillage): MarkerRelation => (v.id === props.current ? 'current' : (v.relation ?? (v.own ? 'own' : v.player ? 'none' : 'barbarian')))
// Groups on the march: a line from village to village and the group where it is now,
// moving straight at constant speed (raiders wait at their camp until they march).
const motion = ref(false)
onMounted(() => (motion.value = !window.matchMedia('(prefers-reduced-motion: reduce)').matches))
const centre = (p: { x: number; y: number }) => [(p.x + 0.5) * props.field, (p.y + 0.5) * props.field] as const
const marches = computed(() =>
(props.view?.movements ?? []).map((m: MapMovement) => {
const [ax, ay] = centre(m.from)
const [bx, by] = centre(m.to)
const start = Date.parse(m.sent_at)
const end = Date.parse(m.arrives_at)
const p = end > start ? Math.max(0, Math.min(1, (props.now - start) / (end - start))) : 1
const colour = m.raid ? MARCH_COLOURS.raid : MARCH_COLOURS[m.type]
return { m, ax, ay, bx, by, x: ax + (bx - ax) * p, y: ay + (by - ay) * p, colour, flip: bx < ax, waiting: props.now < start }
}),
)
const marchTitle = (m: MapMovement) =>
t(`map.march.${m.raid ? 'raid' : m.type}`, { from: `${m.from.name} (${m.from.x}|${m.from.y})`, to: `${m.to.name} (${m.to.x}|${m.to.y})` }) +
' · ' +
t(`map.march.sizes.${m.size}`) +
' · ' +
formatDuration(Math.max(0, (Date.parse(m.arrives_at) - props.now) / 1000))
// Sector lines every 10 fields, continent borders every 100.
const lines = computed(() => {
@ -303,6 +331,16 @@ function onKey(e: KeyboardEvent) {
<MapVillageMarker :tier="tier(f.village!.points)" :relation="relation(f.village!)" :crown="f.village!.crown" />
</g>
<!-- Groups on the march, over the villages. -->
<g v-for="g in marches" :key="`m${g.m.id}`">
<line :x1="g.ax" :y1="g.ay" :x2="g.bx" :y2="g.by" :stroke="g.colour" stroke-width="2.5" :stroke-dasharray="g.m.type === 'return' ? '6 5' : undefined" stroke-linecap="round" />
<circle :cx="g.bx" :cy="g.by" r="4" :fill="g.colour" />
<g :transform="`translate(${g.x} ${g.y}) scale(${Math.max(0.6, field / 55)})`" class="pointer-events-auto" @pointerdown.stop>
<title>{{ marchTitle(g.m) }}</title>
<MapMarch :size="g.m.size" :colour="g.colour" :flip="g.flip" :motion="motion && !g.waiting" />
</g>
</g>
<rect
v-if="selected"
:x="selected.x * field + 1"

View File

@ -42,7 +42,7 @@ import type {
VillageState,
WorldSummary,
} from '~/types/game'
import type { MapVillage, MapView } from '~/types/map'
import type { MapMovement, MapVillage, MapView } from '~/types/map'
import type { GameAuth, GameWs } from '~/utils/networking'
import {
BARBARIAN_STOCK,
@ -718,24 +718,53 @@ function mapView(state: MockState, user: AuthUser, data: any): MapView {
name: player.name,
points: points(player),
continent: continentOf(x, y),
player: { id: player.user_id, name: owner?.name ?? '?' },
player: { id: player.user_id, name: owner?.name ?? '?', tribe: ((t) => (t ? { id: t.id, tag: t.tag } : null))(mockTribe(state, player.user_id, player.world_id)) },
own: player.user_id === user.id,
crown: false,
relation: player.user_id === user.id ? 'own' : 'none',
})
continue
}
const crown = crownAt(x, y)
if (crown >= 0) {
villages.push({ id: -900 - crown, x, y, name: 'Crown fort', points: 3000, continent: continentOf(x, y), player: null, own: false, crown: true })
villages.push({ id: -900 - crown, x, y, name: 'Crown fort', points: 3000, continent: continentOf(x, y), player: null, own: false, crown: true, relation: 'barbarian' })
continue
}
const barbarian = barbarianAt(x, y)
if (barbarian) {
villages.push({ ...barbarian, x, y, continent: continentOf(x, y), player: null, own: false, crown: false })
villages.push({ ...barbarian, x, y, continent: continentOf(x, y), player: null, own: false, crown: false, relation: 'barbarian' })
}
}
}
return { world_id: Number(data.world_id), size, min: MAP_MIN, center: { x: cx, y: cy }, x: x0, y: y0, w, h, villages }
return { world_id: Number(data.world_id), size, min: MAP_MIN, center: { x: cx, y: cy }, x: x0, y: y0, w, h, villages, movements: mapMovements(state, user) }
}
/** The player's own groups and raids on their villages, sized like the backend's tiers. */
function mapMovements(state: MockState, user: AuthUser): MapMovement[] {
const now = Date.now()
const mine = new Set(state.villages.filter((v) => v.user_id === user.id).map((v) => v.id))
const tier = (units: Units): MapMovement['size'] => {
const n = unitSum(units, () => 1)
return n < 50 ? 'tiny' : n < 250 ? 'small' : n < 1000 ? 'medium' : n < 5000 ? 'large' : 'huge'
}
const end = (id: number) => {
const r = villageRef(state, id)
return { id: r.id, name: r.name, x: r.x, y: r.y }
}
return (state.movements ?? [])
.filter((m) => m.arrives_at > now && (m.user_id === user.id || (m.user_id === RAIDERS && mine.has(m.target_id))))
.map((m) => ({
id: m.id,
type: m.type,
own: m.user_id === user.id,
raid: m.user_id === RAIDERS,
from: end(m.origin_id),
to: end(m.target_id),
sent_at: iso(m.sent_at),
arrives_at: iso(m.arrives_at),
size: tier(m.units),
units: m.user_id === user.id ? counts(m.units) : null,
}))
}
// Rally point: marches, battles and reports, crude stand-ins for app/Engine/Rally.php.

View File

@ -1,6 +1,6 @@
<script setup lang="ts">
import type { DockItem } from '~/components/ui/Dock.vue'
import type { MapVillage } from '~/types/map'
import type { MapRelationKind, MapVillage } from '~/types/map'
definePageMeta({ layout: 'game' })
@ -177,6 +177,10 @@ function onDragEnd() {
if (rounded.value) goTo(rounded.value)
}
const clock = useNow()
const LEGEND: MapRelationKind[] = ['own', 'tribe', 'ally', 'nap', 'enemy', 'none', 'barbarian']
const currentVillage = computed(() => useCurrentWorld().current.value?.villageId ?? null)
// The panels in the dock fold and move like the village's boxes.
const { t } = useI18n()
const mapCards = computed<DockItem[]>(() => [
@ -192,10 +196,15 @@ const counts = computed(() => {
const villages = (view.value?.villages ?? []).filter(
(village) => v && village.x >= v.left - 1 && village.x < v.left + v.cols && village.y >= v.top - 1 && village.y < v.top + v.rows,
)
const by = (r: MapRelationKind) => villages.filter((v) => v.relation === r && !v.crown).length
return {
own: villages.filter((v) => v.own).length,
players: villages.filter((v) => v.player && !v.own).length,
barbarians: villages.filter((v) => !v.player && !v.crown).length,
own: by('own'),
tribe: by('tribe'),
ally: by('ally'),
nap: by('nap'),
enemy: by('enemy'),
none: by('none'),
barbarian: by('barbarian'),
crowns: villages.filter((v) => v.crown).length,
}
})
@ -223,6 +232,8 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
:height="area.h"
:field="field"
:selected="selected"
:current="currentVillage"
:now="clock"
@select="selected = $event"
@hover="hovered = $event"
@drag="onDragMove"
@ -303,10 +314,21 @@ const continent = computed(() => (rounded.value ? continentOf(rounded.value.x, r
<template #legend>
<ul class="panel-body space-y-1.5 text-sm">
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#d9b44a]" /> {{ $t('map.legend.own') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.own }}</span></li>
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#962a1f]" /> {{ $t('map.legend.players') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.players }}</span></li>
<li class="flex items-center gap-2"><span class="size-3 border border-wood-900 bg-[#8b9094]" /> {{ $t('map.legend.barbarians') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.barbarians }}</span></li>
<li class="flex items-center gap-2">
<span class="size-3 border border-wood-900" :style="{ background: RELATION_COLOURS.current }" /> {{ $t('map.legend.current') }}
</li>
<template v-for="r in LEGEND" :key="r">
<li v-if="r === 'own' || r === 'none' || r === 'barbarian' || counts[r]" class="flex items-center gap-2">
<span class="size-3 border border-wood-900" :style="{ background: RELATION_COLOURS[r] }" /> {{ $t(`map.legend.${r}`) }}
<span class="ml-auto tabular-nums text-ink-500">{{ counts[r] }}</span>
</li>
</template>
<li v-if="counts.crowns" class="flex items-center gap-2"><span class="size-3 border border-[#6b4f16] bg-[#d9b44a]" /> {{ $t('map.legend.crowns') }} <span class="ml-auto tabular-nums text-ink-500">{{ counts.crowns }}</span></li>
<li class="flex flex-wrap items-center gap-x-3 gap-y-1 pt-1 text-xs">
<span v-for="(c, k) in MARCH_COLOURS" :key="k" class="inline-flex items-center gap-1">
<span class="inline-block h-0.5 w-4" :style="{ background: c }" />{{ $t(`map.march.legend.${k}`) }}
</span>
</li>
<li class="pt-1 text-xs text-ink-500">{{ $t('map.legend.lines') }}</li>
<li class="text-xs text-ink-500">{{ $t('map.controls') }}<template v-if="busy"> · {{ $t('common.loading') }}</template></li>
</ul>

View File

@ -9,10 +9,30 @@ export interface MapVillage {
points: number
continent: string
/** null for barbarian villages. */
player: { id: number; name: string } | null
player: { id: number; name: string; tribe: { id: number; tag: string } | null } | null
own: boolean
/** A crown fort of the season. */
crown: boolean
/** What the owner is to the viewer: the village's colour. */
relation: MapRelationKind
}
export type MapRelationKind = 'own' | 'tribe' | 'ally' | 'nap' | 'enemy' | 'none' | 'barbarian'
/** A group on the map the player knows of; positions run straight from sent_at to arrives_at. */
export interface MapMovement {
id: number
type: 'attack' | 'support' | 'return'
/** The player's own group; strangers' show their size only. */
own: boolean
/** Raiders from a barbarian camp: they wait there until sent_at. */
raid: boolean
from: { id: number; name: string; x: number; y: number }
to: { id: number; name: string; x: number; y: number }
sent_at: string
arrives_at: string
size: 'tiny' | 'small' | 'medium' | 'large' | 'huge'
units: Record<string, number> | null
}
/** `map.view {world_id, x?, y?, w, h}`: the w × h window around center, kept inside the map. */
@ -29,4 +49,5 @@ export interface MapView {
w: number
h: number
villages: MapVillage[]
movements: MapMovement[]
}

19
app/utils/relations.ts Normal file
View File

@ -0,0 +1,19 @@
import type { MapRelationKind } from '~/types/map'
/** The marker shown: the relation, or the village the player is in right now. */
export type MarkerRelation = MapRelationKind | 'current'
/** Map colours by relation, like Die Stämme: own yellow, the current village white, tribe and allies blue, NAP purple, enemies and other players red, barbarians grey. */
export const RELATION_COLOURS: Record<MarkerRelation, string> = {
current: '#f6f1e4',
own: '#d9b44a',
tribe: '#2f5f9e',
ally: '#5f93cf',
nap: '#7b4f9e',
enemy: '#c4281c',
none: '#8a2a1f',
barbarian: '#8b9094',
}
/** Line and banner colours of groups on the map. */
export const MARCH_COLOURS = { attack: '#c4281c', support: '#2f5f9e', return: '#4f6b2a', raid: '#6b1a12' }

View File

@ -17,6 +17,7 @@ export default {
info: {
title: 'Field',
coordinates: 'Coordinates',
relation: 'Relation',
owner: 'Owner',
points: 'Points',
open: 'Open village',
@ -25,11 +26,24 @@ export default {
empty: 'Empty field',
hint: 'Hover or click a field to see who lives there.',
},
march: {
attack: 'Attack from {from} on {to}',
support: 'Support from {from} for {to}',
return: 'Return from {from} to {to}',
raid: 'Raiders from {from} on {to}',
sizes: { tiny: 'tiny group', small: 'small group', medium: 'medium army', large: 'large army', huge: 'huge army' },
legend: { attack: 'Attack', support: 'Support', return: 'Return', raid: 'Raiders' },
},
legend: {
title: 'Legend',
current: 'This village',
own: 'Your villages',
players: 'Other players',
barbarians: 'Barbarian villages',
tribe: 'Your tribe',
ally: 'Allies',
nap: 'Non-aggression pacts',
enemy: 'Enemies',
none: 'Other players',
barbarian: 'Barbarian villages',
crowns: 'Crown forts',
// {'|'} is a literal pipe: a bare | separates plural forms in vue-i18n.
lines: "Thin lines mark sectors of 10 fields, thick lines the continents of 100 (0{'|'}0 is the corner of K44, K45, K54 and K55).",