feat: no outlines in the village; doors, windows and plinths, two-tier firs and shaded villagers; workers in the close-up in depth order
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
da7b644b79
commit
fda81113ec
|
|
@ -9,7 +9,7 @@ This is the Nuxt client for a browser strategy game in the style of Tribal Wars.
|
||||||
- **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.
|
||||||
- **Dense and plain, like the old browser strategy games** (the reference is Die Stämme; notes and screenshots in the sibling repo `game-village-politics-research` (`../game-village-politics-research/die-staemme/`), kept out of this repo). A 16 px root (17 px from 1800 px wide; rem sizes only, `text-sm` for body text, no fixed `text-[13px]`), square frames with thin lines, tan header bands, tight table rows (`.grid-table`), small squared buttons (`.btn-primary` dark wood, `.btn-attack` red for attacks only), thin notice bars. Actions are buttons, not text links: `.btn` for screen links and commands, `.btn-fill` for the "(20)" that fills an amount field; names inside lists and tables stay links. Bigger text must not add line wraps: keep rows `whitespace-nowrap` where they were one line. No rounded cards, pills, big padding or decorative icons: an icon only where it carries meaning. Theme and component classes live in `app/assets/css/main.css`; hand-written inline SVG graphics in `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, and nothing copied from Die Stämme.
|
- **Dense and plain, like the old browser strategy games** (the reference is Die Stämme; notes and screenshots in the sibling repo `game-village-politics-research` (`../game-village-politics-research/die-staemme/`), kept out of this repo). A 16 px root (17 px from 1800 px wide; rem sizes only, `text-sm` for body text, no fixed `text-[13px]`), square frames with thin lines, tan header bands, tight table rows (`.grid-table`), small squared buttons (`.btn-primary` dark wood, `.btn-attack` red for attacks only), thin notice bars. Actions are buttons, not text links: `.btn` for screen links and commands, `.btn-fill` for the "(20)" that fills an amount field; names inside lists and tables stay links. Bigger text must not add line wraps: keep rows `whitespace-nowrap` where they were one line. No rounded cards, pills, big padding or decorative icons: an icon only where it carries meaning. Theme and component classes live in `app/assets/css/main.css`; hand-written inline SVG graphics in `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, and nothing copied from Die Stämme.
|
||||||
- **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 enter the building (`buildingRoute`): the headquarters opens construction, the rally point its commands, a military building its recruiting, every other building its own screen (`/village/<id>/building/<bid>`); each of these screens starts with `VillageBuildingHeader`: a close-up (`VillageCloseup`, `app/diorama/closeup.ts`: the building large on its ground, its props and forest, its assigned workers walking to where they work and back carrying what they make), what it does now and one level up (`effects`/`next_effects` from the server), workers, priority, upgrade and demolish. The open building stays outlined in the village, and clicking it again returns to the overview. Buildings are clickable anywhere on their outline (`hit`, a convex hull round their polygons and ground ring), the thin wall also along a wide band on its ring, and their level badges and countdowns as well; 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. Map coordinates run around 0|0, negative included (−500 to 499 on a 1000-field map, lowest value from `map.view`'s `min`); continents are named from the top-left like Die Stämme, so 0|0 is the corner of K44, K45, K54 and K55. Use `app/utils/map.ts` for bounds and continents, never `0` or `500` literals.
|
- **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 enter the building (`buildingRoute`): the headquarters opens construction, the rally point its commands, a military building its recruiting, every other building its own screen (`/village/<id>/building/<bid>`); each of these screens starts with `VillageBuildingHeader`: a close-up (`VillageCloseup`, `app/diorama/closeup.ts`: the building large on its ground, its props and forest, its assigned workers walking to where they work and back carrying what they make), what it does now and one level up (`effects`/`next_effects` from the server), workers, priority, upgrade and demolish. The open building stays outlined in the village, and clicking it again returns to the overview. Buildings are clickable anywhere on their outline (`hit`, a convex hull round their polygons and ground ring), the thin wall also along a wide band on its ring, and their level badges and countdowns as well; 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. Map coordinates run around 0|0, negative included (−500 to 499 on a 1000-field map, lowest value from `map.view`'s `min`); continents are named from the top-left like Die Stämme, so 0|0 is the corner of K44, K45, K54 and K55. Use `app/utils/map.ts` for bounds and continents, never `0` or `500` literals.
|
||||||
- **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. Surfaces carry small repeating patterns generated in code at startup (`app/utils/patterns.ts` → `--pat-*` custom properties, set by `plugins/patterns.client.ts`, painted per `bg-parchment-*`/`bg-wood-*` class and on `.panel`, `.frame`, `.btn-primary` in `main.css`): parchment flecks, woven header bands with a stitched hem, wood grain; flat opaque shades a step off the surface, never images or opacity. Keep them minimal. One look for every part: each header band is `.panel-head` with a `.panel-title`, everything that floats over the village has the `.float` hard shadow and sits in a bordered frame, and every vertical scroll area is `.scroll-y`, whose bar always shows so content never shifts sideways; the one scrollbar style (wood handle with notches in a parchment track) lives in `main.css`. Pages keep the page scrollbar; the fullscreen village sets `html.stage` and never scrolls. 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. In the diorama there are no outlines: a polygon strokes in its own fill only to close seams, detail comes from a few large shaded panels (a stone plinth, a door and windows from `house()`/`openings()`, two-tier firs, people as shaded shapes in `VillageWalker`), not from many small nodes. A face that must draw over its wall (doors, windows) sets `depth`; offsets and `shift()` carry it along. In the close-up, workers are sorted in among the objects by depth. Surfaces carry small repeating patterns generated in code at startup (`app/utils/patterns.ts` → `--pat-*` custom properties, set by `plugins/patterns.client.ts`, painted per `bg-parchment-*`/`bg-wood-*` class and on `.panel`, `.frame`, `.btn-primary` in `main.css`): parchment flecks, woven header bands with a stitched hem, wood grain; flat opaque shades a step off the surface, never images or opacity. Keep them minimal. One look for every part: each header band is `.panel-head` with a `.panel-title`, everything that floats over the village has the `.float` hard shadow and sits in a bordered frame, and every vertical scroll area is `.scroll-y`, whose bar always shows so content never shifts sideways; the one scrollbar style (wood handle with notches in a parchment track) lives in `main.css`. Pages keep the page scrollbar; the fullscreen village sets `html.stage` and never scrolls. Keep components small and typed, with state in composables (`useVillage`, `useWorld`).
|
||||||
- **The village fills the screen.** On the village's own screens (`/village/<id>/…`) `GameVillageFrame` draws the diorama fixed across the whole browser window and docks everything over it, solid and opaque: the menu and the village bar along the top, the overview boxes in a right column (on phones a bottom sheet on the overview), and the open screen (headquarters, recruit, rally point, workforce) in a `UiWindow` on the left that folds and closes back to the overview; on the overview the left slot holds the build card of an empty plot picked in the village (`useVillageSelection`). Screen grids inside a window use container queries (`@4xl:`), not viewport breakpoints. The village scales to fit, no pan: the frame measures what the bars, the right column, the phone tab bar and the bottom sheet cover (`inset`), `buildScene` fits the whole village into the rest, and ground and forest are generated for the whole stage, so nothing of the village is ever cut off. Windows are docked now and meant to become draggable later, so `UiWindow` holds no position logic. This is where the game deliberately leaves Die Stämme's look behind.
|
- **The village fills the screen.** On the village's own screens (`/village/<id>/…`) `GameVillageFrame` draws the diorama fixed across the whole browser window and docks everything over it, solid and opaque: the menu and the village bar along the top, the overview boxes in a right column (on phones a bottom sheet on the overview), and the open screen (headquarters, recruit, rally point, workforce) in a `UiWindow` on the left that folds and closes back to the overview; on the overview the left slot holds the build card of an empty plot picked in the village (`useVillageSelection`). Screen grids inside a window use container queries (`@4xl:`), not viewport breakpoints. The village scales to fit, no pan: the frame measures what the bars, the right column, the phone tab bar and the bottom sheet cover (`inset`), `buildScene` fits the whole village into the rest, and ground and forest are generated for the whole stage, so nothing of the village is ever cut off. Windows are docked now and meant to become draggable later, so `UiWindow` holds no position logic. This is where the game deliberately leaves Die Stämme's look behind.
|
||||||
- **One game shell for the rest.** The map and reports sit in one centred column (1100 px). All world pages use `layouts/game.vue` (on village screens `GameVillageFrame` draws the same parts over the village): the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`, in two pieces with the village showing between them: on the left the quick bar with the village's screens over the village row, on the right the stock in thin cells and incoming troops; the space between lets clicks through), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header'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()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. The village row starts with the quest book (`QuestBook`, a native `<dialog>` without a veil): it opens by itself when `quests.claimable` goes up, and a goal's "show me" opens its screen, a building goal the headquarters with `?hint=<type>` marking that row.
|
- **One game shell for the rest.** The map and reports sit in one centred column (1100 px). All world pages use `layouts/game.vue` (on village screens `GameVillageFrame` draws the same parts over the village): the dark main menu (`GameMenuBar`: village, map, reports with its count inline, each with a hover dropdown of its sub-pages; server clock; account dropdown), then the village header (`GameVillageBar`, in two pieces with the village showing between them: on the left the quick bar with the village's screens over the village row, on the right the stock in thin cells and incoming troops; the space between lets clicks through), thin notices, and the content in a `.frame`. On phones the screens move to a bottom tab bar (`GameTabBar`). The header'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()`. Pages outside a world use `layouts/default.vue` (menu only). A page has one of two shapes: a title with box tabs (`UiSubTabs`: buildings like the rally point) or a title with a sub-menu on the left (`UiSideMenu`: lists like reports). One key per screen (`useShortcuts`): V overview, H headquarters, T recruit, P rally point, W workforce, M map, R reports. The overview stays clean: the village and a narrow column of boxes (incoming attacks, production, units, population, construction); tables live on the building screens. The map shows a popup over a hovered village and actions under a clicked one. The village row starts with the quest book (`QuestBook`, a native `<dialog>` without a veil): it opens by itself when `quests.claimable` goes up, and a goal's "show me" opens its screen, a building goal the headquarters with `?hint=<type>` marking that row.
|
||||||
- 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`. vue-i18n reads a bare `|` as a plural separator and drops what follows, so coordinates in messages are written `"{x}{'|'}{y}"` inside a double-quoted string.
|
- 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`. vue-i18n reads a bare `|` as a plural separator and drops what follows, so coordinates in messages are written `"{x}{'|'}{y}"` inside a double-quoted string.
|
||||||
|
|
|
||||||
|
|
@ -35,20 +35,17 @@ const SHIRTS = ['#6b4f3a', '#7b1e16', '#3d5a26', '#57391f', '#5a5f63']
|
||||||
<polygon v-for="(p, i) in scene.terrain" :key="`t${i}`" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
<polygon v-for="(p, i) in scene.terrain" :key="`t${i}`" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
||||||
<polygon v-for="(p, i) in scene.decals" :key="`d${i}`" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
<polygon v-for="(p, i) in scene.decals" :key="`d${i}`" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
||||||
</g>
|
</g>
|
||||||
<g v-if="motion" stroke="#2f2013" stroke-width="0.5">
|
<template v-for="(l, i) in scene.layers" :key="l.key">
|
||||||
<g v-for="(w, i) in scene.walks" :key="`walk-${i}-${w.d.length}`">
|
<g v-if="l.walk">
|
||||||
<g transform="scale(2.6)">
|
<template v-if="motion">
|
||||||
<rect x="-1.7" y="-7" width="3.4" height="5.4" rx="0.6" :fill="SHIRTS[i % SHIRTS.length]" />
|
<VillageWalker transform="scale(2.6)" :shirt="SHIRTS[i % SHIRTS.length]!" :carry="l.walk.carry" />
|
||||||
<circle cy="-8.8" r="1.7" fill="#d8a982" />
|
<animateMotion :dur="`${l.walk.seconds}s`" :begin="`${l.walk.delay}s`" repeatCount="indefinite" keyPoints="0;1;0" keyTimes="0;0.5;1" calcMode="linear" :path="l.walk.d" />
|
||||||
<path d="M-1 -1.6v1.8M1 -1.6v1.8" fill="none" stroke-width="0.9" />
|
</template>
|
||||||
<rect v-if="w.carry" x="0.6" y="-9.6" width="3.6" height="2.4" :fill="w.carry" />
|
|
||||||
</g>
|
</g>
|
||||||
<animateMotion :dur="`${w.seconds}s`" :begin="`${w.delay}s`" repeatCount="indefinite" keyPoints="0;1;0" keyTimes="0;0.5;1" calcMode="linear" :path="w.d" />
|
<g v-else v-memo="[l]" stroke-width="0.6" stroke-linejoin="round">
|
||||||
</g>
|
<polygon v-for="(p, j) in l.polys" :key="j" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
||||||
</g>
|
|
||||||
<g v-for="obj in scene.objects" :key="obj.key" v-memo="[obj]" stroke-width="0.6" stroke-linejoin="round">
|
|
||||||
<polygon v-for="(p, i) in obj.polys" :key="i" :points="p.points" :fill="p.fill" :stroke="p.stroke" />
|
|
||||||
</g>
|
</g>
|
||||||
|
</template>
|
||||||
</svg>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -126,14 +126,10 @@ const timers = computed(() => {
|
||||||
</g>
|
</g>
|
||||||
|
|
||||||
<!-- Villagers on their way to work and back, under the buildings they walk into. -->
|
<!-- Villagers on their way to work and back, under the buildings they walk into. -->
|
||||||
<g v-if="motion" class="pointer-events-none" stroke="#2f2013" stroke-width="0.5">
|
<g v-if="motion" class="pointer-events-none">
|
||||||
<template v-for="(w, i) in scene.walks" :key="`walk-${i}-${w.d.length}`">
|
<template v-for="(w, i) in scene.walks" :key="`walk-${i}-${w.d.length}`">
|
||||||
<g v-for="n in w.count" :key="n">
|
<g v-for="n in w.count" :key="n">
|
||||||
<g transform="scale(1.35)">
|
<VillageWalker transform="scale(1.35)" :shirt="SHIRTS[(i * 3 + n) % SHIRTS.length]!" />
|
||||||
<rect x="-1.7" y="-7" width="3.4" height="5.4" rx="0.6" :fill="SHIRTS[(i * 3 + n) % SHIRTS.length]" />
|
|
||||||
<circle cy="-8.8" r="1.7" fill="#d8a982" />
|
|
||||||
<path d="M-1 -1.6v1.8M1 -1.6v1.8" fill="none" stroke-width="0.9" />
|
|
||||||
</g>
|
|
||||||
<animateMotion
|
<animateMotion
|
||||||
:dur="`${w.seconds}s`"
|
:dur="`${w.seconds}s`"
|
||||||
:begin="`${-((n - 1) * w.seconds) / w.count - i * 3}s`"
|
:begin="`${-((n - 1) * w.seconds) / w.count - i * 3}s`"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { scale } from '~/diorama/iso'
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
shirt: string
|
||||||
|
/** What the villager carries on the shoulder, as a colour; none when empty-handed. */
|
||||||
|
carry?: string | null
|
||||||
|
}>()
|
||||||
|
const shirtShade = computed(() => scale(props.shirt, 0.72))
|
||||||
|
const carryTop = computed(() => (props.carry ? scale(props.carry, 1.15) : ''))
|
||||||
|
const carryShade = computed(() => (props.carry ? scale(props.carry, 0.7) : ''))
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!-- A villager in a few flat, shaded panels: legs, a two-tone shirt, head and hair, a load. -->
|
||||||
|
<template>
|
||||||
|
<g>
|
||||||
|
<path d="M-1.5 -2.4h1.2V0h-1.2zM0.3 -2.4h1.2V0h-1.2z" fill="#3a2a1c" />
|
||||||
|
<path d="M-1.9 -6.9L0 -7.3V-2.2H-1.7z" :fill="shirt" />
|
||||||
|
<path d="M0 -7.3L1.9 -6.9L1.7 -2.2H0z" :fill="shirtShade" />
|
||||||
|
<circle cy="-8.9" r="1.65" fill="#d8a982" />
|
||||||
|
<path d="M-1.7 -9.1Q0 -11.5 1.7 -9.1Q0 -9.9 -1.7 -9.1z" fill="#4a3220" />
|
||||||
|
<template v-if="carry">
|
||||||
|
<path d="M0.3 -9.3L3.1 -9.8L4.7 -9L1.9 -8.5z" :fill="carryTop" />
|
||||||
|
<path d="M0.3 -9.3L1.9 -8.5V-6.9L0.3 -7.7z" :fill="carry" />
|
||||||
|
<path d="M1.9 -8.5L4.7 -9V-7.4L1.9 -6.9z" :fill="carryShade" />
|
||||||
|
</template>
|
||||||
|
</g>
|
||||||
|
</template>
|
||||||
|
|
@ -14,9 +14,18 @@ export interface Closeup {
|
||||||
height: number
|
height: number
|
||||||
terrain: Poly[]
|
terrain: Poly[]
|
||||||
decals: Poly[]
|
decals: Poly[]
|
||||||
objects: { key: string; polys: Poly[] }[]
|
/**
|
||||||
/** One per worker shown: a screen path walked there and back, with what they carry. */
|
* Back to front: objects, and one entry per worker shown (a screen path walked there
|
||||||
walks: { d: string; seconds: number; delay: number; carry: string | null }[]
|
* and back, with what they carry), sorted in among the objects by depth.
|
||||||
|
*/
|
||||||
|
layers: ({ key: string; polys: Poly[]; walk?: undefined } | { key: string; walk: Walk; polys?: undefined })[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Walk {
|
||||||
|
d: string
|
||||||
|
seconds: number
|
||||||
|
delay: number
|
||||||
|
carry: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
type Kind = 'timber' | 'clay' | 'iron' | 'farm' | 'wall' | 'core'
|
type Kind = 'timber' | 'clay' | 'iron' | 'farm' | 'wall' | 'core'
|
||||||
|
|
@ -46,9 +55,8 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
|
||||||
const decals: Face[] = [plane(disc(0, 0, S * 2.3, 16, 7, 0.5), GROUND[kind])]
|
const decals: Face[] = [plane(disc(0, 0, S * 2.3, 16, 7, 0.5), GROUND[kind])]
|
||||||
const shadows: Face[] = []
|
const shadows: Face[] = []
|
||||||
const taken: { x: number; y: number; r: number }[] = [{ x: 0, y: 0, r: S * 1.5 }]
|
const taken: { x: number; y: number; r: number }[] = [{ x: 0, y: 0, r: S * 1.5 }]
|
||||||
/** Where workers go; the door is at the front, towards the viewer. */
|
/** Where workers go; each leaves the building on the side that faces their spot. */
|
||||||
const spots: V2[] = []
|
const spots: V2[] = []
|
||||||
const door: V2 = at(deg(45), S * 0.95)
|
|
||||||
const put = (key: string, x: number, y: number, faces: Face[], r: number) => {
|
const put = (key: string, x: number, y: number, faces: Face[], r: number) => {
|
||||||
objects.push({ key, depth: x + y, polys: toPolys(faces) })
|
objects.push({ key, depth: x + y, polys: toPolys(faces) })
|
||||||
taken.push({ x, y, r })
|
taken.push({ x, y, r })
|
||||||
|
|
@ -137,24 +145,32 @@ export function buildCloseup(type: BuildingType, level: number, workers: number,
|
||||||
maxY = minY + h
|
maxY = minY + h
|
||||||
const view = { x: minX, y: minY, w, h }
|
const view = { x: minX, y: minY, w, h }
|
||||||
|
|
||||||
|
// A worker sorts at the depth of the point of their path furthest back, so the building
|
||||||
|
// hides those who work behind it and those in front walk over it.
|
||||||
const shown = Math.min(MAX_WALKERS, Math.max(0, workers))
|
const shown = Math.min(MAX_WALKERS, Math.max(0, workers))
|
||||||
const walks: Closeup['walks'] = []
|
const walkers: { key: string; depth: number; walk: Walk }[] = []
|
||||||
for (let i = 0; i < shown && spots.length; i++) {
|
for (let i = 0; i < shown && spots.length; i++) {
|
||||||
const spot = spots[i % spots.length]!
|
const spot = spots[i % spots.length]!
|
||||||
const path = kind === 'wall' ? [at(deg(i * 90), S * 2.0), at(deg(i * 90 + 45), S * 2.0), at(deg(i * 90 + 90), S * 2.0)] : [door, spot]
|
const path: V2[] =
|
||||||
const length = Math.hypot(spot[0] - door[0], spot[1] - door[1])
|
kind === 'wall'
|
||||||
|
? [0, 15, 30, 45, 60, 75, 90].map((d) => at(deg(i * 90 + d), S * 2.0))
|
||||||
|
: [at(Math.atan2(spot[1], spot[0]), S * 1.5), spot]
|
||||||
|
const length = path.slice(1).reduce((n, p, k) => n + Math.hypot(p[0] - path[k]![0], p[1] - path[k]![1]), 0)
|
||||||
const seconds = Math.max(7, (length / U) * 2.4)
|
const seconds = Math.max(7, (length / U) * 2.4)
|
||||||
walks.push({ d: line(path), seconds, delay: -(i * seconds) / Math.max(1, shown), carry: CARRY[kind] })
|
walkers.push({
|
||||||
|
key: `walker${i}`,
|
||||||
|
depth: Math.min(...path.map(([x, y]) => x + y)),
|
||||||
|
walk: { d: line(path), seconds, delay: -(i * seconds) / Math.max(1, shown), carry: CARRY[kind] },
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
objects.sort((a, b) => a.depth - b.depth)
|
const layers = [...objects, ...walkers].sort((a, b) => a.depth - b.depth)
|
||||||
return {
|
return {
|
||||||
viewBox: `${view.x.toFixed(1)} ${view.y.toFixed(1)} ${w.toFixed(1)} ${h.toFixed(1)}`,
|
viewBox: `${view.x.toFixed(1)} ${view.y.toFixed(1)} ${w.toFixed(1)} ${h.toFixed(1)}`,
|
||||||
width: w,
|
width: w,
|
||||||
height: h,
|
height: h,
|
||||||
terrain: ground(view),
|
terrain: ground(view),
|
||||||
decals: [...decals, ...shadows].flatMap((face) => toPolys([face])),
|
decals: [...decals, ...shadows].flatMap((face) => toPolys([face])),
|
||||||
objects: objects.map(({ key, polys }) => ({ key, polys })),
|
layers: layers.map((l) => ('walk' in l ? { key: l.key, walk: l.walk } : { key: l.key, polys: l.polys })),
|
||||||
walks,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ export interface Face {
|
||||||
twoSided?: boolean
|
twoSided?: boolean
|
||||||
/** Skip light shading, e.g. for fire. */
|
/** Skip light shading, e.g. for fire. */
|
||||||
flat?: boolean
|
flat?: boolean
|
||||||
|
/** Painter depth when the centroid would get it wrong: doors and windows sit just over their wall. */
|
||||||
|
depth?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Poly {
|
export interface Poly {
|
||||||
|
|
@ -119,11 +121,12 @@ export function toPolys(faces: Face[], offset: V3 = [0, 0, 0]): Poly[] {
|
||||||
}
|
}
|
||||||
const fill = f.flat ? f.color : shade(f.color, n)
|
const fill = f.flat ? f.color : shade(f.color, n)
|
||||||
out.push({
|
out.push({
|
||||||
depth: depthOf(centroid(pts)),
|
depth: f.depth !== undefined ? f.depth + offset[0] + offset[1] + offset[2] : depthOf(centroid(pts)),
|
||||||
poly: {
|
poly: {
|
||||||
points: pts.map((p) => project(p).map((v) => v.toFixed(1)).join(',')).join(' '),
|
points: pts.map((p) => project(p).map((v) => v.toFixed(1)).join(',')).join(' '),
|
||||||
fill,
|
fill,
|
||||||
stroke: scale(fill, 0.86),
|
// The fill colour again: closes hairline seams between panels without drawing an outline.
|
||||||
|
stroke: fill,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -140,6 +143,10 @@ export function orient(pts: V3[], inside: V3): V3[] {
|
||||||
|
|
||||||
// Shapes. Bases are counter-clockwise seen from above.
|
// Shapes. Bases are counter-clockwise seen from above.
|
||||||
|
|
||||||
|
const STONE = '#948d82'
|
||||||
|
const DOOR = '#4a3220'
|
||||||
|
const WINDOW = '#2f2620'
|
||||||
|
|
||||||
export function rect(cx: number, cy: number, w: number, d: number): V2[] {
|
export function rect(cx: number, cy: number, w: number, d: number): V2[] {
|
||||||
return [
|
return [
|
||||||
[cx - w / 2, cy - d / 2],
|
[cx - w / 2, cy - d / 2],
|
||||||
|
|
@ -217,7 +224,38 @@ export function gable(
|
||||||
return faces.map((f) => ({ ...f, pts: orient(f.pts, inside) }))
|
return faces.map((f) => ({ ...f, pts: orient(f.pts, inside) }))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A box with a gable roof: the most common house. */
|
/** A dark panel on the outside of a wall facing +x or +y: a door or a window. */
|
||||||
|
function wallPanel(face: 'x' | 'y', at: number, along: number, z0: number, w: number, h: number, wallDepth: number, color: string): Face {
|
||||||
|
const a0 = along - w / 2
|
||||||
|
const a1 = along + w / 2
|
||||||
|
const pts: V3[] =
|
||||||
|
face === 'x'
|
||||||
|
? [[at, a0, z0], [at, a1, z0], [at, a1, z0 + h], [at, a0, z0 + h]]
|
||||||
|
: [[a0, at, z0], [a1, at, z0], [a1, at, z0 + h], [a0, at, z0 + h]]
|
||||||
|
return { pts, color, twoSided: true, flat: true, depth: wallDepth + 0.05 }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A door on the wall towards the lower right and windows on the one towards the lower
|
||||||
|
* left of a box standing on z0, as flat dark panels just outside the walls.
|
||||||
|
*/
|
||||||
|
export function openings(cx: number, cy: number, w: number, d: number, z0: number, h: number): Face[] {
|
||||||
|
const ex = cx + w / 2 + 0.25
|
||||||
|
const ey = cy + d / 2 + 0.25
|
||||||
|
const door = Math.min(d * 0.28, h * 0.5)
|
||||||
|
const win = Math.min(w, d) * 0.16
|
||||||
|
const windows = w > d * 1.15 ? [cx - w * 0.22, cx + w * 0.22] : [cx]
|
||||||
|
return [
|
||||||
|
wallPanel('x', ex, cy + d * 0.12, z0, door, (h - z0) * 0.62, ex + cy + h * 0.5, DOOR),
|
||||||
|
...windows.map((wx) => wallPanel('y', ey, wx, z0 + (h - z0) * 0.45, win, win * 0.9, cx + ey + h * 0.5, WINDOW)),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A box with a gable roof: the most common house. It stands on a low stone plinth and
|
||||||
|
* shows a door on the wall towards the lower right and windows on the one towards the
|
||||||
|
* lower left, as flat dark panels: a few large faces, no outlines.
|
||||||
|
*/
|
||||||
export function house(
|
export function house(
|
||||||
cx: number,
|
cx: number,
|
||||||
cy: number,
|
cy: number,
|
||||||
|
|
@ -230,8 +268,11 @@ export function house(
|
||||||
along: 'x' | 'y' = w >= d ? 'x' : 'y',
|
along: 'x' | 'y' = w >= d ? 'x' : 'y',
|
||||||
): Face[] {
|
): Face[] {
|
||||||
const o = Math.min(w, d) * 0.08
|
const o = Math.min(w, d) * 0.08
|
||||||
|
const plinth = Math.min(h * 0.16, Math.min(w, d) * 0.12)
|
||||||
return [
|
return [
|
||||||
...box(cx, cy, w, d, 0, h, walls),
|
...box(cx, cy, w + plinth * 0.6, d + plinth * 0.6, 0, plinth, STONE, STONE),
|
||||||
|
...box(cx, cy, w, d, plinth, h - plinth, walls),
|
||||||
|
...openings(cx, cy, w, d, plinth, h),
|
||||||
...gable(cx - w / 2 - o, cy - d / 2 - o, cx + w / 2 + o, cy + d / 2 + o, h, rise, along, roof, walls),
|
...gable(cx - w / 2 - o, cy - d / 2 - o, cx + w / 2 + o, cy + d / 2 + o, h, rise, along, roof, walls),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -261,5 +302,9 @@ export function plane(pts: V3[], color: string): Face {
|
||||||
|
|
||||||
/** Every face moved by (dx, dy, dz). */
|
/** Every face moved by (dx, dy, dz). */
|
||||||
export function shift(faces: Face[], dx: number, dy: number, dz = 0): Face[] {
|
export function shift(faces: Face[], dx: number, dy: number, dz = 0): Face[] {
|
||||||
return faces.map((f) => ({ ...f, pts: f.pts.map(([x, y, z]): V3 => [x + dx, y + dy, z + dz]) }))
|
return faces.map((f) => ({
|
||||||
|
...f,
|
||||||
|
pts: f.pts.map(([x, y, z]): V3 => [x + dx, y + dy, z + dz]),
|
||||||
|
...(f.depth !== undefined ? { depth: f.depth + dx + dy + dz } : {}),
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
// stone at high levels.
|
// stone at high levels.
|
||||||
|
|
||||||
import type { BuildingType } from '~/types/game'
|
import type { BuildingType } from '~/types/game'
|
||||||
import { box, type Face, hash, house, log, ngon, orient, plane, prism, pyramid, rect, shift, type V2, type V3 } from './iso'
|
import { box, type Face, hash, house, log, ngon, openings, orient, plane, prism, pyramid, rect, scale, shift, type V2, type V3 } from './iso'
|
||||||
|
|
||||||
/** Muted medieval colours, all flat: faces get their light from iso.ts shading only. */
|
/** Muted medieval colours, all flat: faces get their light from iso.ts shading only. */
|
||||||
export const C = {
|
export const C = {
|
||||||
|
|
@ -98,13 +98,14 @@ export function rock(x: number, y: number, size: number, seed = 0, color = C.roc
|
||||||
|
|
||||||
// Landscape: lighter trees for the forest around the village (few faces each).
|
// Landscape: lighter trees for the forest around the village (few faces each).
|
||||||
|
|
||||||
/** A fir: one tall faceted cone on a short trunk. */
|
/** A fir: two faceted tiers on a short trunk, the upper one a shade lighter. */
|
||||||
export function conifer(x: number, y: number, size: number, seed = 0): Face[] {
|
export function conifer(x: number, y: number, size: number, seed = 0): Face[] {
|
||||||
const rot = hash(seed, 7) * Math.PI
|
const rot = hash(seed, 7) * Math.PI
|
||||||
const color = hash(seed, 3) > 0.5 ? C.conifer : C.coniferDark
|
const color = hash(seed, 3) > 0.5 ? C.conifer : C.coniferDark
|
||||||
return [
|
return [
|
||||||
...prism(ngon(x, y, size * 0.07, 4, rot), 0, size * 0.25, C.trunk),
|
...prism(ngon(x, y, size * 0.07, 4, rot), 0, size * 0.25, C.trunk),
|
||||||
...pyramid(ngon(x, y, size * 0.36, 5, rot), size * 0.18, size * 1.05, color),
|
...pyramid(ngon(x, y, size * 0.38, 5, rot), size * 0.18, size * 0.7, color),
|
||||||
|
...pyramid(ngon(x, y, size * 0.27, 5, rot + 0.6), size * 0.55, size * 0.68, scale(color, 1.1)),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,9 +141,15 @@ export function well(s: number): Model {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A villager: legs, a shirt and a head with hair, a few shaded faces. */
|
||||||
function person(x: number, y: number, s: number, shirt = C.cloth): Face[] {
|
function person(x: number, y: number, s: number, shirt = C.cloth): Face[] {
|
||||||
const r = s * 0.06
|
const r = s * 0.055
|
||||||
return [...prism(ngon(x, y, r, 5), 0, s * 0.2, shirt), ...box(x, y, r * 1.3, r * 1.3, s * 0.2, r * 1.4, C.skin)]
|
return [
|
||||||
|
...prism(ngon(x, y, r * 0.8, 4, 0.4), 0, s * 0.09, C.dark),
|
||||||
|
...prism(ngon(x, y, r, 5), s * 0.09, s * 0.12, shirt),
|
||||||
|
...box(x, y, r * 1.2, r * 1.2, s * 0.21, r * 1.2, C.skin),
|
||||||
|
...box(x, y, r * 1.3, r * 1.3, s * 0.21 + r * 1.1, r * 0.35, C.woodDark),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
function field(x: number, y: number, w: number, d: number, color: string, rows: number): Face[] {
|
function field(x: number, y: number, w: number, d: number, color: string, rows: number): Face[] {
|
||||||
|
|
@ -226,6 +233,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
...box(0, 0, s * 1.35, s * 1.35, 0, s * 0.9, C.stone, C.stoneDark),
|
...box(0, 0, s * 1.35, s * 1.35, 0, s * 0.9, C.stone, C.stoneDark),
|
||||||
|
...openings(0, 0, s * 1.35, s * 1.35, 0, s * 0.9),
|
||||||
...pyramid(rect(0, 0, s * 1.5, s * 1.5), s * 0.9, s * 0.65, C.slate),
|
...pyramid(rect(0, 0, s * 1.5, s * 1.5), s * 0.9, s * 0.65, C.slate),
|
||||||
...prism(ngon(-s * 0.72, s * 0.72, s * 0.28, 6), 0, s * 1.3, C.stone),
|
...prism(ngon(-s * 0.72, s * 0.72, s * 0.28, 6), 0, s * 1.3, C.stone),
|
||||||
...pyramid(ngon(-s * 0.72, s * 0.72, s * 0.34, 6), s * 1.3, s * 0.45, C.slate),
|
...pyramid(ngon(-s * 0.72, s * 0.72, s * 0.34, 6), s * 1.3, s * 0.45, C.slate),
|
||||||
|
|
@ -478,6 +486,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
...box(0, 0, s * 1.9, s * 1.1, 0, s * 0.75, C.stone, C.stoneDark),
|
...box(0, 0, s * 1.9, s * 1.1, 0, s * 0.75, C.stone, C.stoneDark),
|
||||||
|
...openings(0, 0, s * 1.9, s * 1.1, 0, s * 0.75),
|
||||||
...pyramid(rect(0, 0, s * 2.0, s * 1.2), s * 0.75, s * 0.45, C.slate),
|
...pyramid(rect(0, 0, s * 2.0, s * 1.2), s * 0.75, s * 0.45, C.slate),
|
||||||
...prism(ngon(s * 0.85, -s * 0.5, s * 0.25, 6), 0, s * 1.3, C.stone),
|
...prism(ngon(s * 0.85, -s * 0.5, s * 0.25, 6), 0, s * 1.3, C.stone),
|
||||||
...pyramid(ngon(s * 0.85, -s * 0.5, s * 0.3, 6), s * 1.3, s * 0.4, C.slate),
|
...pyramid(ngon(s * 0.85, -s * 0.5, s * 0.3, 6), s * 1.3, s * 0.4, C.slate),
|
||||||
|
|
@ -524,6 +533,7 @@ const models: Record<BuildingType, (s: number, t: number) => Model> = {
|
||||||
return {
|
return {
|
||||||
faces: [
|
faces: [
|
||||||
...box(0, 0, s * 1.6, s * 1.3, 0, s * 0.9, C.stone, C.stoneDark),
|
...box(0, 0, s * 1.6, s * 1.3, 0, s * 0.9, C.stone, C.stoneDark),
|
||||||
|
...openings(0, 0, s * 1.6, s * 1.3, 0, s * 0.9),
|
||||||
...pyramid(rect(0, 0, s * 1.75, s * 1.45), s * 0.9, s * 0.6, C.slate),
|
...pyramid(rect(0, 0, s * 1.75, s * 1.45), s * 0.9, s * 0.6, C.slate),
|
||||||
...tower(-s * 0.85, -s * 0.7, s * 1.5),
|
...tower(-s * 0.85, -s * 0.7, s * 1.5),
|
||||||
...tower(s * 0.85, s * 0.7, s * 1.5),
|
...tower(s * 0.85, s * 0.7, s * 1.5),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue