diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-17 02:25:55 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-17 02:25:55 +0200 |
commit | b8f7115ef39ff8e855f3452e087241f974745438 (patch) | |
tree | f910caf244338c0e23bd6cdb31254bda8feb9ce9 /test-client/tiles.ts | |
parent | b65849bce3fe8ff8d6baebf29728868d4f164827 (diff) | |
download | hurrycurry-b8f7115ef39ff8e855f3452e087241f974745438.tar hurrycurry-b8f7115ef39ff8e855f3452e087241f974745438.tar.bz2 hurrycurry-b8f7115ef39ff8e855f3452e087241f974745438.tar.zst |
prime clients and tile rendering
Diffstat (limited to 'test-client/tiles.ts')
-rw-r--r-- | test-client/tiles.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test-client/tiles.ts b/test-client/tiles.ts new file mode 100644 index 00000000..3b15385c --- /dev/null +++ b/test-client/tiles.ts @@ -0,0 +1,33 @@ + +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, 0, 1, 1) + if (stroke) c.strokeRect(c.lineWidth / 2, c.lineWidth / 2, 1 - c.lineWidth, 1 - c.lineWidth) + } +} +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.5, 0.5, radius, 0, Math.PI * 2) + if (stroke) c.stroke() + c.fill() + } +} + +const table = [base("rgb(133, 76, 38)")]; + +export const FALLBACK_TILE: Component[] = [base("#f0f")]; +export const TILES: { [key: string]: Component[] } = { + "floor": [base("#333", "#222", 0.05)], + "table": table, + "pan": [...table, circle(0.4, "#444", "#999")], +} |