diff options
Diffstat (limited to 'test-client')
-rw-r--r-- | test-client/main.ts | 7 | ||||
-rw-r--r-- | test-client/tiles.ts | 44 | ||||
-rw-r--r-- | test-client/util.ts | 2 |
3 files changed, 42 insertions, 11 deletions
diff --git a/test-client/main.ts b/test-client/main.ts index ef84689f..1b034f28 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -49,7 +49,7 @@ let scale = 0 function send(p: PacketS) { ws.send(JSON.stringify(p)) } function packet(p: PacketC) { - if (!("position" in p)) console.log(p); + if (!("position" in p) && !("set_active" in p)) console.log(p); if ("joined" in p) { my_id = p.joined.id data = p.joined.data @@ -90,9 +90,12 @@ const keys_down = new Set(); const HANDLED_KEYS = ["KeyW", "KeyA", "KeyS", "KeyD", "Space"] function keyboard(ev: KeyboardEvent, down: boolean) { if (HANDLED_KEYS.includes(ev.code)) ev.preventDefault() - if (ev.code == "Space") interact(down) + let change; + if (down) change = !keys_down.has(ev.code) + else change = keys_down.has(ev.code) if (down) keys_down.add(ev.code) else keys_down.delete(ev.code) + if (change && ev.code == "Space") interact(down) } function get_interact_target(): V2 | undefined { diff --git a/test-client/tiles.ts b/test-client/tiles.ts index c628ea5d..883ab7cb 100644 --- a/test-client/tiles.ts +++ b/test-client/tiles.ts @@ -7,7 +7,7 @@ function base(fill: string, stroke?: string, stroke_width?: number): Component { c.lineWidth = stroke_width ?? 0.05 c.lineJoin = "miter" c.lineCap = "square" - c.fillRect(-0.5, -0.5, 1,1) + 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) } } @@ -22,20 +22,48 @@ function circle(radius: number, fill: string, stroke?: string, stroke_width?: nu 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() + } +} + +const plate = [circle(0.4, "#b6b6b6", "#f7f7f7", 0.02)]; + +export const FALLBACK_ITEM: Component[] = [circle(0.3, "#f0f")]; +export const ITEMS: { [key: string]: Component[] } = { + "raw-steak": [circle(0.3, "#cc3705")], + "steak": [circle(0.3, "#702200")], + "flour": [circle(0.3, "#d8c9c2")], + "dough": [circle(0.3, "#b38d7d")], + "tomato": [circle(0.3, "#d63838")], + "dirty-plate": [circle(0.4, "#947a6f", "#d3a187", 0.02)], + "plate": plate, + "steak-meal": [...plate, circle(0.3, "#702200")], +} const table = [base("rgb(133, 76, 38)")]; const floor = [base("#333", "#222", 0.05)]; +const spawn = (i: string) => [base("#60701e", "#b9da37", 0.05), ...ITEMS[i]]; export const FALLBACK_TILE: Component[] = [base("#f0f")]; export const TILES: { [key: string]: Component[] } = { "floor": floor, "table": table, + "counter": [base("rgb(182, 172, 164)")], + "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)], "pan": [...table, circle(0.4, "#444", "#999")], - "flour_bag": [...floor, circle(0.5, "#fff", "#ddd")], -} - -export const FALLBACK_ITEM: Component[] = [circle(0.3, "#f0f")]; -export const ITEMS: { [key: string]: Component[] } = { - "raw-steak": [circle(0.3, "rgb(204, 55, 5)")], - "steak": [circle(0.3, "rgb(112, 34, 0)")], + "flour-spawn": spawn("flour"), + "dirty-plate-spawn": spawn("dirty-plate"), + "raw-steak-spawn": spawn("raw-steak"), + "tomato-spawn": spawn("tomato"), } diff --git a/test-client/util.ts b/test-client/util.ts index 6febac37..baebc61e 100644 --- a/test-client/util.ts +++ b/test-client/util.ts @@ -20,4 +20,4 @@ export function ceil_v2(p: V2): V2 { return { x: Math.ceil(p.x), y: Math.ceil(p. export function add_v2(p: V2, o: V2 | number) { if (typeof o == "number") return { x: p.x + o, y: p.y + o } else return { x: p.x + o.x, y: p.y + o.y } -}
\ No newline at end of file +} |