diff options
Diffstat (limited to 'test-client/tiles.ts')
| -rw-r--r-- | test-client/tiles.ts | 44 | 
1 files changed, 40 insertions, 4 deletions
| diff --git a/test-client/tiles.ts b/test-client/tiles.ts index 046d8297..fee27c9f 100644 --- a/test-client/tiles.ts +++ b/test-client/tiles.ts @@ -114,8 +114,7 @@ const foodprocessor = [circle(0.35, "rgb(86, 168, 189)", "rgb(88, 222, 255)", 0.  const burned = [circle(0.3, "rgb(61, 18, 0)"), cross(0.2, "red", 0.02)]  const leek = [circle(0.3, "rgb(50, 133, 17)")] -export const FALLBACK_ITEM: Component[] = [circle(0.3, "#f0f")]; -export const ITEMS: { [key: string]: Component[] } = { +const ITEMS: { [key: string]: Component[] } = {      "pot": pot,      "foodprocessor": foodprocessor,      "leek": leek, @@ -158,8 +157,7 @@ const floor = [base("#333", "#222", 0.05)];  const counter = [base("rgb(182, 172, 164)")];  const crate = (i: string) => [base("#60701e", "#b9da37", 0.05), ...ITEMS[i]]; -export const FALLBACK_TILE: Component[] = [base("#f0f")]; -export const TILES: { [key: string]: Component[] } = { +const TILES: { [key: string]: Component[] } = {      "floor": floor,      "table": table,      "door": [...floor, door], @@ -184,3 +182,41 @@ export const TILES: { [key: string]: Component[] } = {      "tomato-crate": crate("tomato"),      "leek-crate": crate("leek"),  } + +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: string) { +    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: string) { +    const comps = TILES[name] +    if (comps) { +        for (const c of comps) { +            c(ctx) +        } +    } else { +        base("#f0f")(ctx) +        debug_label(ctx, name) +    } + +}
\ No newline at end of file | 
