Skip to content

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

An upgrade's panel says what is paid now, what is carried in later, and what it gives

SandroMaglione80edc32389b8
diff --git a/scripts/look-ui.ts b/scripts/look-ui.ts
index d1a65ab..f6d265e 100644
--- a/scripts/look-ui.ts
+++ b/scripts/look-ui.ts
@@ -113,6 +113,47 @@ for (const [name, width, height, phone] of [["desktop", 1440, 1000, false], ["ph
await shot("5-town-hall")
await close()
+ // 3b. Works in progress: one building of each kind that has an upgrade, begun together, seen early, midway and done
+ // (desktop only), with the panel of the first while its works go on.
+ if (!phone) {
+ await page.evaluate(() => {
+ const { runtime } = (window as any).town
+ const s = runtime.snapshot()
+ s.resources["Town/Treasury"].coins = 20000
+ for (const e of s.entities) {
+ const inv = e.components["Town/Inventory"]
+ if (e.components["Town/Storage"] && inv) inv.stock = { ...inv.stock, planks: Math.min(inv.cap, 120), stone: Math.min(inv.cap, 120), tools: Math.min(inv.cap, 40), cloth: Math.min(inv.cap, 40) }
+ }
+ runtime.restore(s)
+ })
+ const kinds = ["townhall", "warehouse", "farm", "bakery", "market", "chapel", "quarry", "firewatch"]
+ const picked: Array<{ kind: string; tile: Tile }> = []
+ for (const kind of kinds) {
+ const b = await find(page, (e) => (e.components["Town/Building"]?.kind === kind || (kind === "townhall" && e.components["Town/TownHall"])) && !e.components["Town/Site"] && !e.components["Town/Works"])
+ if (!b) continue
+ const tile: Tile = b.components["Town/Tile"]
+ picked.push({ kind, tile })
+ await page.evaluate((t) => (window as any).town.ui.edits.push({ type: "upgrade", cell: { x: t.x, y: t.y } }), tile)
+ }
+ await page.evaluate(() => (window as any).town.advance(1))
+ const progress = async () => (await town(page)).entities.filter((e: any) => e.components["Town/Works"]).length
+ for (const [stage, seconds] of [["early", 12], ["midway", 40], ["done", 400]] as const) {
+ await page.evaluate((n) => (window as any).town.advance(n), seconds)
+ for (const { kind, tile } of picked) {
+ await look(tile.x + tile.size / 2, tile.y + tile.size / 2, kind === "townhall" ? 2.2 : 2.8)
+ await settle()
+ await page.screenshot({ path: `${out}/${name}-works-${kind}-${stage}.png`, clip: { x: width / 2 - 360, y: height / 2 - 300, width: 720, height: 520 } })
+ }
+ if (stage === "early" && picked[0]) {
+ await look(picked[0].tile.x + 1.5, picked[0].tile.y + 1.5, 2)
+ await pick(picked[0].tile, 20)
+ await shot("works-panel")
+ await close()
+ }
+ }
+ console.log(JSON.stringify({ upgraded: picked.map((p) => p.kind), underway: await progress() }))
+ }
+
// 4. The build menu: no upgrades in it now.
await page.locator(".toolbar button").filter({ hasText: /^build/i }).first().click()
await settle()
diff --git a/src/factory.css b/src/factory.css
index 8c55470..7a0087d 100644
--- a/src/factory.css
+++ b/src/factory.css
@@ -453,8 +453,11 @@ body { font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
.panel section.upgrade { border-top: 3px solid #b39a61; }
.panel section.upgrade .needed { margin: 0 0 6px; font-size: 11.5px; color: #8a938c; }
.panel section.upgrade .needed.now { color: #8a6418; font-weight: 700; }
-.panel section.upgrade .chips { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 2px 0 6px; }
-.panel section.upgrade .cap { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: #9aa29b; margin-right: 4px; }
+.panel section.upgrade > .cap { margin: 10px 0 4px; font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: #9aa29b; }
+/* What carriers bring: the goods on a line of their own, under what they are. */
+.panel section.upgrade .line .chips { grid-column: 2 / -1; justify-self: start; justify-content: flex-start; max-width: none; }
+.panel section.upgrade .begin { margin-top: 12px; padding-top: 10px; border-top: 1px solid #e3e6df; }
+.panel section.upgrade .begin .sub { margin: 6px 0 0; }
.panel .lines .line.dim .count, .panel .lines .line.dim .what { color: #8a938c; font-weight: 400; }
.panel .lines .line .chip { background: #eef0ea; border-radius: 4px; padding: 1px 6px 1px 4px; }
/* An amount as its icon and number: a coin and 3/min, a plank and 2. */
diff --git a/src/host.ts b/src/host.ts
index fc81a6e..d603e72 100644
--- a/src/host.ts
+++ b/src/host.ts
@@ -1322,31 +1322,60 @@ export const createHost = async (
}
/** What upgrading a building would give and cost, said in full before the mayor pays for it, with the button that begins it. */
+ /** An upgrade's gain as a row: what changes, on the left; from what to what, on the right. */
+ const gainLine = (change: string): Line => {
+ const at = change.search(/[+−-]?\d/)
+ const label = at > 0 ? change.slice(0, at).trim() : change, rest = at > 0 ? change.slice(at) : undefined
+ // "+6 → +8, out to 6 cells": the change on the right, what qualifies it under it.
+ const [value, note] = rest?.includes(", ") ? [rest.slice(0, rest.indexOf(", ")), rest.slice(rest.indexOf(", ") + 2)] : [rest, undefined]
+ const glyph: IconName =
+ /^holds/.test(change) ? "build" : /^carriers/.test(change) ? "trade" : /^walker|^a walker/.test(change) ? "people"
+ : /^administration/.test(change) ? "taxes" : /^desirability/.test(change) ? "appeal" : /^workers/.test(change) ? "workers"
+ : /^firefighters/.test(change) ? "fire" : /rock/.test(change) ? "stone" : /a minute/.test(change) ? "jobs" : "goal"
+ return { icon: glyph, label, value, note, tone: "ok" }
+ }
+ /**
+ * What upgrading a building would cost and give, said in full before the mayor pays: what is paid now, what
+ * carriers bring later and the upkeep after; then what it gives. The button that begins it comes last, alone.
+ */
const upgradeBox = (offer: NonNullable<Extract<Panel, { type: "building" }>["upgrade"]>) => {
const box = section(`upgrade to ${offer.title.toLowerCase()}`, "build", offer.blurb)
box.classList.add("lines", "upgrade")
- const cost = costChips(offer.cost)
- cost.box.prepend(el("span", "cap", "cost"))
- const list = el("ul", "changes")
- for (const c of offer.changes) list.append(el("li", "", c))
+ // Why the town needs it now (the gold arrow over it), or that it can wait.
+ const needed = el("p", "needed", "")
+ const pays = el("div", "part"), gets = el("div", "part")
+ const payRows: Array<HTMLElement> = [], getRows: Array<HTMLElement> = []
+ const upkeep = offer.changes.find((c) => c.startsWith("upkeep"))
+ syncLines(gets, getRows, offer.changes.filter((c) => c !== upkeep).map(gainLine))
const begin = el("button", "frame primary", `Begin the ${offer.title.toLowerCase()}`)
begin.onclick = () => {
const now = ui.panel
if (now?.type === "building") ui.edits.push({ type: "upgrade", cell: now.cell })
}
const why = el("p", "sub", "")
- // Why the town needs it now (the gold arrow over it), or that it can wait.
- const needed = el("p", "needed", "")
live.push(() => {
const now = ui.panel
if (now?.type !== "building" || !now.upgrade) return
needed.textContent = now.upgrade.needed ? `needed now: ${now.upgrade.needed}` : "not needed yet: the gold arrow shows when it is"
needed.classList.toggle("now", now.upgrade.needed !== null)
- cost.refresh()
+ const coins = ui.stats?.coins ?? 0, stock = ui.stats?.stock
+ const materials = (Object.entries(offer.cost.materials) as Array<[GoodId, number]>).filter(([, n]) => n > 0)
+ const lacking = materials.filter(([g, n]) => (stock?.[g] ?? 0) < n).map(([g, n]) => `${n - (stock?.[g] ?? 0)} ${goods[g].title}`)
+ syncLines(pays, payRows, [
+ { icon: "coins", label: "now, to begin", value: `${offer.cost.coins} coins`, tone: coins < offer.cost.coins ? "bad" : undefined,
+ note: coins < offer.cost.coins ? `${offer.cost.coins - coins} coins short` : undefined },
+ ...(materials.length > 0
+ ? [{ icon: "trade", label: "later, carried in", goods: materials.map(([good, count]) => ({ good, count })), tone: lacking.length > 0 ? "warn" : undefined,
+ note: lacking.length > 0 ? `the store lacks ${lacking.join(", ")}: the works wait for them` : "from the store: the works go on as they come" } as Line]
+ : []),
+ ...(upkeep ? [{ icon: "upkeep", label: "upkeep after", value: upkeep.replace(/^upkeep /, "") } as Line] : [])
+ ])
begin.disabled = now.upgrade.blocked !== null || now.upgrade.short !== null
- why.textContent = now.upgrade.blocked ?? now.upgrade.short ?? "the coins are paid now; carriers bring the rest, scaffolding rises, and it goes on working"
+ why.textContent = now.upgrade.blocked ?? now.upgrade.short ?? "it goes on working while the works go on, and scaffolding rises inside its plot"
})
- box.append(needed, cost.box, list, begin, why)
+ const footer = el("div", "begin")
+ footer.append(begin, why)
+ box.append(needed, el("p", "cap", "you pay"), pays, el("p", "cap", "you get"), gets, footer)
return box
}