A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D
Add market hall and church upgrade assets (#17)
Sandro Maglione0b02df3e04b7
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.mdindex ca10fe0..ca09cc4 100644--- a/DEVELOPMENT.md+++ b/DEVELOPMENT.md@@ -97,24 +97,30 @@ and elevation controls also work with a keyboard. The original view uses a| Collection | Entries | Coverage || --- | ---: | --- |-| Buildings | 37 | Every building kind, plus winter and worn material presets of the seven town services and stores |+| Buildings | 39 | Every building kind, tier 2 market hall and church, plus winter and worn material presets of the seven town services and stores || Homes | 21 | Four settler and citizen roof palettes, townhouse, and fine/poor/worn/winter material presets of every tier |-| Land | 24 | Trees, rocks, crops, roads, water, raised stone paving, three retained park furnishings and the park layout |+| Land | 30 | Trees, single-cell rocks and larger outcrops, crops, roads, water, raised stone paving, three retained park furnishings and the park layout || People | 32 | Carriers, residents, market and chapel walkers, and five equipped service workers || Cargo and vehicles | 75 | Twelve distinct goods and labelled crates; empty handcart/barrow and small/full loads of each good; the approved mixed goods plate || Construction and effects | 14 | Sites, frame/walls, problem sign, smoke, placement outlines and three kinds of ruin |-The 203 entries cover object families and representative seeded variants.+The 211 entries cover object families and representative seeded variants.Continuous growth, construction progress, walk poses and colours can begenerated; this is not a list of every possible random seed. Page iconsremain the game's original 2D UI art.-`pnpm assets:build` exports 203 GLBs and editable geometry descriptions,-a manifest, and five standalone viewers to `output/inkline-3d/`:+[`/service-upgrades.html`](http://localhost:5232/service-upgrades.html) compares+the market with the market hall and the chapel with the church. The four+models share one scale and synchronized rotation, tilt and zoom. Each model+has a GLB download. [The integration handoff](docs/service-upgrade-assets.md)+describes the asset API and the gameplay work still needed.++`pnpm assets:build` exports 211 GLBs and editable geometry descriptions,+a manifest, and six standalone viewers to `output/inkline-3d/`:`inkline-3d-study.html`, `inkline-3d-map.html`, and-`inkline-town-model-review.html`, `inkline-house-effects.html`, and `inkline-park.html`. It reimports every GLB and+`inkline-town-model-review.html`, `inkline-house-effects.html`, `inkline-park.html`, and `inkline-service-upgrades.html`. It reimports every GLB andchecks geometry and unlit materials. The viewers work without a dev server;their optional web fonts use the network. The game build remains separate.Material effects render in the viewers and live game. Ordinary GLB viewersdiff --git a/docs/service-upgrade-assets.md b/docs/service-upgrade-assets.mdnew file mode 100644index 0000000..f352403--- /dev/null+++ b/docs/service-upgrade-assets.md@@ -0,0 +1,46 @@+# Market hall and church assets++The tier 2 presentation assets are approved, including the church's straight-sided+timber double door. They are registered in the catalogue and review map. Gameplay+still selects the original tier 1 buildings.++## Asset API++`src/asset-lab/service-upgrades.ts` exports `marketHall()`, `church()`, and:++```ts+serviceBuilding("market", 2) // market-hall+serviceBuilding("chapel", 2) // church+serviceBuilding("market", 1) // existing market+```++Both upgrades retain the family's 2×2 footprint. Their catalogue references are+`{ type: "building", kind: "market" | "chapel", tier: 2 }`. `kind` remains the+existing service family. Asset IDs are `market-hall` and `church`.++These functions currently build complete preview assets, including plates. Live+integration should support the existing `BuildingOptions` conventions for+road-facing doors, construction fitting, plate visibility and separate motion.+Do not replace `buildingAsset()` with the preview helper without those controls.++## Gameplay integration still needed++- Define upgrade eligibility, costs and service effects. Persist a service tier+ with a backward-compatible tier 1 default for existing saves.+- Pass tier through presentation to `src/render3d/models.ts` and+ `src/render3d/views.ts`; include it in shared model/cache keys. Preserve the+ current condition, winter, smoke and construction behavior.+- Use the upgraded silhouette and dimensions for construction and effects.+ Keep the chapel's original cupola and market's original flag on tier 1.+- Add upgrade UI and verify save/load, construction, road-facing entrances,+ selection and rotation. Asset metadata alone does not activate upgrades.++## Review and export++Run `pnpm dev` and open `/service-upgrades.html` for synchronized tier comparisons,+street scale and GLB downloads. `/asset-lab.html?asset=church` and+`/asset-lab.html?asset=market-hall` inspect each model. `/map-lab.html` includes both.++`pnpm assets:build` exports GLB and JSON geometry, verifies reimported geometry and+unlit materials, and produces `output/inkline-3d/inkline-service-upgrades.html`.+The standalone viewer works without a dev server.diff --git a/scripts/ink-assets.ts b/scripts/ink-assets.tsindex 7d2ef21..fa54c55 100644--- a/scripts/ink-assets.ts+++ b/scripts/ink-assets.ts@@ -71,7 +71,8 @@ for (const [input, directory, filename] of [["map-lab.html", "map-viewer", "inkline-3d-map.html"],["model-review.html", "town-viewer", "inkline-town-model-review.html"],["effects-lab.html", "effects-viewer", "inkline-house-effects.html"],- ["park-lab.html", "park-viewer", "inkline-park.html"]+ ["park-lab.html", "park-viewer", "inkline-park.html"],+ ["service-upgrades.html", "service-viewer", "inkline-service-upgrades.html"]]) {await build({configFile: false,diff --git a/service-upgrades.html b/service-upgrades.htmlnew file mode 100644index 0000000..d5c06d0--- /dev/null+++ b/service-upgrades.html@@ -0,0 +1,12 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="UTF-8" />+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <title>Inkline Town · Service upgrades</title>+ </head>+ <body>+ <main id="service-study"></main>+ <script type="module" src="/src/asset-lab/service-study.ts"></script>+ </body>+</html>diff --git a/src/asset-lab/assets.ts b/src/asset-lab/assets.tsindex b1729b8..1902432 100644--- a/src/asset-lab/assets.ts+++ b/src/asset-lab/assets.ts@@ -6,6 +6,7 @@ import { groundAsset } from "../render3d/models.ts"import { key } from "../grid.ts"import { makeBuilding } from "./buildings.ts"import { house } from "./homes.ts"+import { marketHall, church } from "./service-upgrades.ts"import { U } from "../iso.ts"import { makeTree, makeRock, makeField, makeRoadPatch, makeWater } from "./land.ts"import { personCatalogue, makeCarrier, makeGoods, makeCrate } from "./people.ts"@@ -108,7 +109,7 @@ baseFir.footprint = 1for (const face of baseFir.faces) if (face.contour) face.contourWidth = 1.5approvedAssets.find((asset) => asset.id === "goods")!.category = "cargo"approvedAssets.find((asset) => asset.id === "goods")!.footprint = 2-const additional: Array<InkAsset> = []+const additional: Array<InkAsset> = [marketHall(), church()]for (const kind of kindIds) if (!approvedAssets.some((asset) => asset.id === kind)) additional.push(makeBuilding(kind))const names = ["terracotta", "slate", "thatch", "moss"]for (const tier of [1, 2] as const)diff --git a/src/asset-lab/main.ts b/src/asset-lab/main.tsindex ee4be30..49f3e70 100644--- a/src/asset-lab/main.ts+++ b/src/asset-lab/main.ts@@ -31,7 +31,7 @@ const root = document.querySelector<HTMLDivElement>("#lab")!root.innerHTML = `<header><a href="/model-review.html">Model review ↗</a><span>COMPLETE ASSET CATALOGUE</span><a href="/effects-lab.html">Animated house effects ↗</a></header><div class="intro"><div><h1>The same ink.<br>A different angle.</h1><p>Original game drawings and complete 3D assets, side by side.</p></div><span class="tag">Procedural · Orthographic · Rotatable</span></div>- <div class="filters"><label>Collection <select id="category"></select></label><label>Find <input id="search" type="search" placeholder="Name or material"></label><a href="/map-lab.html">See everything on the map ↗</a></div><nav class="assets" aria-label="Choose an asset"></nav>+ <div class="filters"><label>Collection <select id="category"></select></label><label>Find <input id="search" type="search" placeholder="Name or material"></label><a href="/service-upgrades.html">Compare service tiers ↗</a><a href="/map-lab.html">See everything on the map ↗</a></div><nav class="assets" aria-label="Choose an asset"></nav><section class="comparison" aria-label="Compare the original drawing with the 3D model"><div class="view"><div class="view-label"><span>01 / CURRENT GAME</span><span>Fixed isometric drawing</span></div><canvas id="reference" aria-label="Original 2D asset"></canvas><span class="view-foot">Original art.ts drawing</span></div><div class="view"><div class="view-label"><span>02 / 3D STUDY</span><span id="angle-label">Original angle</span></div><div id="viewer" role="img" aria-label="Rotatable 3D asset. Drag horizontally to rotate."></div><span class="view-foot">Drag to rotate · wheel to zoom</span></div>@@ -235,7 +235,9 @@ function render() {const ref = references.get(selected.id)!const model = models.get(selected.id)!const effectBounds=selected.smokeEffect||selected.fountains?.length?new THREE.Box3().setFromObject(model.group):null- const vertical = Math.max(40, ref.height * 1.45, ((ref.width * height) / width) * 1.3, effectBounds?effectBounds.getSize(new THREE.Vector3()).y*1.45:0) / zoom+ const upgraded = selected.reference?.type === "building" && selected.reference.tier === 2+ const bounds = upgraded ? new THREE.Box3().setFromObject(model.group).getBoundingSphere(new THREE.Sphere()) : null+ const vertical = Math.max(40, ref.height * 1.45, ((ref.width * height) / width) * 1.3, effectBounds?effectBounds.getSize(new THREE.Vector3()).y*1.45:0, bounds ? bounds.radius * 2.4 * Math.max(1, height / width) : 0) / zoomrenderer.setSize(width, height, false)camera.left = (-vertical * width) / height / 2camera.right = -camera.left@@ -243,7 +245,7 @@ function render() {camera.bottom = -camera.topconst heading = ((45 + yaw) * Math.PI) / 180,altitude = (pitch * Math.PI) / 180- const target = effectBounds?effectBounds.getCenter(new THREE.Vector3()):new THREE.Vector3(0, -(ref.y + ref.height / 2) / Math.cos(Math.PI / 6), 0)+ const target = bounds?.center ?? (effectBounds?effectBounds.getCenter(new THREE.Vector3()):new THREE.Vector3(0, -(ref.y + ref.height / 2) / Math.cos(Math.PI / 6), 0))camera.position.copy(target).add(diff --git a/src/asset-lab/primitives.ts b/src/asset-lab/primitives.tsindex 1bd7e10..242b29a 100644--- a/src/asset-lab/primitives.ts+++ b/src/asset-lab/primitives.ts@@ -20,7 +20,7 @@ export interface Stroke {}export type AssetCategory = "buildings" | "homes" | "land" | "people" | "cargo" | "construction"export type AssetReference =- | { type: "building"; kind: KindId; build?: number }+ | { type: "building"; kind: KindId; tier?: 1 | 2; build?: number }| { type: "house"; tier: Tier; variant: number; build?: number }| { type: "tree"; x: number; y: number; grown: number }| { type: "rock"; x: number; y: number; ore: boolean; amount: number }diff --git a/src/asset-lab/service-study.css b/src/asset-lab/service-study.cssnew file mode 100644index 0000000..ceb6a36--- /dev/null+++ b/src/asset-lab/service-study.css@@ -0,0 +1,5 @@+@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=DM+Mono:wght@400;500&display=swap");+:root{font-family:"DM Sans",sans-serif;color:#3d4943;background:#f0f2ec;font-synthesis:none}+*{box-sizing:border-box}body{margin:0}button,input{font:inherit;color:inherit}a{color:inherit;text-underline-offset:4px}button{cursor:pointer;background:transparent;border:1px solid #bdc7b7;border-radius:4px;padding:10px 12px;font-size:12px}button:hover,button[aria-pressed=true]{background:#e1e7db;border-color:#7b8d70}button:focus-visible,a:focus-visible,input:focus-visible,.model-view:focus-visible{outline:2px solid #3d6db5;outline-offset:4px}#service-study{max-width:1180px;margin:auto;padding:28px 40px 36px}header{display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid #cbd1c6;padding-bottom:20px}header a{text-decoration:none;font-weight:700;font-size:18px}header span,.eyebrow,.model-label{font:10px "DM Mono",monospace;letter-spacing:.1em;color:#748073}.intro{padding:32px 0 26px}.eyebrow{margin:0 0 14px;text-transform:uppercase}h1{font-size:44px;line-height:1.08;font-weight:500;letter-spacing:-.045em;margin:0 0 16px}.intro>p:last-child{font-size:14px;line-height:1.65;margin:0;color:#748073}.study-controls{display:flex;align-items:center;gap:12px;flex-wrap:wrap;border-top:1px solid #cbd1c6;border-bottom:1px solid #cbd1c6;padding:16px 0}.study-controls label{display:flex;align-items:center;gap:9px;font:11px "DM Mono",monospace;flex:1;min-width:180px}.study-controls input{min-width:60px;width:100%;accent-color:#5c7154}.study-controls output{min-width:34px;color:#748073}.family{margin-top:28px}.family-heading{display:flex;align-items:baseline;justify-content:space-between;gap:16px;margin-bottom:12px}h2{font-size:20px;letter-spacing:-.025em;font-weight:500;margin:0}.family-heading p{font-size:12px;color:#748073;margin:0}.model-pair{display:grid;grid-template-columns:1fr 1fr;border:1px solid #cbd1c6;border-radius:6px;overflow:hidden}.model-card{min-width:0;position:relative;background:#f5f6f0}.model-card+article{border-left:1px solid #cbd1c6}.model-label{display:flex;justify-content:space-between;padding:18px 20px 0}.model-label span:first-child{color:#3d4943}.model-view{height:315px;touch-action:none;cursor:grab}.model-view:active{cursor:grabbing}.model-view canvas{width:100%;height:100%;display:block}.model-caption{display:flex;gap:14px;align-items:flex-start;justify-content:space-between;padding:0 20px 20px;min-height:91px}h3{font-size:19px;font-weight:500;margin:0 0 7px}.model-caption p{font-size:12px;line-height:1.55;color:#748073;max-width:320px;margin:0}.model-caption button{white-space:nowrap;font:10px "DM Mono",monospace}footer{border-top:1px solid #cbd1c6;margin-top:28px;padding-top:16px;font-size:12px;color:#748073;line-height:1.7}footer p{margin:0 0 10px}footer div{display:flex;gap:24px}footer .note{font-size:11px;margin-top:12px}+@media(max-width:700px){#service-study{padding:20px}h1{font-size:36px}.family-heading{display:block}.family-heading p{margin-top:7px}.study-controls label{flex-basis:100%}.model-view{height:250px}.model-caption{padding:0 12px 16px;display:block}.model-caption button{margin-top:12px}.model-label{padding:16px 12px 0;font-size:9px}.model-caption p{font-size:11px}h3{font-size:17px}header span{font-size:9px}.intro{padding-top:26px}}+@media(max-width:440px){#service-study{padding:16px}.model-pair{grid-template-columns:1fr}.model-card+article{border-left:0;border-top:1px solid #cbd1c6}.model-view{height:290px}.model-caption{display:flex;min-height:88px}.model-caption button{margin:0}.model-caption p{font-size:12px}footer div{flex-direction:column;gap:8px}}diff --git a/src/asset-lab/service-study.ts b/src/asset-lab/service-study.tsnew file mode 100644index 0000000..4750a51--- /dev/null+++ b/src/asset-lab/service-study.ts@@ -0,0 +1,125 @@+import * as THREE from "three"+import { assetById } from "./assets.ts"+import { buildAsset, exportAsset, floorScale, vertex3 } from "./renderer.ts"+import "./service-study.css"++const root = document.querySelector<HTMLElement>("#service-study")!+root.innerHTML = `+ <header><a href="/">Inkline Town</a><span>BUILDING STUDY / 02</span></header>+ <section class="intro"><p class="eyebrow">Room to grow</p><h1>A familiar town.<br>A little more established.</h1><p>Two service upgrades, in the same pale stone and ink.<br>Both tiers keep their 2×2 plot. All four views share one scale.</p></section>+ <nav class="study-controls" aria-label="Model camera controls">+ <button id="reset">Original angle</button><button id="back">See the back</button>+ <label>Turn <input id="heading" type="range" min="-180" max="180" value="0"><output id="heading-value">0°</output></label>+ <label>Tilt <input id="tilt" type="range" min="15" max="65" value="30"><output id="tilt-value">30°</output></label>+ <button id="scale" aria-pressed="false">Street scale</button>+ </nav>+ <section class="family" aria-labelledby="market-heading"><div class="family-heading"><h2 id="market-heading">A place to trade</h2><p>Striped stalls become a covered hall.</p></div><div class="model-pair">+ ${card("market", "01", "Market", "The familiar striped stall and goods yard.")}+ ${card("market-hall", "02", "Market hall", "A pitched roof, covered arcade and upper windows. The stripes stay.")}+ </div></section>+ <section class="family" aria-labelledby="chapel-heading"><div class="family-heading"><h2 id="chapel-heading">A place to gather</h2><p>A small cupola becomes a proper bell tower.</p></div><div class="model-pair">+ ${card("chapel", "01", "Chapel", "Blue glass, pale walls and the original small cupola.")}+ ${card("church", "02", "Church", "A pitched nave, stone buttresses and an open belfry with a bronze bell.")}+ </div></section>+ <footer><p>Drag any model to turn all four. Scroll over a model to zoom.</p><div><a href="/asset-lab.html?asset=market-hall">Full asset catalogue ↗</a><a href="/map-lab.html">See them in the town ↗</a></div><p class="note">Asset preview. Gameplay upgrade rules will be connected separately.</p></footer>+`++function card(id: string, tier: string, title: string, note: string) {+ return `<article class="model-card"><div class="model-label"><span>TIER ${tier}</span><span>2 × 2 PLOT</span></div><div class="model-view" data-model="${id}" role="img" aria-label="${title}, rotatable 3D model" tabindex="0"></div><div class="model-caption"><div><h3>${title}</h3><p>${note}</p></div><button data-export="${id}" aria-label="Download ${title} GLB">GLB ↓</button></div></article>`+}++let yaw = 0, pitch = 30, zoom = 1, street = false+const heading = root.querySelector<HTMLInputElement>("#heading")!+const tilt = root.querySelector<HTMLInputElement>("#tilt")!+const views = [...root.querySelectorAll<HTMLElement>("[data-model]")].map(view => {+ const asset = assetById.get(view.dataset.model!)!+ const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true, preserveDrawingBuffer: true })+ renderer.setPixelRatio(Math.min(devicePixelRatio, 2))+ renderer.outputColorSpace = THREE.SRGBColorSpace+ renderer.toneMapping = THREE.NoToneMapping+ renderer.setClearColor(0xf0f2ec, 0)+ view.append(renderer.domElement)+ const model = buildAsset(asset, { batchFaces: true })+ const scene = new THREE.Scene()+ scene.add(model.group)+ const camera = new THREE.OrthographicCamera(-130, 130, 130, -130, 0.1, 4000)+ let drag: { x: number; y: number } | null = null+ view.onpointerdown = e => { drag = { x: e.clientX, y: e.clientY }; view.setPointerCapture(e.pointerId) }+ view.onpointermove = e => {+ if (!drag) return+ yaw = THREE.MathUtils.euclideanModulo(yaw + (e.clientX - drag.x) * 0.6 + 180, 360) - 180+ pitch = Math.max(15, Math.min(65, pitch + (e.clientY - drag.y) * 0.25))+ drag = { x: e.clientX, y: e.clientY }+ render()+ }+ view.onpointerup = view.onpointercancel = view.onlostpointercapture = () => { drag = null }+ view.addEventListener("wheel", e => {+ e.preventDefault()+ zoom = Math.max(0.65, Math.min(1.75, zoom * Math.exp(-e.deltaY * 0.001)))+ render()+ }, { passive: false })+ view.onkeydown = e => {+ if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown", "Home"].includes(e.key)) return+ e.preventDefault()+ if (e.key === "Home") { yaw = 0; pitch = 30; zoom = 1 }+ else if (e.key === "ArrowLeft" || e.key === "ArrowRight") yaw = THREE.MathUtils.euclideanModulo(yaw + (e.key === "ArrowLeft" ? -15 : 15) + 180, 360) - 180+ else pitch = Math.max(15, Math.min(65, pitch + (e.key === "ArrowUp" ? 5 : -5)))+ render()+ }+ return { id: asset.id, view, renderer, model, scene, camera }+})++function render() {+ heading.value = String(yaw)+ tilt.value = String(pitch)+ root.querySelector("#heading-value")!.textContent = `${Math.round(yaw)}°`+ root.querySelector("#tilt-value")!.textContent = `${Math.round(pitch)}°`+ for (const { view, renderer, model, scene, camera } of views) {+ const width = view.clientWidth, height = view.clientHeight+ if (!width || !height) continue+ renderer.setSize(width, height, false)+ // Shared projection and ground target keep tier height differences honest.+ const span = (street ? 335 : 195) / zoom+ camera.left = -span * width / height / 2+ camera.right = -camera.left+ camera.top = span / 2+ camera.bottom = -camera.top+ const target = vertex3([0, 0, 49])+ const angle = THREE.MathUtils.degToRad(45 + yaw), altitude = THREE.MathUtils.degToRad(pitch)+ camera.position.set(target.x + Math.cos(angle) * 700 * Math.cos(altitude), target.y + 700 * Math.sin(altitude), target.z + Math.sin(angle) * 700 * Math.cos(altitude))+ camera.lookAt(target)+ camera.updateProjectionMatrix()+ for (const { material, width } of model.lineMaterials) material.linewidth = width+ model.updateContours(camera)+ renderer.render(scene, camera)+ }+}++heading.oninput = () => { yaw = Number(heading.value); render() }+tilt.oninput = () => { pitch = Number(tilt.value); render() }+root.querySelector<HTMLButtonElement>("#reset")!.onclick = () => { yaw = 0; pitch = 30; zoom = 1; render() }+root.querySelector<HTMLButtonElement>("#back")!.onclick = () => { yaw = yaw === -180 ? 0 : -180; render() }+root.querySelector<HTMLButtonElement>("#scale")!.onclick = e => {+ street = !street+ ;(e.currentTarget as HTMLButtonElement).setAttribute("aria-pressed", String(street))+ render()+}+for (const button of root.querySelectorAll<HTMLButtonElement>("[data-export]")) button.onclick = async () => {+ const asset = assetById.get(button.dataset.export!)!+ const blob = new Blob([await exportAsset(asset)], { type: "model/gltf-binary" })+ const url = URL.createObjectURL(blob), a = document.createElement("a")+ a.href = url; a.download = `inkline-${asset.id}.glb`; a.click()+ setTimeout(() => URL.revokeObjectURL(url), 1000)+}+const observer = new ResizeObserver(render)+views.forEach(({ view }) => observer.observe(view))+render()+Object.assign(window, { serviceStudy: {+ rotate: (angle: number, elevation = 30) => { yaw = angle; pitch = elevation; render() },+ stats: () => ({ yaw, pitch, street, scale: floorScale, models: views.map(v => ({ id: v.id, triangles: v.renderer.info.render.triangles })) }),+ capture: (id: string) => views.find(v => v.id === id)!.renderer.domElement.toDataURL("image/png")+} })+if (import.meta.hot) import.meta.hot.dispose(() => {+ observer.disconnect()+ views.forEach(({ renderer, model }) => { model.dispose(); renderer.dispose() })+})diff --git a/src/asset-lab/service-upgrades.ts b/src/asset-lab/service-upgrades.tsnew file mode 100644index 0000000..cc56ffa--- /dev/null+++ b/src/asset-lab/service-upgrades.ts@@ -0,0 +1,200 @@+import { U } from "../iso.ts"+import { kinds } from "../content.ts"+import { makeBuilding } from "./buildings.ts"+import { Drawing, palette, pale, sides, type Side, type Vertex } from "./primitives.ts"++export type ServiceKind = "market" | "chapel"++/** Presentation assets only. Service costs, unlocks and upgrade rules belong to the simulation. */+export function serviceBuilding(kind: ServiceKind, tier: 1 | 2) {+ if (tier === 1) return makeBuilding(kind)+ return kind === "market" ? marketHall() : church()+}++const blue = 0x3d6db5+const stone = { top: 0xf0f1eb, left: 0xe1e5dc, right: 0xd3d9cf }+const timber = { top: 0xeee2c8, left: 0xdcc9a8, right: 0xc6b18e }++function base(kind: ServiceKind, id: string, title: string, note: string) {+ const d = new Drawing(id, title, note)+ d.asset.category = "buildings"+ d.asset.reference = { type: "building", kind, tier: 2 }+ d.asset.footprint = kinds[kind].size+ d.plate(kinds[kind].size)+ return d+}++/** A closed rectangular pitched roof, including both end walls. Ridge follows v. */+function roof(d: Drawing, u: number, v: number, a: number, b: number, z: number, rise: number, color: number) {+ const p = (x: number, y: number, h: number): Vertex => [u + x, v + y, h]+ d.face([p(-a, -b, z), p(-a, b, z), p(0, b, z + rise), p(0, -b, z + rise)], pale(color, 0.7))+ d.face([p(a, -b, z), p(a, b, z), p(0, b, z + rise), p(0, -b, z + rise)], pale(color, 0.52))+ for (const sign of [-1, 1]) d.face([p(-a, sign * b, z), p(a, sign * b, z), p(0, sign * b, z + rise)], sign > 0 ? palette.left : palette.right)+ d.face([p(-a, -b, z), p(a, -b, z), p(a, b, z), p(-a, b, z)], palette.roof, 0)+}++type Wall = (along: number, z: number, out?: number) => Vertex+const wall = (side: Side, a: number, u = 0, v = 0): Wall => {+ const d = new Drawing("wall", "", "")+ return (s, z, out = 0.008) => {+ const [x, y, h] = d.wall(side, a, s, z, out)+ return [x + u, y + v, h]+ }+}++/** Convex opening and separate stone voussoirs keep the arch solid from every heading. */+function arch(d: Drawing, p: Wall, s: number, z: number, half: number, height: number, fill: number, frame = false, rise = 4) {+ const spring = z + height - rise+ const arc = Array.from({ length: 9 }, (_, i) => {+ const t = (i / 8) * Math.PI+ return p(s + Math.cos(t) * half, spring + Math.sin(t) * rise)+ })+ d.face([p(s - half, z), p(s + half, z), ...arc], fill, 0)+ // Long strokes are smoothed by the ink renderer. Only the arch is curved;+ // keep the jambs and threshold in a separate, straight four-point stroke.+ d.line([p(s - half, spring), p(s - half, z), p(s + half, z), p(s + half, spring)], 1)+ d.line(arc, 1)+ if (frame) {+ for (let i = 0; i < 8; i++) {+ const t = (i / 8) * Math.PI, next = ((i + 1) / 8) * Math.PI+ const point = (angle: number, outer: boolean) => p(s + Math.cos(angle) * (half + (outer ? U : 0)), spring + Math.sin(angle) * (rise + (outer ? 1.5 : 0)), 0.014)+ d.face([point(t, false), point(next, false), point(next, true), point(t, true)], stone.top, 0.65)+ }+ }+}++function churchDoor(d: Drawing, p: Wall) {+ const half = 2.25 * U, bottom = 4, spring = 19+ arch(d, p, 0, bottom, half, 18, 0xc6b18e, true, 3)+ for (const sign of [-1, 1]) {+ const inner = sign * half, outer = sign * (half + U)+ d.face([p(inner, bottom, 0.014), p(outer, bottom, 0.014), p(outer, spring, 0.014), p(inner, spring, 0.014)], stone.top, 0.65)+ d.line([p(inner, 11.5, 0.02), p(outer, 11.5, 0.02)], 0.6, palette.ink, 0.6)+ // Small vertical handles make the two leaves readable without extra ornament.+ d.line([p(sign * 0.6 * U, 10.5, 0.03), p(sign * 0.6 * U, 12, 0.03)], 0.8, 0x7d6140)+ }+ d.line([p(0, bottom, 0.025), p(0, 22, 0.025)], 0.7, 0x7d6140)+}++export function marketHall() {+ const d = base("market", "market-hall", "Market hall", "Tier 2 market. A pitched hall above a covered arcade, with the market's striped awnings, blue trim and goods crates. Same 2×2 plot.")+ const a = 9 * U+ d.box(0, 0, 10 * U, 10 * U, 0, 3, stone.top, stone.left, stone.right)+ d.box(0, 0, a, a, 3, 40)+ d.box(0, 0, 9.4 * U, 9.4 * U, 28, 2, stone.top, stone.left, stone.right, 1)+ for (const side of sides) {+ const p = wall(side, a)+ arch(d, p, 0, 3, 2.5 * U, 19, 0xc6b18e, true)+ d.line([p(0, 3, 0.02), p(0, 18, 0.02)], 0.8, 0x7d6140)+ for (const s of [-5.5 * U, 0, 5.5 * U]) {+ arch(d, p, s, 33, 1.15 * U, 7, palette.glass)+ d.line([p(s, 33, 0.02), p(s, 38, 0.02)], 0.65)+ d.line([p(s - 1.5 * U, 32), p(s + 1.5 * U, 32)], 1)+ }+ d.line([p(-a, 30), p(a, 30)], 1, pale(blue, 0.3))+ }+ roof(d, 0, 0, 11 * U, 11 * U, 44, 18, 0x8a6a45)+ // A complete arcade on the two street faces. Narrow posts retain open space below the canopy.+ for (const side of ["right", "left"] as const) {+ const p = wall(side, 13 * U)+ for (const s of [-12 * U, -4 * U, 4 * U, 12 * U]) {+ const [u, v] = p(s, 0, 0)+ d.box(u, v, 0.7 * U, 0.7 * U, 0, 2, stone.top, stone.left, stone.right, 1)+ d.box(u, v, 0.45 * U, 0.45 * U, 2, 20, timber.top, timber.left, timber.right, 1)+ d.box(u, v, 0.75 * U, 0.75 * U, 22, 2, timber.top, timber.left, timber.right, 1)+ }+ const transform = (s: number, depth: number, z: number) => wall(side, depth)(s, z, 0)+ // A solid lintel joins the posts below the canopy.+ const [u, v] = p(0, 0, 0)+ d.box(u, v, (side === "left" ? 13 : 0.65) * U, (side === "right" ? 13 : 0.65) * U, 24, 2, timber.top, timber.left, timber.right, 1)+ for (let i = 0; i < 13; i++) {+ const from = (-12 + i * 2) * U, to = from + 2 * U+ // Mitre the two canopy faces along the corner diagonal. No intersecting striped sheets.+ const panel: Array<[number, number]> = [[from, 9 * U], [to, 9 * U], [to, 14 * U], [from, 14 * U]]+ const clipped: Array<[number, number]> = []+ for (let j = 0; j < panel.length; j++) {+ const a = panel[j]!, b = panel[(j + 1) % panel.length]!+ const da = a[0] - a[1], db = b[0] - b[1]+ if (da <= 0) clipped.push(a)+ if ((da < 0 && db > 0) || (da > 0 && db < 0)) {+ const t = da / (da - db)+ clipped.push([a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t])+ }+ }+ d.face(clipped.map(([s, depth]) => transform(s, depth, 30 - ((depth / U - 9) / 5) * 4)), i % 2 ? 0xf7f3ea : 0xc4523f, 0.65)+ d.face([transform(from, 14 * U, 26), transform(to, 14 * U, 26), transform(to, 14 * U, 23.5), transform(from, 14 * U, 23.5)], i % 2 ? 0xf7f3ea : 0xc4523f, 0.65)+ }+ for (const s of [-8 * U, 8 * U]) {+ const [x, y] = p(s, 0, -U)+ d.box(x, y, 1.3 * U, 1.3 * U, 0, 7, timber.top, timber.left, timber.right, 1)+ d.crate(x, y, 7, s < 0 ? 0x2f8c87 : 0xd6ae2e, 1.1 * U, 4)+ }+ }+ d.crate(-12 * U, 5 * U, 0, 0x8a58a8)+ d.sack(-12 * U, 0)+ // Blue gable plaques carry the service colour above the striped street fronts.+ for (const side of ["left", "backLeft"] as const) {+ const p = wall(side, 11 * U)+ d.face([p(-2 * U, 47), p(2 * U, 47), p(2 * U, 51), p(-2 * U, 51)], pale(blue, 0.28), 1)+ for (const s of [-U, 0, U]) d.line([p(s, 48, 0.02), p(s, 50, 0.02)], 0.7, 0xf7f3ea)+ }+ return d.asset+}++export function church() {+ const d = base("chapel", "church", "Church", "Tier 2 chapel. A slate-blue nave, stone buttresses, arched glass and an open belfry with a bronze bell. Same 2×2 plot.")+ const a = 7 * U, b = 11 * U+ d.box(0, 0, 8 * U, 12 * U, 0, 3, stone.top, stone.left, stone.right)+ d.box(0, 0, a, b, 3, 48)+ roof(d, 0, 0, 8.5 * U, 12 * U, 52, 24, blue)+ for (const side of ["right", "backRight"] as const) {+ const p = wall(side, a)+ for (const s of [-7 * U, 0, 7 * U]) {+ arch(d, p, s, 20, 1.4 * U, 21, 0xc9d6ee, true)+ d.line([p(s, 20, 0.025), p(s, 38, 0.025)], 0.75)+ d.line([p(s - 1.4 * U, 29, 0.025), p(s + 1.4 * U, 29, 0.025)], 0.75)+ d.line([p(s - 2 * U, 19), p(s + 2 * U, 19)], 1)+ }+ for (const s of [-10 * U, -3.5 * U, 3.5 * U, 10 * U]) {+ const [x, y] = p(s, 0, 1.2 * U)+ d.box(x, y, 1.2 * U, 0.65 * U, 3, 28, stone.top, stone.left, stone.right, 1)+ d.box(x, y, 0.65 * U, 0.65 * U, 31, 14, stone.top, stone.left, stone.right, 1)+ }+ }+ const rear = wall("backLeft", b)+ arch(d, rear, 0, 24, 2.4 * U, 23, 0xc9d6ee, true)+ d.line([rear(0, 24, 0.025), rear(0, 44, 0.025)], 0.8)+ // Front tower grows from the nave's entrance, with a genuinely open four-sided bell chamber.+ const tv = 9 * U, ta = 3.4 * U+ d.box(0, tv, ta + 0.8 * U, ta + 0.8 * U, 0, 4, stone.top, stone.left, stone.right)+ d.box(0, tv, ta, ta, 4, 76)+ for (const z of [28, 56, 79]) d.box(0, tv, ta + 0.4 * U, ta + 0.4 * U, z, 2, stone.top, stone.left, stone.right, 1)+ for (const side of sides) {+ const p = wall(side, ta, 0, tv)+ if (side !== "backLeft") {+ if (side === "left") churchDoor(d, p)+ else arch(d, p, 0, 34, U, 15, 0xc9d6ee, true)+ }+ }+ for (const u of [-ta + 0.5 * U, ta - 0.5 * U]) for (const v of [tv - ta + 0.5 * U, tv + ta - 0.5 * U])+ d.box(u, v, 0.5 * U, 0.5 * U, 81, 16)+ // The bell has depth and a dark mouth. It remains visible through the open chamber on rotation.+ d.box(0, tv, 2.5 * U, 0.4 * U, 94, 2, timber.top, timber.left, timber.right, 1)+ d.cylinder(0, tv, 1.1 * U, 87, 6, 0xb39a61, 0xd5c18b, 0.7, 12)+ d.cylinder(0, tv, 1.9 * U, 85, 2, 0xb39a61, 0xd5c18b, 0.7, 16)+ d.cylinder(0, tv, 0.6 * U, 83, 2, 0x68726c, 0xb39a61, 0.6, 12)+ d.box(0, tv, ta + 0.6 * U, ta + 0.6 * U, 97, 3, stone.top, stone.left, stone.right, 1)+ const cap = new Drawing("spire", "", "")+ cap.pyramid(ta + 0.9 * U, 100, 17, pale(blue, 0.7), pale(blue, 0.52))+ d.asset.faces.push(...cap.asset.faces.map(f => ({ ...f, points: f.points.map(([u, v, z]): Vertex => [u, v + tv, z]) })))+ d.asset.strokes.push(...cap.asset.strokes.map(s => ({ ...s, points: s.points.map(([u, v, z]): Vertex => [u, v + tv, z]) })))+ d.box(0, tv, 0.22 * U, 0.22 * U, 117, 8, stone.top, stone.left, stone.right, 0.8)+ d.box(0, tv, 1.25 * U, 0.22 * U, 121, 1, stone.top, stone.left, stone.right, 0.8)+ // Broad steps, low planting and an entrance path stay inside the original plot.+ for (let i = 0; i < 2; i++) d.box(0, (12.5 - i) * U, (3 + i * 0.3) * U, 0.7 * U, 0, 1 + i, stone.top, stone.left, stone.right, 0.8)+ for (const sign of [-1, 1]) {+ d.box(sign * 11 * U, 9 * U, 1.5 * U, 3 * U, 0, 2, stone.top, stone.left, stone.right, 0.8)+ for (const v of [7.5, 10.5]) d.ellipsoid(sign * 11 * U, v * U, 4, 1.5 * U, 1.5 * U, 2.5, 0xccd5ae, 0.7, 0xe8ecd2, 12)+ }+ return d.asset+}diff --git a/src/map-lab/map.ts b/src/map-lab/map.tsindex 476dd01..db55f8c 100644--- a/src/map-lab/map.ts+++ b/src/map-lab/map.ts@@ -119,7 +119,9 @@ const layout: Array<[string, number, number]> = [["smithy", -2, 1],["bakery", 3, 1],["weaver", 7, 1],- ["fishery", 13, 1]+ ["fishery", 13, 1],+ ["market-hall", -7, -5],+ ["church", -6.5, -8]]for (const [id, x, y] of layout) place(id, x, y)// Services, food stores and a park along the south-west street.diff --git a/test/ink-assets.test.ts b/test/ink-assets.test.tsindex 069c1d5..e688285 100644--- a/test/ink-assets.test.ts+++ b/test/ink-assets.test.ts@@ -47,6 +47,19 @@ test("all geometry is finite, nondegenerate and uses valid ink weights", () => {}})+test("service upgrades retain the original plot and declare their family and tier", () => {+ for (const [id, kind] of [["market-hall", "market"], ["church", "chapel"]] as const) {+ const asset = assetById.get(id)!, original = assetById.get(kind)!+ assert.deepEqual(asset.reference, { type: "building", kind, tier: 2 })+ assert.equal(asset.footprint, original.footprint)+ const points = [...asset.faces, ...asset.strokes].flatMap(part => part.points)+ const edge = (kinds[kind].size * 8 - 1) * U+ assert.ok(points.every(([u, v]) => Math.abs(u) <= edge && Math.abs(v) <= edge), `${id}: geometry leaves its plot`)+ const height = (a: typeof asset) => Math.max(...a.faces.flatMap(f => f.points.map(p => p[2])))+ assert.ok(height(asset) > height(original), `${id}: upgrade should have a taller silhouette`)+ }+})+test("the review map includes every catalogue model at least once", () => {const represented = new Set(testMap.buildings.map((p) => p.asset))assert.deepEqual([...represented].sort(), inkAssets.map((a) => a.id).sort())diff --git a/vite.config.ts b/vite.config.tsindex 1b2c8d2..812cbf6 100644--- a/vite.config.ts+++ b/vite.config.ts@@ -16,7 +16,8 @@ export default defineConfig({map: "map-lab.html",models: "model-review.html",effects: "effects-lab.html",- parks: "park-lab.html"+ parks: "park-lab.html",+ services: "service-upgrades.html"}}}