A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D
Phone play: a pause switch, a quieter tooltip, and strokes that wait to be built
SandroMaglionebb3067a1c089
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.mdindex 37887a2..680f48a 100644--- a/DEVELOPMENT.md+++ b/DEVELOPMENT.md@@ -32,13 +32,21 @@ pan and pinch to zoom; twisting them rotates. Road/home tools still drag tobuild; camera gestures never place anything. A finger has no hover, so ontouch the tap tools (buildings, park pieces, bulldoze) take two taps: thefirst holds the ghost or outline where it landed, a second on the same spot-commits it. This lives entirely in `src/render3d/input.ts`; the game still-sees one ordinary press and release.+commits it. The drag tools (road, pave, homes, park ground) hold the stroke+on touch too: a bar above the tool bar says what it lays and costs, with+**Build** and ✕; a tap on the stroke's end builds it, a tap elsewhere drops+it, and two fingers move the camera under it. With any pointer, a stroke let+go off the map (over the tool bar, say) is dropped and shows red while it+would be, as are a right click or Esc mid-drag. On touch the tooltip shows+only for what is about to be built, never while panning or picking, in a+strip under the top line. This lives entirely in `src/render3d/input.ts`+(and the bar in `host.ts`); the game still sees one ordinary press and+release.Phones get their layout from `src/phone.css`, loaded after `factory.css`. Ona narrow or short screen the HUD folds away: one top line (clock, treasury,people, and a chip of planks, stone and tools), one tool bar along the bottom-(town, the tools, pause, a speed button that cycles, and a ⋯ menu holding+(town, the tools, pause (a switch: play while paused), a speed button that cycles, and a ⋯ menu holdingshare, guide, save, load, new town and recentre), and two buttons top rightfor the guide and the map overlays. `host.ts` sets `body.fold-goods`,`fold-guide`, `fold-views` or `fold-more` while one is open; a tap on the mapdiff --git a/src/factory.css b/src/factory.cssindex e4fec2f..3271c7f 100644--- a/src/factory.css+++ b/src/factory.css@@ -113,6 +113,19 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;font-size: 12px; padding: 7px 14px; border-radius: 4px; opacity: 0; transition: opacity 160ms ease; pointer-events: none; z-index: 20;}.toast.show { opacity: 1; }+/* A stroke let go of on a touch screen: what it lays and costs, with build and cancel, above the tool bar. */+.stroke-bar {+ position: fixed; left: 50%; bottom: calc(70px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 5;+ display: none; align-items: center; gap: 6px; padding: 5px 5px 5px 12px; max-width: calc(100vw - 16px);+ background: #f7f8f4; border: 1px solid #c9cec4; border-radius: 10px; box-shadow: 0 2px 0 #dfe2db; font-size: 12px; color: #3d4943;+}+.stroke-bar.open { display: flex; }+.stroke-bar .what { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }+.stroke-bar button {+ font: inherit; font-weight: 700; display: flex; align-items: center; justify-content: center; min-width: 40px; min-height: 36px;+ padding: 0 12px; border-radius: 7px; border: 1px solid #3d4943; background: #f7f8f4; color: #3d4943; cursor: pointer;+}+.stroke-bar button.primary { background: #3d4943; color: #f7f8f4; padding: 0 16px; }@media (max-width: 1000px) {.system button.labelled { font-size: 0; gap: 0; padding: 6px 9px; }.toolbar button kbd, .toolbar .town-button kbd { display: none; }@@ -212,6 +225,10 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;/* ── The term: season, approval, the crown, dangers ── */.hud .clock .winter { color: #3d6db5; font-weight: 600; }+.hud .clock .paused-tag {+ margin-left: 6px; padding: 1px 5px; border-radius: 4px; background: #3d4943; color: #f7f8f4;+ font-size: 10px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; vertical-align: 2px;+}.hud .request, .hud .alarm { display: none; }.hud .request.show, .hud .alarm.show { display: flex; }.hud .request { border-color: #d6ae2e; box-shadow: 0 2px 0 #eadca7; width: 440px; max-width: 100%; box-sizing: border-box; }diff --git a/src/host.ts b/src/host.tsindex 7594f88..77ca8e0 100644--- a/src/host.ts+++ b/src/host.ts@@ -390,8 +390,9 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste].map(({ speed, label, key }) => {const button = el("button", speed === 0 ? "pause" : "", label)if (speed === 0) button.append(iconEl("pause", 14))- button.title = speed === 0 ? "Pause the town (space)" : `Run the town at ${label} (${key})`- button.onclick = () => setSpeed(speed)+ button.title = speed === 0 ? "Pause the town, or run it again (space)" : `Run the town at ${label} (${key})`+ // Pause is a switch: pressed again it runs the town at its last speed.+ button.onclick = () => setSpeed(speed === 0 && ui.speed === 0 ? lastSpeed : speed)speedGroup.append(button)return { speed, button }})@@ -406,8 +407,12 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persisteif (speed > 0) lastSpeed = speedui.speed = speedfor (const s of speeds) s.button.classList.toggle("on", s.speed === speed)+ // Paused, the pause button shows play.+ const pause = speeds[0]!.button+ pause.replaceChildren(iconEl(speed === 0 ? "play" : "pause", 14))+ pause.setAttribute("aria-label", speed === 0 ? "Run the town" : "Pause the town")cycle.textContent = `${speed === 0 ? lastSpeed : speed}×`- cycle.classList.toggle("paused", speed === 0)+ cycle.title = speed === 0 ? `Run the town at ${lastSpeed}×` : "Change speed: 1×, 2×, 4×"}setSpeed(1)@@ -564,7 +569,9 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persisteif (event.key === "2") setSpeed(2)if (event.key === "3") setSpeed(4)if (event.key === "Escape") {- if (ui.tool !== "select") choose("select")+ // A stroke being drawn or held is dropped first; the tool stays.+ if (ui.dragFrom) input.cancelStroke()+ else if (ui.tool !== "select") choose("select")else if (ui.menu) ui.menu = nullelse ui.selected = nullrefreshTools()@@ -1667,6 +1674,17 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste}const input = new MapInput(stage, ui)+ // A road, a row of homes, or a patch of park let go of on a touch screen is held here until built or dropped.+ const strokeBar = el("div", "stroke-bar")+ const strokeText = el("span", "what")+ const strokeBuild = el("button", "frame primary", "Build")+ strokeBuild.onclick = () => input.confirmStroke()+ const strokeDrop = el("button", "frame", "")+ strokeDrop.append(iconEl("close", 14))+ strokeDrop.setAttribute("aria-label", "Cancel")+ strokeDrop.onclick = () => input.cancelStroke()+ strokeBar.append(strokeText, strokeDrop, strokeBuild)+ document.body.append(strokeBar)const resetPage = () => {choose("select")ui.menu = null@@ -1742,7 +1760,7 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste: s.season.coming === null? "no more winters this term": `winter in ${clockText(s.season.left)}${severity(s.season.coming)}`- setHtml(clock, `${icon(s.season.winter ? "winter" : "clock", 20)}<span class="stack"><b>${clockText(left)}</b><small class="${s.season.winter ? "winter" : s.season.coming === "hard" ? "down" : ""}">year ${s.season.year} · ${until}</small></span>`)+ setHtml(clock, `${icon(s.season.winter ? "winter" : "clock", 20)}<span class="stack"><b>${clockText(left)}${ui.speed === 0 ? `<span class="paused-tag">paused</span>` : ""}</b><small class="${s.season.winter ? "winter" : s.season.coming === "hard" ? "down" : ""}">year ${s.season.year} · ${until}</small></span>`)clock.title = `${s.season.winter ? "Winter: fields lie still, fishing is slow, and homes eat faster" : "Time left in the term"}\nThe almanac: the coming winter is ${s.season.coming === null ? "beyond the term" : winters[s.season.coming].title}, the one after ${s.season.after === null ? "beyond the term" : winters[s.season.after].title}.\nMild: fishing at ${Math.round(winters.mild.fishing * 100)}%. Normal: ${Math.round(winters.normal.fishing * 100)}%. Hard: half as long again, fishing at ${Math.round(winters.hard.fishing * 100)}%, and homes heating are a fire risk.`const trend = s.mood.target > s.mood.approval ? "↑" : s.mood.target < s.mood.approval ? "↓" : ""setHtml(approval, `${icon("approval", 18)}<span class="stack"><b class="${s.mood.approval < 0 ? "down" : ""}">${signed(s.mood.approval)} <span class="${s.mood.target >= s.mood.approval ? "up" : "down"}">${trend}</span></b><small>approval</small></span>`)@@ -1883,8 +1901,13 @@ export const createHost = async (mount: HTMLElement, persistence: () => PersistesyncReckoning(s)}input.sync()- const screenPointer = input.pointer- const text = ui.preview.tooltip+ const screenPointer = input.tip+ // A stroke being drawn says what it lays and costs.+ const text = ui.dragFrom && ui.stroke !== "cancel" && ui.preview.stroke ? ui.preview.stroke : ui.preview.tooltip+ // A held touch stroke waits for its build button.+ const held = ui.stroke === "held" && ui.preview.stroke !== null+ if (held) strokeText.textContent = ui.preview.stroke+ strokeBar.classList.toggle("open", held)if (text && screenPointer) {tooltip.textContent = texttooltip.style.display = "block"diff --git a/src/phone.css b/src/phone.cssindex 50035e2..cb10510 100644--- a/src/phone.css+++ b/src/phone.css@@ -107,7 +107,6 @@.toolbar .speed { gap: 1px; }.toolbar .speed button:not(.pause):not(.cycle) { display: none; }.toolbar .speed button.cycle { display: flex; font-size: 12px; font-weight: 700; min-width: 38px; }- .toolbar .speed button.cycle.paused { color: #9aa29b; }.toolbar button.more { display: flex; }.toolbar button.more.on { background: #3d4943; }.toolbar button.more.on .icon circle { fill: #f7f8f4; }@@ -126,7 +125,8 @@font-size: 12px; gap: 10px; padding: 7px 12px 7px 9px; min-height: 34px; justify-content: flex-start; color: #3d4943;}- .toast { bottom: calc(100px + env(safe-area-inset-bottom)); max-width: calc(100vw - 28px); white-space: normal; text-align: center; }+ .toast { bottom: calc(108px + env(safe-area-inset-bottom)); max-width: calc(100vw - 28px); white-space: normal; text-align: center; }+ .stroke-bar { bottom: calc(56px + env(safe-area-inset-bottom)); width: max-content; }/* ── Dialogs: the whole screen, the body scrolling, the actions pinned to the bottom ── */.dialog { padding: 0; }@@ -201,12 +201,14 @@/* No hover, so no key hints. */.toolbar button kbd, .views button kbd { display: none; }.panel .close { min-width: 40px; min-height: 40px; }- /* The build hint follows no finger: it sits in one place above the tool bar. */+ /* The build hint follows no finger: a slim strip at the top, under the top line, clear of the town in the middle. */.tooltip {- left: 10px !important; right: 10px; top: auto !important; bottom: calc(100px + env(safe-area-inset-bottom));- transform: none; white-space: normal; text-align: center; font-size: 12px; line-height: 1.4;+ left: 50% !important; top: calc(58px + env(safe-area-inset-top)) !important; transform: translateX(-50%);+ width: max-content; max-width: calc(100vw - 20px); white-space: normal; text-align: center;+ font-size: 11px; line-height: 1.35; padding: 4px 10px; background: rgba(47, 70, 57, 0.82); border-radius: 6px;}}-@media (pointer: coarse) and (max-height: 500px) {- .tooltip { left: 25% !important; right: 25%; }+/* A portrait phone's top line takes two rows: the hint goes under both. */+@media (pointer: coarse) and (max-width: 760px) and (min-height: 501px) {+ .tooltip { top: calc(88px + env(safe-area-inset-top)) !important; }}diff --git a/src/present.ts b/src/present.tsindex dff32e7..24dfacf 100644--- a/src/present.ts+++ b/src/present.ts@@ -509,7 +509,19 @@ export const Interact = Game.System(else ui.flash = null}- if (ui.tool === "road" || ui.tool === "home" || ui.tool === "pave") {+ /** A cost `n` times over. */+ const times = (cost: Kind["cost"], n: number): Kind["cost"] => ({+ coins: cost.coins * n,+ materials: Object.fromEntries(Object.entries(cost.materials).map(([g, m]) => [g, (m ?? 0) * n]))+ })+ const counted = (n: number, what: string) => `${n} ${what}${n === 1 ? "" : "s"}`+ // Let go off the map (over the tool bar, say) and the stroke is dropped: it shows as blocked.+ const dropping = ui.stroke === "cancel" && ui.dragFrom !== null+ if (dropping && cell && (ui.tool === "road" || ui.tool === "home" || ui.tool === "pave" || ui.tool === "ground")) {+ for (const c of ui.tool === "ground" ? rectangle(ui.dragFrom!, cell) : lPath(ui.dragFrom!, cell))+ if (inside(c.x, c.y)) preview.plots.push({ ...c, size: 1, look: "blocked" })+ preview.tooltip = "let go here to cancel"+ } else if (ui.tool === "road" || ui.tool === "home" || ui.tool === "pave") {const cells = cell === null ? [] : ui.dragFrom ? lPath(ui.dragFrom, cell) : [cell]for (const c of cells) {if (!inside(c.x, c.y)) continue@@ -529,6 +541,15 @@ export const Interact = Game.System(preview.tooltip = `homes · ${costText(home.cost)} each · along a road · ${preview.rangeNote ?? "touch a road and residents walk to work within " + COMMUTE + " road cells"}`}if (ui.tool === "road" && cell) preview.tooltip = `road · ${ROAD_COST} coins a cell · buildings need one at the middle of a side`+ if (ui.dragFrom && cell) {+ const n = ui.tool === "road" ? preview.roads.length : ui.tool === "home" ? preview.ghosts.length : preview.plots.filter((p) => p.look === "reach").length+ preview.stroke =+ ui.tool === "road"+ ? `${counted(n, "road cell")} · ${costText({ coins: n * ROAD_COST, materials: {} })}`+ : ui.tool === "home"+ ? `${counted(n, "home")} · ${costText(times(home.cost, n))}`+ : `pave ${counted(n, "cell")} · ${costText({ coins: n * PAVE_COST.coins, materials: { stone: n * PAVE_COST.stone } })}`+ }} else if (ui.tool === "ground" && cell) {const laid: Array<ParkCell> = []for (const c of ui.dragFrom ? rectangle(ui.dragFrom, cell) : [cell]) {@@ -541,8 +562,9 @@ export const Interact = Game.System(const after = laid.length > 0 ? parkOf(laid[0]!, laid) : undefined// What the park it joins gives now, if it joins one.const before = laid.map((c) => parkOf(c)).find((p) => p !== undefined)- const cost = grounds[ui.ground].cost- preview.tooltip = `${grounds[ui.ground].title.toLowerCase()} · ${laid.length} cell${laid.length === 1 ? "" : "s"}, ${costText({ coins: cost.coins * laid.length, materials: Object.fromEntries(Object.entries(cost.materials).map(([g, n]) => [g, (n ?? 0) * laid.length])) })}${after ? ` · the park: ${parkText(after)}${before && before.value !== after.value ? ` (now ${signed(before.value)})` : ""}` : ""} · drag a rectangle`+ const cost = costText(times(grounds[ui.ground].cost, laid.length))+ if (ui.dragFrom) preview.stroke = `${grounds[ui.ground].title.toLowerCase()} · ${counted(laid.length, "cell")} · ${cost}`+ preview.tooltip = `${grounds[ui.ground].title.toLowerCase()} · ${counted(laid.length, "cell")}, ${cost}${after ? ` · the park: ${parkText(after)}${before && before.value !== after.value ? ` (now ${signed(before.value)})` : ""}` : ""} · drag a rectangle`if (after) preview.plots.push(...reachPlots(after))} else if (ui.tool === "prop" && cell && inside(cell.x, cell.y)) {const there = parkAt.get(key(cell.x, cell.y))?.data.park.get()@@ -908,7 +930,7 @@ export const Interact = Game.System(const lock = lockReason(kind, resources.census.get())if (lock) preview.tooltip = `${kind.title.toLowerCase()} · ${lock}`else preview.tooltip = `${kind.title.toLowerCase()}${r !== null ? ` · works ${r} cells around` : ""}${a ? ` · desirability ${signed(a.value)} out to ${a.reach} cells` : ""}${preview.rangeNote ? ` · ${preview.rangeNote}` : ""} · needs a road at the middle of a side`- } else if (ui.tool === "pave") preview.tooltip = `drag along a road to pave it · ${PAVE_COST.coins} coins and a stone a cell · carriers and walkers go half again as fast on it, and homes beside it like it a little`+ } else if (ui.tool === "pave" && !dropping) preview.tooltip = `drag along a road to pave it · ${PAVE_COST.coins} coins and a stone a cell · carriers and walkers go half again as fast on it, and homes beside it like it a little`else if (cell && ui.view === "appeal" && inside(cell.x, cell.y)) preview.tooltip = `desirability ${appealAt(cells, cell.x, cell.y)}`ui.preview = previewdiff --git a/src/render3d/input.ts b/src/render3d/input.tsindex 6ff4deb..8c11c39 100644--- a/src/render3d/input.ts+++ b/src/render3d/input.ts@@ -9,16 +9,28 @@ import type { GameScene } from "./scene.ts"* A finger has no hover, so on touch the tap tools (place, prop, bulldoze)* take two taps: the first shows the ghost or outline where it lands and* holds it there, a second tap on the same spot commits it. The game only- * ever sees the ordinary press and release of the confirming tap. */+ * ever sees the ordinary press and release of the confirming tap.+ *+ * The drag tools (road, pave, homes, park ground) work the same way on touch:+ * letting go holds the stroke, and a tap on its end (or the page's build+ * button) lays it; a tap anywhere else drops it, and dragging again starts a+ * new one. With any pointer, letting go off the map (over the tool bar, say)+ * drops the stroke, as a button drops a click released outside it. */export class MapInput {private scene: GameSceneprivate ui: UiValueprivate pointers = new Map<number, Point>()- private press: { id: number; start: Point; last: Point; mode: "edit" | "pan" | "rotate"; moved: boolean } | null = null+ /** `deferred`: a press while a stroke is held, which is a tap on it until it moves. */+ private press: { id: number; start: Point; last: Point; mode: "edit" | "pan" | "rotate"; moved: boolean; deferred: boolean } | null = nullprivate pinch: { distance: number; angle: number; mid: Point } | null = nullprivate screen: Point | null = nullprivate mode: "pan" | "rotate" = "pan"private armed: { tool: string; at: Point; hit: number | null } | null = null+ /** A touch stroke let go of and waiting for a tap: from `ui.dragFrom` to `at`. */+ private held: { tool: string; at: Point } | null = null+ /** The stroke being dragged is over something other than the map: let go, it is dropped. */+ private offMap = false+ private touch = falsereadonly controls: HTMLElementprivate abort = new AbortController()constructor(scene: GameScene, ui: UiValue) {@@ -34,13 +46,15 @@ export class MapInput {canvas.focus({ preventScroll: true })canvas.setPointerCapture(e.pointerId)const p = at(e)+ this.touch = e.pointerType === "touch"this.pointers.set(e.pointerId, p)this.screen = pthis.updatePointer()if (this.pointers.size === 2) {this.pinch = this.spread()this.press = null- ui.dragFrom = null+ // Two fingers move the camera under a held stroke; they drop one being drawn.+ if (!this.held) ui.dragFrom = nullui.gestures.length = 0return}@@ -55,8 +69,9 @@ export class MapInput {: ui.tool === "road" || ui.tool === "home" || ui.tool === "pave" || ui.tool === "ground"? "edit": "pan"- this.press = { id: e.pointerId, start: p, last: p, mode, moved: false }- if (e.button === 0 && this.mode !== "rotate") ui.gestures.push({ type: "press", at: scene.groundAt(p.x, p.y) })+ const deferred = mode === "edit" && this.held !== null+ this.press = { id: e.pointerId, start: p, last: p, mode, moved: false, deferred }+ if (e.button === 0 && this.mode !== "rotate" && !deferred) ui.gestures.push({ type: "press", at: scene.groundAt(p.x, p.y) })},{ signal })@@ -65,6 +80,7 @@ export class MapInput {(e) => {const p = at(e)if (e.pointerType === "mouse") this.armed = null+ if (this.pointers.has(e.pointerId) || e.pointerType === "mouse") this.touch = e.pointerType === "touch"if (this.pointers.has(e.pointerId)) this.pointers.set(e.pointerId, p)if (this.pinch && this.pointers.size === 2) {const next = this.spread()@@ -83,6 +99,13 @@ export class MapInput {if (Math.hypot(p.x - press.start.x, p.y - press.start.y) > 6) press.moved = trueif (press.mode === "rotate" && press.moved) scene.rotate((p.x - press.last.x) * 0.006, (p.y - press.last.y) * 0.004)if (press.mode === "pan" && press.moved) scene.pan(p.x - press.last.x, p.y - press.last.y)+ // Dragging from a held stroke draws a new one: the held one is dropped.+ if (press.deferred && press.moved) {+ this.cancelStroke()+ press.deferred = false+ ui.gestures.push({ type: "press", at: scene.groundAt(press.start.x, press.start.y) })+ }+ if (press.mode === "edit") this.offMap = this.overPage(p)press.last = p}this.screen = p@@ -96,15 +119,29 @@ export class MapInput {if (this.pinch) {if (this.pointers.size < 2) this.pinch = nullthis.press = null- ui.dragFrom = null+ if (!this.held) ui.dragFrom = null}const press = this.pressif (press?.id === e.pointerId) {const input = scene.inputAt(p.x, p.y, ui.tool)const panned = cancelled || press.mode === "rotate" || e.button !== 0 || (press.mode === "pan" && press.moved)- const held = e.pointerType === "touch" && !panned && this.arm(input.at, input.hit)- if (!held) ui.gestures.push({ type: "release", at: press.mode === "edit" ? scene.groundAt(p.x, p.y) : input.at, hit: input.hit, panned })- if (panned) ui.dragFrom = null+ const ground = scene.groundAt(p.x, p.y)+ if (press.deferred) {+ // A tap while a stroke is held: on the stroke's end it lays it, anywhere else it drops it.+ if (!panned && this.held) {+ if (Math.floor(ground.x) === Math.floor(this.held.at.x) && Math.floor(ground.y) === Math.floor(this.held.at.y)) this.confirmStroke()+ else this.cancelStroke()+ }+ } else if (press.mode === "edit" && !panned && this.offMap) {+ ui.dragFrom = null+ } else if (press.mode === "edit" && !panned && e.pointerType === "touch") {+ this.held = { tool: ui.tool, at: ground }+ } else {+ const held = e.pointerType === "touch" && !panned && this.arm(input.at, input.hit)+ if (!held) ui.gestures.push({ type: "release", at: press.mode === "edit" ? ground : input.at, hit: input.hit, panned })+ if (panned) ui.dragFrom = null+ }+ this.offMap = falsethis.press = null}if (e.pointerType !== "mouse") {@@ -125,7 +162,20 @@ export class MapInput {},{ signal })- canvas.addEventListener("contextmenu", (e) => e.preventDefault(), { signal })+ canvas.addEventListener(+ "contextmenu",+ (e) => {+ e.preventDefault()+ // A right click during a drag drops the stroke.+ if (this.press?.mode === "edit") {+ this.press = null+ this.offMap = false+ ui.dragFrom = null+ this.updatePointer()+ }+ },+ { signal }+ )canvas.addEventListener("wheel",(e) => {@@ -202,10 +252,39 @@ export class MapInput {this.updatePointer()return true}+ /** Whether a point on the screen is over the page rather than the map. */+ private overPage(p: Point) {+ const canvas = this.scene.canvas+ const box = canvas.getBoundingClientRect()+ if (p.x < box.left || p.y < box.top || p.x > box.right || p.y > box.bottom) return true+ return document.elementFromPoint(p.x, p.y) !== canvas+ }+ /** Lays the held stroke. */+ confirmStroke() {+ const held = this.held+ if (!held) return+ this.held = null+ this.ui.gestures.push({ type: "release", at: held.at, panned: false })+ this.updatePointer()+ }+ /** Drops the stroke being drawn or held. */+ cancelStroke() {+ this.held = null+ this.offMap = false+ if (this.press?.mode === "edit") this.press = null+ this.ui.dragFrom = null+ this.updatePointer()+ }private updatePointer() {if (this.armed && this.armed.tool !== this.ui.tool) this.armed = null+ // A held stroke goes with its tool, or once the page has dropped it (another tool chosen).+ if (this.held && (this.held.tool !== this.ui.tool || (this.ui.dragFrom === null && !this.ui.gestures.some((g) => g.type === "press")))) this.held = null+ this.ui.stroke = this.held ? "held" : this.offMap && this.press ? "cancel" : null// An armed tap holds the ghost where it landed, even while the map pans under it.- if (this.armed) {+ if (this.held) {+ this.ui.pointer = this.held.at+ this.ui.pointerHit = null+ } else if (this.armed) {this.ui.pointer = this.armed.atthis.ui.pointerHit = this.armed.hit} else if (this.screen) {@@ -220,6 +299,16 @@ export class MapInput {get pointer() {return this.screen}+ /** Where the tooltip goes, or `null` for none. A finger shows it only for what it is about to+ * build (a stroke being drawn, an armed tap), never while it moves the camera or picks a+ * building, whose panel says the same, nor for a held stroke, whose bar says it; the+ * stylesheet pins it to the top on touch. */+ get tip(): Point | null {+ if (!this.touch) return this.screen+ if (this.pinch || this.held) return null+ if (this.armed) return this.screen ?? { x: 0, y: 0 }+ return this.press?.mode === "edit" ? this.screen : null+ }sync() {this.updatePointer()this.controls.querySelector("output")!.textContent = this.scene.camera.zoom.toFixed(1) + "×"@@ -239,6 +328,8 @@ export class MapInput {reset() {this.mode = "pan"this.armed = null+ this.held = null+ this.offMap = falsethis.press = nullthis.pinch = nullthis.pointers.clear()diff --git a/src/ui.ts b/src/ui.tsindex b423ea9..4969e49 100644--- a/src/ui.ts+++ b/src/ui.ts@@ -103,9 +103,11 @@ export interface Preview {/** Bulldozing: the hovered thing is tinted. */danger: booleantooltip: string | null+ /** A road, pave, home, or park stroke being dragged: how much it lays and what it costs. */+ stroke: string | null}-export const emptyPreview = (): Preview => ({ plots: [], ghosts: [], roads: [], range: [], rangeNote: null, parks: [], hover: null, danger: false, tooltip: null })+export const emptyPreview = (): Preview => ({ plots: [], ghosts: [], roads: [], range: [], rangeNote: null, parks: [], hover: null, danger: false, tooltip: null, stroke: null })/** The side panel: the build menu, the town's numbers and taxes, a building, or a home. */export type Panel =@@ -301,6 +303,8 @@ export interface UiValue {pointerHit?: number | null/** Where a road, a row of homes, or a patch of park being dragged started. */dragFrom: Point | null+ /** The stroke from `dragFrom` is held for a tap to confirm (touch), or let go here it would be dropped (off the map). */+ stroke?: "held" | "cancel" | nullselected: number | nullgestures: Array<Gesture>edits: Array<Edit>