/* Hurry Curry! - a game about cooking Copyright 2024 metamuffin This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, version 3 of the License only. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ type Component = (ctx: CanvasRenderingContext2D) => void function base(fill: string, stroke?: string, stroke_width?: number): Component { return c => { c.fillStyle = fill; c.strokeStyle = stroke ?? "black"; c.lineWidth = stroke_width ?? 0.05 c.lineJoin = "miter" c.lineCap = "square" c.fillRect( -0.5, -0.5, 1, 1 ) if (stroke) c.strokeRect( -0.5 + c.lineWidth / 2, -0.5 + c.lineWidth / 2, 1 - c.lineWidth, 1 - c.lineWidth ) } } function rect(inset: number, fill: string, stroke?: string, stroke_width?: number): Component { return c => { c.fillStyle = fill; c.strokeStyle = stroke ?? "black"; c.lineWidth = stroke_width ?? 0.05 c.lineJoin = "round" c.lineCap = "round" c.fillRect( -0.5 + inset, -0.5 + inset, 1 - inset * 2, 1 - inset * 2 ) if (stroke) c.strokeRect( -0.5 + inset, -0.5 + inset, 1 - inset * 2, 1 - inset * 2 ) } } function circle(radius: number, fill: string, stroke?: string, stroke_width?: number): Component { return c => { c.fillStyle = fill; c.strokeStyle = stroke ?? "black"; c.lineWidth = stroke_width ?? 0.05 c.beginPath() c.arc(0.0, 0.0, radius, 0, Math.PI * 2) if (stroke) c.stroke() c.fill() } } function cross(size: number, stroke: string, stroke_width = 0.05): Component { return c => { c.strokeStyle = stroke c.lineWidth = stroke_width c.lineCap = "round" c.beginPath() c.moveTo(-size, -size) c.lineTo(size, size) c.moveTo(size, -size) c.lineTo(-size, size) c.stroke() } } 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() } } }) } const door: Component = c => { c.fillStyle = "#ff9843" 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)) 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 TileName = "sink" | "conveyor" | "book" | "tomato-crate" | "raw-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)], "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)")], "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)]; 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)")], "cuttingboard": [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"), "raw-steak-crate": crate("raw-steak"), "tomato-crate": crate("tomato"), "leek-crate": crate("leek"), "rice-crate": crate("rice"), "fish-crate": crate("fish"), "coconut-crate": crate("coconut"), "strawberry-crate": crate("strawberry"), } function debug_label(ctx: CanvasRenderingContext2D, name: string) { ctx.save() ctx.font = "10px sans-serif" ctx.fillStyle = "white" ctx.strokeStyle = "black" ctx.lineWidth = 1 ctx.textAlign = "center" ctx.textBaseline = "middle" ctx.scale(0.03, 0.03) ctx.strokeText(name, 0, 0) ctx.fillText(name, 0, 0) ctx.restore() } export function draw_item_sprite(ctx: CanvasRenderingContext2D, name: ItemName) { const comps = ITEMS[name] if (comps) { for (const c of comps) { c(ctx) } } else { circle(0.4, "#f0f")(ctx) debug_label(ctx, name) } } export function draw_tile_sprite(ctx: CanvasRenderingContext2D, name: TileName) { const comps = TILES[name] if (comps) { for (const c of comps) { c(ctx) } } else { base("#f0f")(ctx) debug_label(ctx, name) } }