aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2026-01-28 12:10:10 +0100
committertpart <tpart120@proton.me>2026-02-26 20:49:14 +0100
commit59deabd281199c8e77839ebc3194efa61fe1ad30 (patch)
tree5e263330f5930c858f1103cdb8f16651e5c0a9f3
parent4d380b8faad6f9a9253e7adbc22ea4dfa4cabc5f (diff)
downloadhurrycurry-59deabd281199c8e77839ebc3194efa61fe1ad30.tar
hurrycurry-59deabd281199c8e77839ebc3194efa61fe1ad30.tar.bz2
hurrycurry-59deabd281199c8e77839ebc3194efa61fe1ad30.tar.zst
test-client: split params when drawing tiles
-rw-r--r--test-client/tiles.ts70
1 files changed, 28 insertions, 42 deletions
diff --git a/test-client/tiles.ts b/test-client/tiles.ts
index 0f5d34bb..150d654f 100644
--- a/test-client/tiles.ts
+++ b/test-client/tiles.ts
@@ -124,10 +124,10 @@ const door: Component = c => {
}
const iref = (name: ItemName): Component => c => draw_item_sprite(c, name)
-const tref = (name: TileName): Component => c => TILES[name].forEach(f => f(c))
+const tref = (name: ItemName): Component => c => draw_tile_sprite(c, name)
export type ItemName = string
-export type TileName = "sink" | "conveyor" | "book" | "lettuce-crate" | "cheese-crate" | "tomato-crate" | "steak-crate" | "flour-crate" | "leek-crate" | "rice-crate" | "fish-crate" | "coconut-crate" | "strawberry-crate" | "oven" | "cutting-board" | "stove" | "freezer" | "trash" | "grass" | "tree" | "wall" | "chair" | "floor" | "door" | "counter" | "wall-window" | "table" | "counter-window" | "path" | "lamp" | "street"
+export type TileName = string
const ITEMS: { [key in ItemName]: (c: string[]) => Component } = {
"bun": () => circle(0.3, "#853e20"),
@@ -174,42 +174,30 @@ const ITEMS: { [key in ItemName]: (c: string[]) => Component } = {
}
-const crate = (i: ItemName) => [base("#60701e", "#b9da37", 0.05), iref(i)];
-const floor = tref("floor");
const counter = tref("counter");
-const TILES: { [key in TileName]: Component[] } = {
- "floor": [base("#333", "#222", 0.05)],
- "street": [base("rgb(19, 19, 19)")],
- "table": [base("rgb(133, 76, 38)")],
- "door": [floor, door],
- "chair": [floor, circle(0.45, "rgb(136, 83, 41)")],
- "wall": [base("rgb(0, 14, 56)")],
- "wall-window": [base("rgb(19, 40, 102)")],
- "counter": [base("rgb(182, 172, 164)")],
- "counter-window": [base("rgb(233, 233, 233)")],
- "grass": [base("rgb(0, 107, 4)")],
- "path": [base("rgb(100, 80, 55)")],
- "conveyor": [base("rgb(107, 62, 128)")],
- "tree": [base("rgb(1, 82, 4)")],
- "cutting-board": [counter, rect(0.3, "rgb(158, 236, 68)", "rgb(158, 236, 68)", 0.2)],
- "trash": [floor, circle(0.4, "rgb(20, 20, 20)"), cross(0.3, "rgb(90, 36, 36)")],
- "sink": [base("rgb(131, 129, 161)", "rgb(177, 174, 226)", 0.2)],
- "oven": [base("rgb(241, 97, 61)", "rgb(109, 84, 84)", 0.3)],
- "freezer": [base("rgb(61, 97, 241)", "rgb(84, 88, 109)", 0.3)],
- "stove": [counter, circle(0.4, "#444", "#999")],
- "book": [counter, rect(0.2, "rgb(88, 44, 7)")],
- "lamp": [tref("grass"), rect(0.3, "rgb(255, 217, 127)", "rgb(32, 32, 32)", 0.1)],
-
- "flour-crate": crate("flour"),
- "steak-crate": crate("steak"),
- "tomato-crate": crate("tomato"),
- "lettuce-crate": crate("lettuce"),
- "cheese-crate": crate("cheese"),
- "leek-crate": crate("leek"),
- "rice-crate": crate("rice"),
- "fish-crate": crate("fish"),
- "coconut-crate": crate("coconut"),
- "strawberry-crate": crate("strawberry"),
+const TILES: { [key in TileName]: (param: string) => Component } = {
+ "floor": () => base("#333", "#222", 0.05),
+ "street": () => base("rgb(19, 19, 19)"),
+ "table": () => base("rgb(133, 76, 38)"),
+ "door": () => door,
+ "chair": () => circle(0.45, "rgb(136, 83, 41)"),
+ "wall": () => base("rgb(0, 14, 56)"),
+ "wall-window": () => base("rgb(19, 40, 102)"),
+ "counter": () => base("rgb(182, 172, 164)"),
+ "counter-window": () => base("rgb(233, 233, 233)"),
+ "grass": () => base("rgb(0, 107, 4)"),
+ "path": () => base("rgb(100, 80, 55)"),
+ "conveyor": () => base("rgb(107, 62, 128)"),
+ "tree": () => base("rgb(1, 82, 4)"),
+ "cutting-board": () => rect(0.3, "rgb(158, 236, 68)", "rgb(158, 236, 68)", 0.2),
+ "trash": () => c => (circle(0.4, "rgb(20, 20, 20)")(c), cross(0.3, "rgb(90, 36, 36)")(c)),
+ "sink": () => base("rgb(131, 129, 161)", "rgb(177, 174, 226)", 0.2),
+ "oven": () => base("rgb(241, 97, 61)", "rgb(109, 84, 84)", 0.3),
+ "freezer": () => base("rgb(61, 97, 241)", "rgb(84, 88, 109)", 0.3),
+ "stove": () => c => (counter(c), circle(0.4, "#444", "#999")(c)),
+ "book": () => c => (counter(c), rect(0.2, "rgb(88, 44, 7)")(c)),
+ "lamp": () => c => rect(0.3, "rgb(255, 217, 127)", "rgb(32, 32, 32)", 0.1),
+ "crate": name => c => (base("#60701e", "#b9da37", 0.05)(c), iref(name)(c))
}
function debug_label(ctx: CanvasRenderingContext2D, name: string) {
@@ -238,11 +226,9 @@ export function draw_item_sprite(ctx: CanvasRenderingContext2D, name: ItemName)
}
}
export function draw_tile_sprite(ctx: CanvasRenderingContext2D, name: TileName) {
- const comps = TILES[name]
- if (comps) {
- for (const c of comps) {
- c(ctx)
- }
+ const [kind, param] = name.split(":", 2)
+ if (TILES[kind]) {
+ TILES[kind](param)(ctx)
} else {
base("#f0f")(ctx)
debug_label(ctx, name)