feat: a richer world map: forests, lakes and hills in patches, five village sizes with palisades and keeps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fabian @ Blax Software 2026-10-29 00:48:34 +01:00
parent 9df0ee10bc
commit c1176aacc4
3 changed files with 138 additions and 41 deletions

View File

@ -8,7 +8,7 @@ This is the Nuxt client for a browser strategy game in the style of Tribal Wars.
- **`ssr: false` for every target**, so one static build serves both the web and Steam. Code must not rely on Nuxt server routes or SSR-only APIs. - **`ssr: false` for every target**, so one static build serves both the web and Steam. Code must not rely on Nuxt server routes or SSR-only APIs.
- **Transport** is WS-first through the `ws` singleton from `@blax-software/networking`, the same as learn-atc. HTTP is only for login and register, which return the bearer token. Load the `blax-websockets` skill before you write `ws.send` or `ws.listen` code. - **Transport** is WS-first through the `ws` singleton from `@blax-software/networking`, the same as learn-atc. HTTP is only for login and register, which return the bearer token. Load the `blax-websockets` skill before you write `ws.send` or `ws.listen` code.
- **Light Tailwind UI** (Tailwind 4, theme and component classes like `.panel`, `.btn` in `app/assets/css/main.css`) with simple hand-written inline SVG graphics (`app/components/icon/`, colours in `app/utils/palette.ts`). No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo. - **Light Tailwind UI** (Tailwind 4, theme and component classes like `.panel`, `.btn` in `app/assets/css/main.css`) with simple hand-written inline SVG graphics (`app/components/icon/`, colours in `app/utils/palette.ts`). No paid, hosted or licensed assets: no icon packs, web fonts or images from outside the repo.
- **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Levels start at 1. Each type has a model per level tier (1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them. - **The village is a ground-level land view** (`app/components/village/Diorama.vue`, geometry in `app/diorama/`): isometric low-poly, drawn as inline SVG, no WebGL. The land fills the frame edge to edge (no island, no sky), cut to the container's shape; narrow screens scroll sideways. There are no tiles or positions: the server only sends each building's `space` and the village's `space.used/max`, and the client lays everything out deterministically in id order. The village core sits in the middle (headquarters on the plaza, storage, hiding places and rally point around it, inside the wall ring when there is one, a dirt edge without). Resource sites stand outside in their zones: iron mines at the rocky hill (upper left), clay pits on clay ground (lower left), timber camps at the forest edge (lower right), farms with fields (right); dirt roads lead from the gates to each zone and forest fills the rest. Levels start at 1. Each type has a model per level tier (1–4, 5–14, 15+); the wall goes stakes → timber → stone with towers. Buildings are focusable buttons that open their details card; a type that doesn't stand yet keeps an invisible empty plot that opens its build card. Buildings never move or light up on hover: only a click outlines the ground under them. Ambient life is welcome and stays out of the way: flat ground shadows, smoke from chimneys, forges and kilns, villagers walking the roads to the zones they work in; all motion stops under `prefers-reduced-motion`. The same models draw the building portraits on screen headers, the HQ list and the building cards (`VillageBuildingPortrait`). The world map groups forests, lakes and rocky hills by smooth noise of the coordinates, and village markers grow in five sizes with points.
- **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. Keep components small and typed, with state in composables (`useVillage`, `useWorld`). - **Flat medieval colours only**, in the diorama and everywhere else: no gradients (CSS or SVG), no blur or backdrop-blur, no SVG filters or glows, no translucent overlays. Depth comes from the three flat shades per face in `app/diorama/iso.ts`, solid borders and hard shadows. Keep components small and typed, with state in composables (`useVillage`, `useWorld`).
- **One game shell, like Die Stämme.** Pages inside a world (village screens, map, reports) use `layouts/game.vue`: the dark menu bar (`GameMenuBar`: village, map, reports with the unread count, server clock, account menu), then the sticky village bar (`GameVillageBar`: which village, stock with storage meters, incoming troops, and the village's screens as tabs: Overview, Headquarters, Recruit, Rally point, Workforce). On phones the screens move to a bottom tab bar (`GameTabBar`). The bar's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`, so the map and reports keep the village on top. Pages outside a world use `layouts/default.vue` (menu bar only). The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. - **One game shell, like Die Stämme.** Pages inside a world (village screens, map, reports) use `layouts/game.vue`: the dark menu bar (`GameMenuBar`: village, map, reports with the unread count, server clock, account menu), then the sticky village bar (`GameVillageBar`: which village, stock with storage meters, incoming troops, and the village's screens as tabs: Overview, Headquarters, Recruit, Rally point, Workforce). On phones the screens move to a bottom tab bar (`GameTabBar`). The bar's village is the URL's on village screens and the last opened one elsewhere; `GameVillageFrame` holds its one `useVillage()` and shares it through `useVillageContext()`, so the map and reports keep the village on top. Pages outside a world use `layouts/default.vue` (menu bar only). The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens.
- All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`. - All user-facing text goes through i18n keys, with `en` as the first locale. Sources are `i18n/locales/` and `i18n/pages/` (`@blax-software/i18n` layout); register a new page file in `i18n/messageloader.ts`.

View File

@ -1,38 +1,59 @@
<script setup lang="ts"> <script setup lang="ts">
export type MapRelation = 'own' | 'player' | 'barbarian' export type MapRelation = 'own' | 'player' | 'barbarian'
const props = defineProps<{ tier: 1 | 2 | 3; relation: MapRelation }>() const props = defineProps<{ tier: 1 | 2 | 3 | 4 | 5; relation: MapRelation }>()
// Low-poly huts in a 100 × 100 box: each is an isometric block with two lit wall // 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
// town behind a palisade, and a stone keep behind walls. Each block has two lit wall
// faces and a two-facet roof, so it reads as 3D like the village diorama. // faces and a two-facet roof, so it reads as 3D like the village diorama.
const tones = computed(() => const tones = computed(() =>
props.relation === 'barbarian' props.relation === 'barbarian'
? { wallLight: '#d6cfc2', wallDark: '#a99f90', roofLight: '#8e857a', roofDark: '#6c6459' } ? { wallLight: '#d6cfc2', wallDark: '#a99f90', roofLight: '#8e857a', roofDark: '#6c6459' }
: { wallLight: '#e3cfa2', wallDark: '#b49870', roofLight: '#9c4a26', roofDark: '#73321a' }, : { wallLight: '#e3cfa2', wallDark: '#b49870', roofLight: '#9c4a26', roofDark: '#73321a' },
) )
const STONE = { wallLight: '#b9b3a7', wallDark: '#8d877b', roofLight: '#5d636b', roofDark: '#464b52' }
const flag = computed(() => ({ own: '#d9b44a', player: '#962a1f', barbarian: '#8b9094' })[props.relation]) const flag = computed(() => ({ own: '#d9b44a', player: '#962a1f', barbarian: '#8b9094' })[props.relation])
interface Hut { interface Block {
cx: number cx: number
cy: number cy: number
w: number w: number
d: number d: number
h: number h: number
roof: number roof: number
stone?: boolean
} }
const huts = computed<Hut[]>(() => { const blocks = computed<Block[]>(() => {
if (props.tier === 1) return [{ cx: 50, cy: 66, w: 20, d: 11, h: 16, roof: 16 }] switch (props.tier) {
if (props.tier === 2) case 1:
return [{ cx: 50, cy: 66, w: 18, d: 10, h: 14, roof: 14 }]
case 2:
return [ return [
{ cx: 36, cy: 58, w: 16, d: 9, h: 13, roof: 13 }, { cx: 36, cy: 60, w: 15, d: 8, h: 12, roof: 12 },
{ cx: 62, cy: 70, w: 19, d: 10, h: 15, roof: 15 }, { cx: 62, cy: 70, w: 18, d: 10, h: 14, roof: 14 },
] ]
case 3:
return [ return [
{ cx: 50, cy: 50, w: 11, d: 6, h: 34, roof: 14 }, { cx: 50, cy: 52, w: 10, d: 6, h: 30, roof: 13 },
{ cx: 30, cy: 66, w: 15, d: 8, h: 13, roof: 12 }, { cx: 30, cy: 66, w: 15, d: 8, h: 13, roof: 12 },
{ cx: 70, cy: 70, w: 16, d: 9, h: 14, roof: 13 }, { cx: 70, cy: 70, w: 16, d: 9, h: 14, roof: 13 },
] ]
case 4:
return [
{ cx: 50, cy: 46, w: 11, d: 6, h: 34, roof: 14 },
{ cx: 28, cy: 58, w: 14, d: 8, h: 13, roof: 12 },
{ cx: 72, cy: 60, w: 15, d: 8, h: 14, roof: 12 },
{ cx: 48, cy: 70, w: 16, d: 8, h: 12, roof: 11 },
]
default:
return [
{ cx: 50, cy: 50, w: 17, d: 10, h: 38, roof: 16, stone: true },
{ cx: 26, cy: 58, w: 13, d: 7, h: 12, roof: 11 },
{ cx: 74, cy: 60, w: 13, d: 7, h: 12, roof: 11 },
]
}
}) })
const pts = (...p: number[]) => { const pts = (...p: number[]) => {
@ -41,34 +62,54 @@ const pts = (...p: number[]) => {
return out.join(' ') return out.join(' ')
} }
function faces(h: Hut) { function faces(b: Block) {
const { cx, cy, w, d } = h const { cx, cy, w, d } = b
const top = cy - h.h const top = cy - b.h
const apex = top - h.roof const apex = top - b.roof
return { return {
left: pts(cx - w, cy, cx, cy + d, cx, cy + d - h.h, cx - w, top), left: pts(cx - w, cy, cx, cy + d, cx, cy + d - b.h, cx - w, top),
right: pts(cx, cy + d, cx + w, cy, cx + w, top, cx, cy + d - h.h), right: pts(cx, cy + d, cx + w, cy, cx + w, top, cx, cy + d - b.h),
roofLeft: pts(cx - w - 2, top + 1, cx, cy + d - h.h + 2, cx, apex), roofLeft: pts(cx - w - 2, top + 1, cx, cy + d - b.h + 2, cx, apex),
roofRight: pts(cx, cy + d - h.h + 2, cx + w + 2, top + 1, cx, apex), roofRight: pts(cx, cy + d - b.h + 2, cx + w + 2, top + 1, cx, apex),
colors: b.stone ? STONE : tones.value,
} }
} }
/** Points along the front half of the ring a palisade or wall stands on. */
const ring = computed(() =>
Array.from({ length: 15 }, (_, i) => {
const a = Math.PI * (0.02 + (i / 14) * 0.96)
return { x: 50 + Math.cos(a) * 44, y: 66 + Math.sin(a) * 19 }
}),
)
const pole = computed(() => { const pole = computed(() => {
const first = huts.value[0]! const first = blocks.value[0]!
const x = first.cx return { x: first.cx, y: first.cy - first.h - first.roof }
const y = first.cy - first.h - first.roof
return { x, y }
}) })
</script> </script>
<template> <template>
<g> <g>
<ellipse cx="50" cy="74" rx="40" ry="17" fill="#57391f" opacity="0.35" /> <ellipse cx="50" cy="72" rx="42" ry="18" fill="#5f7531" />
<g v-for="(hut, i) in huts" :key="i"> <g v-for="(b, i) in blocks" :key="i">
<polygon :points="faces(hut).left" :fill="tones.wallDark" /> <polygon :points="faces(b).left" :fill="faces(b).colors.wallDark" />
<polygon :points="faces(hut).right" :fill="tones.wallLight" /> <polygon :points="faces(b).right" :fill="faces(b).colors.wallLight" />
<polygon :points="faces(hut).roofLeft" :fill="tones.roofDark" /> <polygon :points="faces(b).roofLeft" :fill="faces(b).colors.roofDark" />
<polygon :points="faces(hut).roofRight" :fill="tones.roofLight" /> <polygon :points="faces(b).roofRight" :fill="faces(b).colors.roofLight" />
</g>
<!-- A town's palisade or a keep's stone wall along the front of the ring. -->
<g v-if="tier === 4">
<rect v-for="(p, i) in ring" :key="i" :x="p.x - 2" :y="p.y - 9" width="4" height="10" :fill="i % 2 ? '#6a4526' : '#8a5f38'" />
</g>
<g v-else-if="tier === 5">
<polygon
v-for="(p, i) in ring.slice(0, -1)"
:key="i"
:points="pts(p.x, p.y, ring[i + 1]!.x, ring[i + 1]!.y, ring[i + 1]!.x, ring[i + 1]!.y - 10, p.x, p.y - 10)"
:fill="i % 2 ? '#8d877b' : '#a39d92'"
/>
<rect v-for="i in [0, 7, 14]" :key="`t${i}`" :x="ring[i]!.x - 4" :y="ring[i]!.y - 16" width="8" height="16" fill="#847e74" />
</g> </g>
<line :x1="pole.x" :y1="pole.y" :x2="pole.x" :y2="pole.y - 20" stroke="#4a3b2e" stroke-width="2" /> <line :x1="pole.x" :y1="pole.y" :x2="pole.x" :y2="pole.y - 20" stroke="#4a3b2e" stroke-width="2" />
<polygon :points="pts(pole.x, pole.y - 20, pole.x + 15, pole.y - 15, pole.x, pole.y - 10)" :fill="flag" stroke="#2b2118" stroke-width="0.8" /> <polygon :points="pts(pole.x, pole.y - 20, pole.x + 15, pole.y - 15, pole.x, pole.y - 10)" :fill="flag" stroke="#2b2118" stroke-width="0.8" />

View File

@ -39,6 +39,31 @@ const hash = (x: number, y: number) => {
return ((h ^ (h >>> 16)) >>> 0) / 4294967296 return ((h ^ (h >>> 16)) >>> 0) / 4294967296
} }
const GRASS = ['#7f9645', '#78903f', '#86994b', '#73893c'] const GRASS = ['#7f9645', '#78903f', '#86994b', '#73893c']
const WATER = '#5f7f87'
/** Smooth value noise: neighbouring fields get similar values, so terrain comes in patches. */
const smooth = (t: number) => t * t * (3 - 2 * t)
function noise(x: number, y: number, size: number, seed: number) {
const gx = x / size
const gy = y / size
const ix = Math.floor(gx)
const iy = Math.floor(gy)
const fx = smooth(gx - ix)
const fy = smooth(gy - iy)
const at = (a: number, b: number) => hash(a * 7 + seed * 101, b * 13 - seed * 37)
const top = at(ix, iy) + (at(ix + 1, iy) - at(ix, iy)) * fx
const bottom = at(ix, iy + 1) + (at(ix + 1, iy + 1) - at(ix, iy + 1)) * fx
return top + (bottom - top) * fy
}
type Ground = 'grass' | 'forest' | 'water' | 'hill'
/** Lakes, rocky hills and forests in patches; a village's field is always open land. */
function groundAt(x: number, y: number): Ground {
if (noise(x, y, 11, 1) < 0.17) return 'water'
if (noise(x, y, 8, 2) > 0.8) return 'hill'
if (noise(x, y, 6, 3) > 0.6 || hash(x, y) < 0.05) return 'forest'
return 'grass'
}
// Whole fields touching the visible area. These only change when an edge crosses a // Whole fields touching the visible area. These only change when an edge crosses a
// field, so dragging moves one transform instead of re-rendering every field. // field, so dragging moves one transform instead of re-rendering every field.
@ -52,7 +77,11 @@ interface Field {
y: number y: number
grass: string grass: string
village: MapVillage | null village: MapVillage | null
forest: number[] | null ground: Ground
/** Trees as [x, y, size] in the field's 100 × 100 box, back to front. */
trees: [number, number, number][]
/** Sides of a lake field that meet land and get a shore. */
shore: { top: boolean; right: boolean; bottom: boolean; left: boolean } | null
} }
const fields = computed<Field[]>(() => { const fields = computed<Field[]>(() => {
@ -61,13 +90,23 @@ const fields = computed<Field[]>(() => {
for (let x = x0.value; x < x1.value; x++) { for (let x = x0.value; x < x1.value; x++) {
const r = hash(x, y) const r = hash(x, y)
const village = villageAt.value.get(`${x}|${y}`) ?? null const village = villageAt.value.get(`${x}|${y}`) ?? null
const ground: Ground = village ? 'grass' : groundAt(x, y)
const land = (gx: number, gy: number) => !!villageAt.value.get(`${gx}|${gy}`) || groundAt(gx, gy) !== 'water'
// Deeper in a forest, more and bigger trees.
const count = ground === 'forest' ? 2 + Math.round(noise(x, y, 6, 3) * 4) : 0
const trees = Array.from({ length: count }, (_, i): [number, number, number] => [
14 + hash(x * 3 + i, y) * 72,
28 + hash(x, y * 3 + i) * 56,
0.75 + hash(x + i, y + i) * 0.5,
]).sort((a, b) => a[1] - b[1])
out.push({ out.push({
x, x,
y, y,
grass: GRASS[Math.floor(r * GRASS.length)]!, grass: GRASS[Math.floor(r * GRASS.length)]!,
village, village,
// About one empty field in five is forest: 2–3 trees at hashed spots. ground,
forest: !village && r < 0.2 ? [hash(x + 1, y), hash(x, y + 1), hash(x + 2, y + 3)] : null, trees,
shore: ground === 'water' ? { top: land(x, y - 1), right: land(x + 1, y), bottom: land(x, y + 1), left: land(x - 1, y) } : null,
}) })
} }
} }
@ -75,7 +114,8 @@ const fields = computed<Field[]>(() => {
}) })
const villageFields = computed(() => fields.value.filter((f) => f.village)) const villageFields = computed(() => fields.value.filter((f) => f.village))
const tier = (points: number): 1 | 2 | 3 => (points < 60 ? 1 : points < 200 ? 2 : 3) /** 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) => (v.own ? 'own' : v.player ? 'player' : 'barbarian')
// Sector lines every 10 fields, continent borders every 100. // Sector lines every 10 fields, continent borders every 100.
@ -201,9 +241,25 @@ function onKey(e: KeyboardEvent) {
<!-- Fields sit at their world position; panning only moves this group. --> <!-- Fields sit at their world position; panning only moves this group. -->
<g :transform="`translate(${shiftX} ${shiftY})`"> <g :transform="`translate(${shiftX} ${shiftY})`">
<g v-for="f in fields" :key="`${f.x}|${f.y}`" @pointerenter="emit('hover', f.village)"> <g v-for="f in fields" :key="`${f.x}|${f.y}`" @pointerenter="emit('hover', f.village)">
<rect :x="f.x * field" :y="f.y * field" :width="field" :height="field" :fill="f.grass" /> <rect :x="f.x * field" :y="f.y * field" :width="field" :height="field" :fill="f.ground === 'water' ? WATER : f.grass" />
<g v-if="f.forest" :transform="`translate(${f.x * field} ${f.y * field}) scale(${field / 100})`"> <g v-if="f.ground !== 'grass'" :transform="`translate(${f.x * field} ${f.y * field}) scale(${field / 100})`">
<g v-for="(r, i) in f.forest" :key="i" :transform="`translate(${18 + r * 52 + i * 8} ${34 + ((r * 7) % 1) * 40 + i * 6})`"> <template v-if="f.shore">
<!-- Sandy shore where the lake meets land, and a ripple. -->
<rect v-if="f.shore.top" x="0" y="0" width="100" height="9" fill="#b8a173" />
<rect v-if="f.shore.bottom" x="0" y="91" width="100" height="9" fill="#b8a173" />
<rect v-if="f.shore.left" x="0" y="0" width="9" height="100" fill="#b8a173" />
<rect v-if="f.shore.right" x="91" y="0" width="9" height="100" fill="#b8a173" />
<path :d="`M${28 + hash(f.x, f.y) * 30} 50h18M${40 + hash(f.y, f.x) * 20} 64h12`" stroke="#7e9da3" stroke-width="3" stroke-linecap="round" />
</template>
<g v-else-if="f.ground === 'hill'">
<ellipse cx="52" cy="70" rx="40" ry="16" fill="#6f7f3d" />
<polygon points="18,72 40,30 58,72" fill="#8d877b" />
<polygon points="40,30 58,72 64,60" fill="#6f6a60" />
<polygon points="48,74 68,42 86,74" fill="#a39d92" />
<polygon points="68,42 86,74 90,66" fill="#7c776a" />
</g>
<g v-for="(tr, i) in f.trees" :key="i" :transform="`translate(${tr[0]} ${tr[1]}) scale(${tr[2]})`">
<ellipse cx="4" cy="26" rx="12" ry="4" fill="#5f7531" />
<rect x="-2" y="18" width="4" height="9" fill="#57391f" /> <rect x="-2" y="18" width="4" height="9" fill="#57391f" />
<polygon points="0,-10 -13,20 0,16" fill="#2f5222" /> <polygon points="0,-10 -13,20 0,16" fill="#2f5222" />
<polygon points="0,-10 13,20 0,16" fill="#46702f" /> <polygon points="0,-10 13,20 0,16" fill="#46702f" />