Skip to content

A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D

Make the game playable on phones

Claude67f7af71afc7
diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md
index 4f32cfb..ad546fa 100644
--- a/DEVELOPMENT.md
+++ b/DEVELOPMENT.md
@@ -28,7 +28,19 @@ drive the approved 3D models. Drag to pan; right-drag or choose **Rotate** to
turn and tilt. Scroll to zoom. Q/E turn, arrow keys pan, Home resets, and
the camera toolbar provides the same controls. On touch screens, two fingers
pan and pinch to zoom; twisting them rotates. Road/home tools still drag to
-build; camera gestures never place anything.
+build; camera gestures never place anything. A finger has no hover, so on
+touch the tap tools (buildings, park pieces, bulldoze) take two taps: the
+first 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.
+
+Phones get their layout from `src/phone.css`, loaded after `factory.css`. It
+only moves and resizes what `factory.css` draws, in three media queries:
+compact (narrow or short screens: icon-only bars, a two-line ticker),
+portrait (chrome stacked top and bottom, the panel as a bottom sheet) and
+touch (bigger targets, no key hints, the hint line pinned above the bars).
+New UI needs nothing there unless it has to move on a phone; check it at
+390×844, 360×640 and 844×390.
`src/render3d/scene.ts` owns the orthographic camera, ground projection and
frame source. `views.ts` follows live construction, upgrades, resources,
diff --git a/docs/screenshots/phone-landscape.webp b/docs/screenshots/phone-landscape.webp
new file mode 100644
index 0000000..546cafb
Binary files /dev/null and b/docs/screenshots/phone-landscape.webp differ
diff --git a/docs/screenshots/phone-place.webp b/docs/screenshots/phone-place.webp
new file mode 100644
index 0000000..d0c881e
Binary files /dev/null and b/docs/screenshots/phone-place.webp differ
diff --git a/docs/screenshots/phone-portrait.webp b/docs/screenshots/phone-portrait.webp
new file mode 100644
index 0000000..cda496c
Binary files /dev/null and b/docs/screenshots/phone-portrait.webp differ
diff --git a/docs/screenshots/phone-road.webp b/docs/screenshots/phone-road.webp
new file mode 100644
index 0000000..2a88640
Binary files /dev/null and b/docs/screenshots/phone-road.webp differ
diff --git a/docs/screenshots/phone-sheet.webp b/docs/screenshots/phone-sheet.webp
new file mode 100644
index 0000000..55fda4a
Binary files /dev/null and b/docs/screenshots/phone-sheet.webp differ
diff --git a/index.html b/index.html
index 7b52a2b..b054778 100644
--- a/index.html
+++ b/index.html
@@ -2,10 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
+ <meta name="theme-color" content="#f0f2ec" />
<title>Inkline Town</title>
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<link rel="stylesheet" href="/src/factory.css" />
+ <link rel="stylesheet" href="/src/phone.css" />
</head>
<body>
<div id="app"></div>
diff --git a/scripts/check-browser.ts b/scripts/check-browser.ts
index 78c8366..292fb46 100644
--- a/scripts/check-browser.ts
+++ b/scripts/check-browser.ts
@@ -160,7 +160,6 @@ try {
await page.setViewportSize({width:390,height:844})
await page.getByRole("button",{name:"Reset camera",exact:true}).click()
await page.getByRole("button",{name:"Rotate map left",exact:true}).click()
- await page.getByRole("button",{name:"Zoom in",exact:true}).click()
assert.equal(await page.evaluate(()=>[...document.querySelectorAll(".camera-controls,.toolbar,.system,.hud")].some(e=>{const r=e.getBoundingClientRect();return r.left<0||r.right>innerWidth+1})),false)
facts.phoneViewport=true
await tool("homes")
diff --git a/src/factory.css b/src/factory.css
index 64056c8..6f397db 100644
--- a/src/factory.css
+++ b/src/factory.css
@@ -258,20 +258,6 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}
.result.show { display: block; }
-@media(max-width:760px){
- .hud.left {left:10px;right:10px;max-width:none}
- .hud.right,.panel-open .hud.right {top:64px;left:10px;right:10px;max-width:none;align-items:flex-start}
- .hud .card .cell {padding:7px 9px}
- .hud.left .stock {margin-top:48px;max-width:100%;overflow-x:auto;flex:none}
- .hud .stock .group {flex:none}
- .hud.right .card {max-width:100%;overflow-x:auto}
- .toolbar {left:10px;right:10px;bottom:calc(64px + env(safe-area-inset-bottom))}
- .toolbar .group,.toolbar .town-button {flex:none}
- .system,.panel-open .system {right:10px;bottom:calc(12px + env(safe-area-inset-bottom))}
- .camera-controls {left:10px;max-width:calc(100vw - 20px);bottom:calc(118px + env(safe-area-inset-bottom))}
- .camera-controls button {padding:6px 7px;min-height:34px}
- .panel {width:calc(100vw - 24px);max-width:360px}
- .toast {bottom:calc(165px + env(safe-area-inset-bottom));max-width:calc(100vw - 28px)}
}
/* ── The town ticker, map views and their legend ── */
diff --git a/src/host.ts b/src/host.ts
index b431e0d..4604691 100644
--- a/src/host.ts
+++ b/src/host.ts
@@ -298,7 +298,7 @@ export const createHost = async (mount: HTMLElement, persistence: () => Persiste
toolGroup.append(button)
return { tool, button }
})
- const speedGroup = el("div", "group")
+ const speedGroup = el("div", "group speed")
toolbar.append(speedGroup)
const speeds = [
{ speed: 0, label: "", key: "space" },
diff --git a/src/phone.css b/src/phone.css
new file mode 100644
index 0000000..777d487
--- /dev/null
+++ b/src/phone.css
@@ -0,0 +1,109 @@
+/* ── Phones and other small or touch screens ──
+ * Layout only: every rule here rearranges or resizes the page that
+ * factory.css draws, so new UI works on a phone by default and only needs a
+ * line here when it has to move. Three layers, each a media query:
+ * compact (narrow or short screens): icon-only bars, a shorter ticker
+ * portrait (narrow screens): the chrome stacked top and bottom, the panel as a bottom sheet
+ * touch (coarse pointers): bigger targets, no key hints, the hint line pinned
+ */
+
+/* ── Compact: narrow (portrait phone) or short (landscape phone) ── */
+@media (max-width: 760px), (max-height: 500px) {
+ /* The bars keep their icons; the words are in each button's title. */
+ .toolbar button, .toolbar .town-button { font-size: 0; gap: 0; padding: 6px; min-width: 40px; min-height: 40px; justify-content: center; }
+ .toolbar .speed button { font-size: 12px; min-width: 36px; }
+ .toolbar button kbd { display: none; }
+ .system button { font-size: 0; gap: 0; padding: 6px; min-width: 38px; min-height: 38px; justify-content: center; }
+ .camera-controls [data-mode="pan"], .camera-controls output { display: none; }
+
+ /* The goods on one line that scrolls, a little smaller. */
+ .hud .stock { max-width: 100%; overflow-x: auto; flex: none; padding: 4px; scrollbar-width: none; }
+ .hud .stock .group { flex: none; gap: 3px; padding: 0 3px; }
+ .hud .good { gap: 4px; padding: 3px 7px 3px 4px; }
+ .hud .good .count { font-size: 12px; }
+
+ /* The ticker: only what needs looking at now, in at most two lines. */
+ .hud .ticker .head, .hud .ticker .cell ~ .cell { display: none; }
+ .hud .ticker .cell { padding: 6px 4px 6px 12px; font-size: 11px; line-height: 1.45; }
+ .hud .ticker .cell .text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
+
+ /* The map overlays: a column of icons on the right, the legend beside it. */
+ .views { top: auto; right: 10px; bottom: calc(120px + env(safe-area-inset-bottom)); flex-direction: column; max-width: none; }
+ .views button { font-size: 0; gap: 0; padding: 7px; justify-content: center; }
+ .views button kbd, .views-title { display: none; }
+ .legend { top: auto; right: 64px; bottom: calc(120px + env(safe-area-inset-bottom)); max-width: min(220px, calc(100vw - 84px)); }
+}
+
+/* ── Portrait phone: stacked chrome, map in the middle, panel from the bottom ── */
+@media (max-width: 760px) {
+ /* Top: the clock and treasury (with save and load beside them), the people, the goods, the ticker. */
+ .hud { top: calc(8px + env(safe-area-inset-top)); gap: 6px; }
+ .hud.left { left: 10px; right: 10px; max-width: none; }
+ .hud.right, .panel-open .hud.right { top: calc(58px + env(safe-area-inset-top)); left: 10px; right: auto; max-width: calc(100vw - 20px); align-items: flex-start; }
+ .hud .card .cell { padding: 6px 9px; gap: 7px; }
+ .hud .stack b { font-size: 14px; }
+ .hud .coins b { font-size: 15px; }
+ .hud.left .stock { margin-top: 48px; }
+ .hud .ticker { width: auto; }
+ .system, .panel-open .system { top: calc(8px + env(safe-area-inset-top)); bottom: auto; right: 10px; padding: 3px; }
+ .system button { min-height: 32px; }
+
+ /* Bottom: the tools along the edge; the camera and the speed just above them. */
+ .toolbar { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); justify-content: center; overflow: visible; max-width: none; }
+ .toolbar .group, .toolbar .town-button { flex: none; }
+ .toolbar .speed { position: fixed; right: 10px; bottom: calc(66px + env(safe-area-inset-bottom)); padding: 3px; }
+ .toolbar .speed button { min-height: 38px; }
+ /* Pinch zooms, so the zoom buttons give their room to the speed. */
+ .camera-controls { left: 10px; bottom: calc(66px + env(safe-area-inset-bottom)); padding: 3px; }
+ .camera-controls [data-action="in"], .camera-controls [data-action="out"] { display: none; }
+ .camera-controls button { min-height: 38px; padding: 6px 9px; }
+ .toast { bottom: calc(120px + env(safe-area-inset-bottom)); max-width: calc(100vw - 28px); white-space: normal; text-align: center; }
+
+ /* The panel slides up as a sheet over the bottom half, so the town stays in view above it. */
+ .panel {
+ top: auto; left: 0; width: auto; max-width: none; height: 58dvh; border-left: 0; border-top: 1px solid #c3c8bf;
+ border-radius: 14px 14px 0 0; box-shadow: 0 -3px 0 #dfe2db; padding-top: 22px; transform: translateY(100%);
+ }
+ .panel::before { content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: #c9cec4; }
+ .panel.open { transform: none; }
+ .panel-open .hud .stock, .panel-open .hud .ticker, .panel-open .hud .request, .panel-open .hud .alarm, .panel-open .views, .panel-open .legend { display: none; }
+}
+
+/* A very narrow phone: a little less padding so the tool row still fits. */
+@media (max-width: 370px) {
+ .toolbar .group { gap: 2px; padding: 3px; }
+ .toolbar button, .toolbar .town-button { min-width: 38px; }
+ .camera-controls button { padding: 6px; min-width: 34px; }
+ .toolbar .speed button { min-width: 32px; padding: 6px 4px; }
+}
+
+/* ── Landscape phone: short, so the bars stay low and the panel keeps to the side ── */
+@media (max-height: 500px) {
+ .hud { top: calc(6px + env(safe-area-inset-top)); gap: 5px; }
+ .hud .card .cell { padding: 5px 10px; }
+ .toolbar { bottom: calc(6px + env(safe-area-inset-bottom)); }
+ .system { bottom: calc(6px + env(safe-area-inset-bottom)); }
+ .panel-open .system { display: none; }
+ .camera-controls { bottom: calc(60px + env(safe-area-inset-bottom)); padding: 3px; }
+ .views { bottom: calc(60px + env(safe-area-inset-bottom)); }
+ .legend { bottom: calc(60px + env(safe-area-inset-bottom)); }
+ .toast { bottom: calc(110px + env(safe-area-inset-bottom)); }
+ .panel { padding-top: 12px; }
+}
+
+/* ── Touch: fingers instead of a mouse ── */
+@media (pointer: coarse) {
+ /* No hover, so no key hints; targets big enough for a thumb. */
+ .toolbar button kbd, .views button kbd { display: none; }
+ .camera-controls button, .views button { min-width: 40px; min-height: 40px; }
+ .panel .close { min-width: 40px; min-height: 40px; }
+ .hud .ticker .act { width: 32px; height: 32px; opacity: 0.6; }
+ /* The build hint follows no finger: it sits in one place above the bottom bars. */
+ .tooltip {
+ left: 10px !important; right: 62px; top: auto !important; bottom: calc(120px + env(safe-area-inset-bottom));
+ transform: none; white-space: normal; text-align: center; font-size: 12px; line-height: 1.4;
+ }
+}
+@media (pointer: coarse) and (max-height: 500px) {
+ .tooltip { bottom: calc(110px + env(safe-area-inset-bottom)); left: 25% !important; right: 25%; }
+}
diff --git a/src/render3d/input.ts b/src/render3d/input.ts
index 29fcabf..836567c 100644
--- a/src/render3d/input.ts
+++ b/src/render3d/input.ts
@@ -4,7 +4,12 @@ import type { GameScene } from "./scene.ts"
/** Camera gestures and game gestures share the canvas, but a pan, orbit or
* pinch never commits a build stroke or a selection. Game coordinates come
- * from the ground ray; object IDs come from the rendered instances. */
+ * from the ground ray; object IDs come from the rendered instances.
+ *
+ * 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. */
export class MapInput {
private scene: GameScene
private ui: UiValue
@@ -13,6 +18,7 @@ export class MapInput {
private pinch: { distance: number; angle: number; mid: Point } | null = null
private screen: Point | null = null
private mode: "pan" | "rotate" = "pan"
+ private armed: { tool: string; at: Point; hit: number | null } | null = null
readonly controls: HTMLElement
private abort = new AbortController()
constructor(scene: GameScene, ui: UiValue) {
@@ -58,6 +64,7 @@ export class MapInput {
"pointermove",
(e) => {
const p = at(e)
+ if (e.pointerType === "mouse") this.armed = null
if (this.pointers.has(e.pointerId)) this.pointers.set(e.pointerId, p)
if (this.pinch && this.pointers.size === 2) {
const next = this.spread()
@@ -95,14 +102,14 @@ export class MapInput {
if (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)
- ui.gestures.push({ type: "release", at: press.mode === "edit" ? scene.groundAt(p.x, p.y) : input.at, hit: input.hit, panned })
+ 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
this.press = null
}
if (e.pointerType !== "mouse") {
this.screen = null
- ui.pointer = null
- ui.pointerHit = null
+ this.updatePointer()
}
}
canvas.addEventListener("pointerup", (e) => release(e, false), { signal })
@@ -136,7 +143,8 @@ export class MapInput {
(button) =>
(button.onclick = () => {
if (button.dataset.mode) {
- this.mode = button.dataset.mode as "pan" | "rotate"
+ // Rotate toggles, so a phone can do without the Pan button.
+ this.mode = button.dataset.mode === "rotate" && this.mode === "rotate" ? "pan" : (button.dataset.mode as "pan" | "rotate")
ui.dragFrom = null
this.press = null
}
@@ -182,11 +190,33 @@ export class MapInput {
}
: null
}
+ /** A touch tap with a tap tool: the first tap arms (and returns true, so the
+ * release is held back); a second on the same spot lets the release through. */
+ private arm(at: Point, hit: number | null) {
+ const tool = this.ui.tool
+ if (tool !== "place" && tool !== "prop" && tool !== "bulldoze") return false
+ const armed = this.armed
+ this.armed = null
+ const same = armed && armed.tool === tool && (tool === "bulldoze" && hit !== null ? armed.hit === hit : Math.hypot(armed.at.x - at.x, armed.at.y - at.y) < 1.5)
+ if (same) return false
+ this.armed = { tool, at, hit }
+ this.ui.toast(tool === "bulldoze" ? "tap it again to remove it" : "tap it again to build it here")
+ this.updatePointer()
+ return true
+ }
private updatePointer() {
- if (this.screen) {
+ if (this.armed && this.armed.tool !== this.ui.tool) this.armed = null
+ // An armed tap holds the ghost where it landed, even while the map pans under it.
+ if (this.armed) {
+ this.ui.pointer = this.armed.at
+ this.ui.pointerHit = this.armed.hit
+ } else if (this.screen) {
const input = this.scene.inputAt(this.screen.x, this.screen.y, this.ui.tool)
this.ui.pointer = input.at
this.ui.pointerHit = input.hit
+ } else {
+ this.ui.pointer = null
+ this.ui.pointerHit = null
}
}
get pointer() {
@@ -210,6 +240,7 @@ export class MapInput {
}
reset() {
this.mode = "pan"
+ this.armed = null
this.press = null
this.pinch = null
this.pointers.clear()