summaryrefslogtreecommitdiff
path: root/test-client
diff options
context:
space:
mode:
Diffstat (limited to 'test-client')
-rw-r--r--test-client/tiles.ts165
1 files changed, 57 insertions, 108 deletions
diff --git a/test-client/tiles.ts b/test-client/tiles.ts
index d1011cc2..150bfdd2 100644
--- a/test-client/tiles.ts
+++ b/test-client/tiles.ts
@@ -84,23 +84,24 @@ function cross(size: number, stroke: string, stroke_width = 0.05): Component {
}
}
-function arrange_items(...items: ItemName[]): Component[] {
- return items.flatMap((item, index) => {
- const t = index / items.length * Math.PI * 2.
- const radius = items.length == 1 ? 0 : (0.4 / items.length)
- const off_x = Math.sin(t) * radius
- const off_y = Math.cos(t) * radius
- const scale = 1. / Math.sqrt(items.length)
- return c => {
- for (const comp of ITEMS[item]) {
- c.save()
- c.translate(off_x, off_y)
- c.scale(scale, scale)
- comp(c)
- c.restore()
- }
+function arrange_items(...items: ItemName[]): Component {
+ return c => {
+ for (let index = 0; index < items.length; index++) {
+ const item = items[index];
+
+ const t = index / items.length * Math.PI * 2.
+ const radius = items.length == 1 ? 0 : (0.4 / items.length)
+ const off_x = Math.sin(t) * radius
+ const off_y = Math.cos(t) * radius
+ const scale = 1. / Math.sqrt(items.length)
+
+ c.save()
+ c.translate(off_x, off_y)
+ c.scale(scale, scale)
+ iref(item)(c)
+ c.restore()
}
- })
+ }
}
const door: Component = c => {
@@ -108,96 +109,44 @@ const door: Component = c => {
c.fillRect(-0.5, -0.1, 1, 0.2)
}
-const iref = (name: keyof typeof ITEMS): Component => c => ITEMS[name].forEach(f => f(c))
-const tref = (name: keyof typeof TILES): Component => c => TILES[name].forEach(f => f(c))
+const iref = (name: ItemName, ...content: string[]): Component => ITEMS[name] ? ITEMS[name](content) : () => { }
+const tref = (name: TileName): Component => c => TILES[name].forEach(f => f(c))
-type HelperItemName = "steak" | "milk" | "cooked-rice" | "curry" | "strawberry-icecream" | "strawberry-shake"
-export type ItemName = HelperItemName | "dirty-plate" | "plate" | "tomato" | "raw-steak" | "flour" | "leek" | "rice" | "fish" | "coconut" | "strawberry" | "foodprocessor" | "flour-foodprocessor" | "dough-foodprocessor" | "dough" | "bread" | "burned" | "bread-slice" | "pot" | "raw-steak-pot" | "steak-pot" | "burned-pot" | "sliced-tomato" | "steak-plate" | "sliced-tomato-plate" | "bread-slice-plate" | "bread-slice-steak-plate" | "bread-slice-sliced-tomato-plate" | "bread-slice-sliced-tomato-steak-plate" | "sliced-tomato-steak-plate" | "tomato-foodprocessor" | "tomato-juice-foodprocessor" | "leek-pot" | "tomato-juice-pot" | "leek-tomato-juice-pot" | "tomato-soup-pot" | "tomato-soup-plate" | "sliced-fish" | "rice-pot" | "cooked-rice-pot" | "nigiri" | "nigiri-plate" | "strawberry-foodprocessor" | "strawberry-puree-foodprocessor" | "coconut-foodprocessor" | "milk-foodprocessor" | "coconut-strawberry-puree-foodprocessor" | "strawberry-shake-foodprocessor" | "milk-strawberry-foodprocessor" | "strawberry-icecream-foodprocessor" | "strawberry-icecream-plate" | "rice-foodprocessor" | "rice-flour-foodprocessor" | "rice-flour-pot" | "mochi-dough-pot" | "strawberry-mochi" | "glass" | "strawberry-shake-glass" | "tomato-juice-glass" | "water-glass" | "milk-pot" | "tomato-pot" | "leek-milk-pot" | "leek-tomato-pot" | "leek-milk-tomato-pot" | "milk-tomato-pot" | "curry-pot" | "cooked-rice-plate" | "curry-plate" | "cooked-rice-curry-plate"
+export type ItemName = string
export type TileName = "sink" | "conveyor" | "book" | "tomato-crate" | "steak-crate" | "flour-crate" | "leek-crate" | "rice-crate" | "fish-crate" | "coconut-crate" | "strawberry-crate" | "oven" | "cuttingboard" | "stove" | "freezer" | "trash" | "grass" | "tree" | "wall" | "chair" | "floor" | "door" | "counter" | "wall-window" | "table" | "counter-window" | "path" | "lamp" | "street"
-const pot = iref("pot")
-const plate = iref("plate")
-const foodprocessor = iref("foodprocessor")
-const glass = iref("glass")
-const ITEMS: { [key in ItemName]: Component[] } = {
- "tomato": [circle(0.3, "#d63838")],
- "raw-steak": [circle(0.3, "#ca3510")],
- "flour": [circle(0.3, "#d8c9c2")],
- "leek": [circle(0.3, "rgb(50, 133, 17)")],
- "rice": [circle(0.3, "rgb(163, 163, 163)")],
- "fish": [circle(0.3, "rgb(62, 66, 104)")],
- "coconut": [circle(0.3, "rgb(75, 49, 25)")],
- "strawberry": [circle(0.3, "rgb(228, 79, 111)")],
-
- "pot": [circle(0.35, "rgb(29, 29, 29)", "rgb(39, 39, 39)", 0.04)],
- "foodprocessor": [circle(0.35, "rgb(86, 168, 189)", "rgb(88, 222, 255)", 0.04)],
- "plate": [circle(0.4, "#b6b6b6", "#f7f7f7", 0.02)],
- "glass": [circle(0.35, "rgb(150, 255, 237)", "rgb(52, 129, 155)", 0.02)],
+const ITEMS: { [key in ItemName]: (c: string[]) => Component } = {
+ "bun": () => circle(0.3, "#853e20"),
+ "burned": () => c => (circle(0.3, "rgb(61, 18, 0)")(c), cross(0.2, "red", 0.02)(c)),
+ "coconut": () => circle(0.3, "rgb(75, 49, 25)"),
+ "cooked-rice": () => circle(0.3, "rgb(233, 233, 233)"),
+ "curry": () => circle(0.3, "rgb(185, 67, 37)"),
+ "dough": () => circle(0.3, "#b38d7d"),
+ "fish": () => circle(0.3, "rgb(62, 66, 104)"),
+ "flour": () => circle(0.3, "#d8c9c2"),
+ "leek": () => circle(0.3, "rgb(50, 133, 17)"),
+ "milk": () => circle(0.3, "rgb(252, 243, 208)"),
+ "nigiri": () => circle(0.25, "rgb(233, 233, 233)", "salmon"),
+ "rice": () => circle(0.3, "rgb(163, 163, 163)"),
+ "seared-steak": () => circle(0.3, "#702200"),
+ "sliced-bun": () => circle(0.3, "#853e20"),
+ "sliced-fish": () => circle(0.3, "salmon", "rgb(62, 66, 104)"),
+ "steak": () => circle(0.3, "#ca3510"),
+ "strawberry-icecream": () => circle(0.2, "rgb(250, 148, 236)"),
+ "strawberry-mochi": () => circle(0.2, "rgb(161, 111, 132)"),
+ "strawberry-shake": () => circle(0.3, "rgb(255, 180, 180)"),
+ "strawberry": () => circle(0.3, "rgb(228, 79, 111)"),
+ "tomato-juice": () => circle(0.3, "#b80000"),
+ "tomato-soup": () => circle(0.3, "#ff2600"),
+ "tomato": () => circle(0.3, "#d63838"),
+ "water": () => circle(0.3, "rgb(86, 92, 206)"),
+ "sliced-tomato": () => circle(0.3, "#d16363", "#d63838", 0.08),
- "steak": [circle(0.3, "#702200")],
- "dough": [circle(0.3, "#b38d7d")],
- "bread": [circle(0.3, "#853e20")],
- "milk": [circle(0.3, "rgb(252, 243, 208)")],
- "curry": [circle(0.3, "rgb(185, 67, 37)")],
- "cooked-rice": [circle(0.3, "rgb(233, 233, 233)")],
- "bread-slice": [circle(0.3, "#853e20")],
- "sliced-fish": [circle(0.3, "salmon", "rgb(62, 66, 104)")],
- "nigiri": [circle(0.25, "rgb(233, 233, 233)", "salmon")],
- "burned": [circle(0.3, "rgb(61, 18, 0)"), cross(0.2, "red", 0.02)],
- "strawberry-icecream": [circle(0.2, "rgb(250, 148, 236)")],
- "strawberry-shake": [circle(0.3, "rgb(255, 180, 180)")],
+ "pot": i => c => (circle(0.35, "rgb(29, 29, 29)", "rgb(39, 39, 39)", 0.04)(c), arrange_items(...i)(c)),
+ "foodprocessor": i => c => (circle(0.35, "rgb(86, 168, 189)", "rgb(88, 222, 255)", 0.04)(c), arrange_items(...i)(c)),
+ "plate": i => c => (circle(0.4, "#b6b6b6", "#f7f7f7", 0.02)(c), arrange_items(...i)(c)),
+ "glass": () => circle(0.35, "rgb(150, 255, 237)", "rgb(52, 129, 155)", 0.02),
- "bread-slice-plate": [plate, ...arrange_items("bread-slice")],
- "bread-slice-sliced-tomato-plate": [plate, ...arrange_items("bread-slice", "sliced-tomato")],
- "bread-slice-sliced-tomato-steak-plate": [plate, ...arrange_items("bread-slice", "sliced-tomato", "steak")],
- "bread-slice-steak-plate": [plate, ...arrange_items("bread-slice", "steak")],
- "burned-pot": [pot, iref("burned")],
- "coconut-foodprocessor": [foodprocessor, iref("coconut")],
- "coconut-strawberry-puree-foodprocessor": [foodprocessor, iref("coconut"), iref("strawberry")],
- "cooked-rice-curry-plate": [plate, ...arrange_items("curry", "cooked-rice")],
- "cooked-rice-plate": [plate, iref("cooked-rice")],
- "cooked-rice-pot": [pot, iref("rice")],
- "curry-plate": [plate, iref("curry")],
- "curry-pot": [pot, iref("curry")],
- "dirty-plate": [circle(0.4, "#947a6f", "#d3a187", 0.02)],
- "dough-foodprocessor": [foodprocessor, circle(0.3, "#b38d7d")],
- "flour-foodprocessor": [foodprocessor, circle(0.3, "#d8c9c2")],
- "leek-milk-pot": [pot, ...arrange_items("leek", "milk")],
- "leek-milk-tomato-pot": [pot, ...arrange_items("leek", "milk", "tomato")],
- "leek-pot": [pot, iref("leek")],
- "leek-tomato-juice-pot": [pot, circle(0.3, "#dd5800")],
- "leek-tomato-pot": [pot, ...arrange_items("leek", "tomato")],
- "milk-foodprocessor": [foodprocessor, iref("milk")],
- "milk-pot": [pot, iref("milk")],
- "milk-strawberry-foodprocessor": [foodprocessor, iref("strawberry"), circle(0.2, "rgb(252, 243, 208)")],
- "milk-tomato-pot": [pot, ...arrange_items("milk", "tomato")],
- "mochi-dough-pot": [pot, circle(0.3, "rgb(172, 162, 151)")],
- "nigiri-plate": [plate, iref("nigiri")],
- "raw-steak-pot": [pot, iref("raw-steak")],
- "rice-flour-foodprocessor": [foodprocessor, iref("rice")],
- "rice-flour-pot": [pot, iref("rice")],
- "rice-foodprocessor": [foodprocessor, iref("rice")],
- "rice-pot": [pot, iref("rice")],
- "sliced-tomato-plate": [plate, ...arrange_items("sliced-tomato")],
- "sliced-tomato-steak-plate": [plate, ...arrange_items("sliced-tomato", "steak")],
- "sliced-tomato": [circle(0.3, "#d16363", "#d63838", 0.08)],
- "steak-plate": [plate, ...arrange_items("steak")],
- "steak-pot": [pot, iref("steak")],
- "strawberry-foodprocessor": [foodprocessor, iref("strawberry")],
- "strawberry-icecream-foodprocessor": [foodprocessor, iref("strawberry-icecream")],
- "strawberry-icecream-plate": [plate, iref("strawberry-icecream")],
- "strawberry-mochi": [pot, circle(0.2, "rgb(161, 111, 132)")],
- "strawberry-puree-foodprocessor": [foodprocessor, iref("strawberry")],
- "strawberry-shake-foodprocessor": [foodprocessor, iref("strawberry-shake")],
- "strawberry-shake-glass": [glass, iref("strawberry-shake")],
- "tomato-foodprocessor": [foodprocessor, circle(0.3, "#d63838")],
- "tomato-juice-foodprocessor": [foodprocessor, circle(0.3, "#b80000")],
- "tomato-juice-glass": [glass, circle(0.3, "#b80000")],
- "tomato-juice-pot": [pot, circle(0.3, "#b80000")],
- "tomato-pot": [pot, iref("tomato")],
- "tomato-soup-plate": [plate, circle(0.3, "#ff2600")],
- "tomato-soup-pot": [pot, circle(0.3, "#ff2600")],
- "water-glass": [glass, circle(0.3, "rgb(86, 92, 206)")],
}
const crate = (i: ItemName) => [base("#60701e", "#b9da37", 0.05), iref(i)];
@@ -227,7 +176,7 @@ const TILES: { [key in TileName]: Component[] } = {
"lamp": [tref("grass"), rect(0.3, "rgb(255, 217, 127)", "rgb(32, 32, 32)", 0.1)],
"flour-crate": crate("flour"),
- "steak-crate": crate("raw-steak"),
+ "steak-crate": crate("steak"),
"tomato-crate": crate("tomato"),
"leek-crate": crate("leek"),
"rice-crate": crate("rice"),
@@ -250,12 +199,12 @@ function debug_label(ctx: CanvasRenderingContext2D, name: string) {
ctx.restore()
}
+// TODO performance
export function draw_item_sprite(ctx: CanvasRenderingContext2D, name: ItemName) {
- const comps = ITEMS[name]
- if (comps) {
- for (const c of comps) {
- c(ctx)
- }
+ const [base, cont] = name.split(":")
+ const c = ITEMS[base]
+ if (c) {
+ c(cont?.split(",") ?? [])(ctx)
} else {
circle(0.4, "#f0f")(ctx)
debug_label(ctx, name)
@@ -272,4 +221,4 @@ export function draw_tile_sprite(ctx: CanvasRenderingContext2D, name: TileName)
debug_label(ctx, name)
}
-} \ No newline at end of file
+}