A town simulation in pale isometric line art, implemented with Ritmo ECS and PixiJs 3D
Credit Typeonce and ritmo, quietly
SandroMaglione95bebba08d27
diff --git a/src/ui/dom/brand/credit.ts b/src/ui/dom/brand/credit.tsnew file mode 100644index 0000000..cf657d0--- /dev/null+++ b/src/ui/dom/brand/credit.ts@@ -0,0 +1,118 @@+/**+ * The maker's credit: the Typeonce pixel lockup, a link to typeonce.games,+ * and "Made with ritmo", a link to the GitHub repository of the ECS runtime+ * the town is built on. Two places carry it, both out of the way of play:+ *+ * - `corner`: a small, pale note just above the system bar in the bottom+ * right, quieter than the town's own cards. It rides with the bar, never+ * asks for anything, and steps aside while the panel is open and on a phone.+ * - `line`: a footer along the bottom of the charter and the reckoning, the two+ * moments the town is waiting anyway.+ *+ * Every link is a real `<a>` that opens a new tab, so the town is never left.+ * While that tab is in front the town's frames stop (the loop clamps a frame to+ * a quarter of a second), so the term does not run on while the mayor is away.+ */+import { PIXEL_LETTERS, PIXEL_MARK_32, PIXEL_WORDMARK } from "./pixel-mark.ts"++/** The home of the maker's games. */+export const typeonceSite = "https://typeonce.games"+/** The ECS runtime the simulation runs on: its GitHub repository. */+export const ritmoSite = "https://github.com/typeonce-dev/ritmo"++// The brand's own layout: the letters' x-height starts on row 13 of the 32 px+// mark, two pixels after the mark and two between letters.+const MARK_SIZE = 32+const MARK_TO_TEXT = 2+const LETTER_GAP = 2+const TEXT_TOP = 13++/** The filled runs of one row of pixel art, as path commands at (`x`, `y`). */+const rowPath = (row: string, x: number, y: number): string => {+ let path = ""+ for (let from = 0; from < row.length; from++) {+ if (row[from] !== "#") continue+ let to = from+ while (row[to + 1] === "#") to+++ path += `M${x + from} ${y}h${to - from + 1}v1h${-(to - from + 1)}z`+ from = to+ }+ return path+}+const art = (rows: ReadonlyArray<string>, x: number, y: number): string => rows.map((row, i) => rowPath(row, x, y + i)).join("")++let letterX = MARK_SIZE + MARK_TO_TEXT+const letters = PIXEL_WORDMARK.map((letter) => {+ const rows = PIXEL_LETTERS[letter]+ const path = art(rows, letterX, TEXT_TOP)+ letterX += (rows[0]?.length ?? 0) + LETTER_GAP+ return path+}).join("")+const lockupWidth = letterX - LETTER_GAP+const lockupPath = art(PIXEL_MARK_32, 0, 0) + letters++/** An arrow pointing up and out, in the lockup's own pixels. */+const ARROW = ["..#####", "..#####", "....###", "...####", "..##.##", ".##....", "##....."]+const arrowPath = art(ARROW, 0, 0)++const svg = (path: string, width: number, height: number, size: number, className: string): SVGSVGElement => {+ const node = document.createElementNS("http://www.w3.org/2000/svg", "svg")+ node.setAttribute("viewBox", `0 0 ${width} ${height}`)+ node.setAttribute("width", String((size * width) / height))+ node.setAttribute("height", String(size))+ node.setAttribute("shape-rendering", "crispEdges")+ node.setAttribute("aria-hidden", "true")+ node.classList.add(className)+ const fill = document.createElementNS("http://www.w3.org/2000/svg", "path")+ fill.setAttribute("d", path)+ fill.setAttribute("fill", "currentColor")+ node.append(fill)+ return node+}++const link = (href: string, label: string, ...content: Array<Node>): HTMLAnchorElement => {+ const a = document.createElement("a")+ a.href = href+ a.target = "_blank"+ a.rel = "noopener"+ a.setAttribute("aria-label", `${label} (opens in a new tab)`)+ a.append(...content)+ // The keys belong to the town again as soon as the link has been used.+ a.addEventListener("click", () => a.blur())+ return a+}++const text = (className: string, value: string): HTMLSpanElement => {+ const span = document.createElement("span")+ span.className = className+ span.textContent = value+ return span+}++/** The two links, `lockup` CSS pixels tall for the mark. */+const links = (lockup: number): Array<Node> => [+ link(+ typeonceSite,+ "Typeonce Games: more games by the maker of Inkline Town",+ svg(lockupPath, lockupWidth, MARK_SIZE, lockup, "lockup")+ ),+ text("dot", "·"),+ link(ritmoSite, "ritmo on GitHub: the ECS runtime Inkline Town is made with", text("what", "Made with"), text("name", "ritmo"), svg(arrowPath, ARROW.length, ARROW.length, 7, "arrow"))+]++/** The note in the bottom-right corner. */+export const createCreditCorner = (): HTMLElement => {+ const note = document.createElement("nav")+ note.className = "credit corner"+ note.setAttribute("aria-label", "Made by Typeonce")+ note.append(...links(16))+ return note+}++/** The footer of a dialog. */+export const createCreditLine = (): HTMLElement => {+ const line = document.createElement("footer")+ line.className = "credit line"+ line.append(...links(16))+ return line+}diff --git a/src/ui/dom/brand/pixel-mark.ts b/src/ui/dom/brand/pixel-mark.tsnew file mode 100644index 0000000..981a913--- /dev/null+++ b/src/ui/dom/brand/pixel-mark.ts@@ -0,0 +1,157 @@+// Copied from typeonce-dev packages/brand/src (commit 612caa02). Change it there and copy it again.+// Pixel-art versions of the Typeonce mark, for games. Each string is one row+// and `#` is one filled pixel. `pnpm brand:generate` (in `apps/dev`) renders+// them into `apps/dev/docs/brand/pixel/`.+//+// The grids put the vector construction (`./mark.ts`) on whole+// pixels: bar and ear 4 / 8, gap 2 / 4, stem 5 / 10 at 16 / 32 px. The stem+// top and the ear's end land on the golden sections of the square, the inner+// curve shares its centre with the stem shoulder, and every leaf corner uses+// the same steps. Tips are square pixels.+export const PIXEL_MARK_16 = [+ "....############",+ "..##############",+ ".##############.",+ ".#############..",+ "#######.........",+ "######..........",+ "#####...###.....",+ "####...####.....",+ ".###..#####.....",+ "..##..#####.....",+ "......#####.....",+ "......#####.....",+ "......#####.....",+ "......#####.....",+ "......####......",+ "......###.......",+];++export const PIXEL_MARK_32 = [+ ".........#######################",+ ".......#########################",+ ".....###########################",+ "....###########################.",+ "...############################.",+ "..############################..",+ "..###########################...",+ ".##########################.....",+ ".###############................",+ "##############..................",+ "############....................",+ "###########.....................",+ "##########.......#####..........",+ "##########.....#######..........",+ "#########.....########..........",+ ".########....#########..........",+ ".#######.....#########..........",+ "..######....##########..........",+ "...#####....##########..........",+ ".....###....##########..........",+ "............##########..........",+ "............##########..........",+ "............##########..........",+ "............##########..........",+ "............##########..........",+ "............##########..........",+ "............##########..........",+ "............#########...........",+ "............#########...........",+ "............########............",+ "............#######.............",+ "............#####...............",+];++// Letters for the wordmark next to the 32 px mark: x-height 11 (rows 0-10),+// descenders to row 14, 3 px stems, and the mark's corner steps.+export const PIXEL_LETTERS = {+ y: [+ "###.....###",+ "###.....###",+ ".###...###.",+ ".###...###.",+ "..###..###.",+ "..###.###..",+ "..###.###..",+ "...#####...",+ "...#####...",+ "....###....",+ "....###....",+ "....###....",+ "...###.....",+ "#####......",+ "####.......",+ ],+ p: [+ "###.#####..",+ "##########.",+ "####...####",+ "###.....###",+ "###.....###",+ "###.....###",+ "###.....###",+ "###.....###",+ "####...####",+ "##########.",+ "###.#####..",+ "###........",+ "###........",+ "###........",+ "###........",+ ],+ e: [+ "...#####...",+ ".#########.",+ "####...####",+ "###.....###",+ "###########",+ "###########",+ "###........",+ "###........",+ "####...###.",+ ".#########.",+ "...#####...",+ ],+ o: [+ "...#####...",+ ".#########.",+ "####...####",+ "###.....###",+ "###.....###",+ "###.....###",+ "###.....###",+ "###.....###",+ "####...####",+ ".#########.",+ "...#####...",+ ],+ n: [+ "###.####..",+ "#########.",+ "####...###",+ "###....###",+ "###....###",+ "###....###",+ "###....###",+ "###....###",+ "###....###",+ "###....###",+ "###....###",+ ],+ c: [+ "...#####..",+ ".########.",+ "####...###",+ "###.......",+ "###.......",+ "###.......",+ "###.......",+ "###.......",+ "####...###",+ ".########.",+ "...#####..",+ ],+} as const;++// The letters after the T, in order.+export const PIXEL_WORDMARK = ["y", "p", "e", "o", "n", "c", "e"] as const;diff --git a/src/ui/dom/screens/charter.ts b/src/ui/dom/screens/charter.tsindex 6ff019f..fa2ef95 100644--- a/src/ui/dom/screens/charter.ts+++ b/src/ui/dom/screens/charter.ts@@ -10,6 +10,7 @@ import { generate } from "../../../game/world/mapgen.ts"import type { Interaction } from "../../../view/contracts.ts"import type { IconName } from "../../../view/icons.ts"import type { Controls } from "../controls.ts"+import { createCreditLine } from "../brand/credit.ts"import { el, escapeHtml, setHtml } from "../kit/dom.ts"import { icon } from "../kit/icons.ts"import { section } from "../kit/section.ts"@@ -201,7 +202,7 @@ export const createCharter = (cancel.onclick = () => closeCharter()actions.append(cancel)}- card.append(body, actions)+ card.append(body, actions, createCreditLine())dialog.append(card)dialog.classList.add("open")}diff --git a/src/ui/dom/screens/reckoning.ts b/src/ui/dom/screens/reckoning.tsindex a3bb3c2..a0e0ef0 100644--- a/src/ui/dom/screens/reckoning.ts+++ b/src/ui/dom/screens/reckoning.ts@@ -7,6 +7,7 @@ import { sizes } from "../../../game/content/index.ts"import type { Edit } from "../../../game/edits.ts"import type { Interaction, Stats } from "../../../view/contracts.ts"import type { Controls } from "../controls.ts"+import { createCreditLine } from "../brand/credit.ts"import { el } from "../kit/dom.ts"import { clockText, signed } from "../kit/text.ts"import { verdictOf } from "./share-card.ts"@@ -113,7 +114,7 @@ export const createReckoning = (ui: Interaction, stats: () => Stats | null, sendshare.title = "A picture of the town and its verdict, or a link anyone can open"share.onclick = () => controls.openShare()actions.append(again, look, share)- card.append(actions)+ card.append(actions, createCreditLine())reckoning.append(card)showReckoning(true)}diff --git a/src/ui/dom/styles/factory.css b/src/ui/dom/styles/factory.cssindex ac73d61..8db424c 100644--- a/src/ui/dom/styles/factory.css+++ b/src/ui/dom/styles/factory.css@@ -599,3 +599,22 @@ kbd.key {.panel .deal-line .mode { width: 12ch; text-align: right; font-size: 11px; color: #9aa29b; white-space: nowrap; }.panel .deal-line .mode.sell { color: #4f8a3e; font-weight: 700; }.panel .deal-line .mode.buy { color: #3d6db5; font-weight: 700; }++/* ── The maker's credit (`brand/credit.ts`): quieter than the town's own cards ── */+.credit { display: flex; align-items: center; gap: 8px; font-size: 11px; line-height: 1; color: #8a938c; white-space: nowrap; }+.credit a { display: inline-flex; align-items: center; gap: 6px; color: inherit; text-decoration: none; border-radius: 4px; transition: color 140ms ease; }+.credit a:hover, .credit a:focus-visible { color: #3d4943; outline: none; }+.credit a:focus-visible { box-shadow: 0 0 0 1px #3d4943; }+.credit svg { display: block; flex: none; }+.credit .lockup { margin-top: -1px; }+.credit .arrow { opacity: 0.45; transition: opacity 140ms ease, transform 140ms ease; }+.credit a:hover .arrow, .credit a:focus-visible .arrow { opacity: 1; transform: translate(1px, -1px); }+.credit .name { font-weight: 700; margin-left: -1px; }+.credit .dot { color: #c3c8bf; }+/* Just above the system bar, its right edges lined up: it rides with the bar. */+.credit.corner {+ position: absolute; right: -1px; bottom: calc(100% + 8px); padding: 6px 10px;+ background: rgba(247, 248, 244, 0.94); border: 1px solid #dfe2db; border-radius: 6px;+}+.panel-open .credit.corner { display: none; }+.credit.line { justify-content: flex-end; margin-top: 18px; padding-top: 12px; border-top: 1px dashed #d3d7ce; }diff --git a/src/ui/dom/styles/phone.css b/src/ui/dom/styles/phone.cssindex 96f4ee7..fa499d8 100644--- a/src/ui/dom/styles/phone.css+++ b/src/ui/dom/styles/phone.css@@ -140,6 +140,7 @@padding: 4px; gap: 1px; z-index: 4;}.fold-more .system .phone-only { display: flex; }+ .system .credit.corner { display: none; }.fold-more .system button, .fold-more .system button.labelled {font-size: 12px; gap: 10px; padding: 7px 12px 7px 9px; min-height: 34px; justify-content: flex-start; color: #3d4943;}@@ -167,6 +168,9 @@}.dialog .sheet > .actions .frame { flex: 1; justify-content: center; padding: 10px 12px; }.dialog .sheet > .actions .frame.primary { flex: 2; }+ /* The credit stays with the content, above the buttons pinned to the bottom. */+ .dialog .sheet > .credit.line { order: 1; margin-top: 4px; padding-bottom: 14px; }+ .dialog .sheet:has(> .credit.line) > .actions { order: 2; }/* Room under the last of the content, so it never ends tucked against the buttons. */.dialog .charter { padding-bottom: 18px; }.dialog h2 { font-size: 17px; }diff --git a/src/ui/dom/system-menu.ts b/src/ui/dom/system-menu.tsindex 28cbb8d..481e0bc 100644--- a/src/ui/dom/system-menu.ts+++ b/src/ui/dom/system-menu.ts@@ -6,6 +6,7 @@import type { Interaction, Stats } from "../../view/contracts.ts"import type { IconName } from "../../view/icons.ts"import type { Controls, Fold } from "./controls.ts"+import { createCreditCorner } from "./brand/credit.ts"import { el } from "./kit/dom.ts"import { iconEl } from "./kit/icons.ts"@@ -44,6 +45,8 @@ export const createSystemMenu = (// A phone has no camera bar: this puts the camera back.action("view", "recentre", "Back to the original angle and centre", resetCamera)system.lastElementChild!.classList.add("phone-only")+ // The maker's credit rides just above the bar, wherever the bar goes.+ system.append(createCreditCorner())// A choice from the menu folds it.system.addEventListener("click", () => {if (fold() === "more") controls.setFold(null)