Skip to content
1        10        20        30        40        50        60        70        801// Map tiles are drawn in code into one canvas, so the client ships no images.2// Each glyph in the server's map maps to a tile name here.34export const TILE = 16;56export const BASE = {7  '#': 'wall',8  w: 'window',9  k: 'kitchen',10  R: 'rug',11};12export const DEFAULT_BASE = 'wood';1314export const OVERLAY = {15  C: 'counter', I: 'counter', Z: 'sink', S: 'stove', O: 'oven', F: 'fridge',16  G: 'greens', L: 'loaf', B: 'board', N: 'bowl', T: 'table', c: 'chair',17  K: 'cabinet', p: 'plant', V: 'couch', Q: 'coffee',18};1920const r = (ctx, x, y, w, h, color) => {21  ctx.fillStyle = color;22  ctx.fillRect(x, y, w, h);23};2425const counterBase = (ctx) => {26  r(ctx, 0, 0, 16, 16, '#6b4220');27  r(ctx, 0, 0, 16, 4, '#d9a86c');28  r(ctx, 0, 4, 16, 1, '#b8864a');29  r(ctx, 1, 6, 14, 9, '#8b5a2b');30  r(ctx, 7, 6, 2, 9, '#6b4220');31};3233const DRAW = {34  wall(ctx) {35    r(ctx, 0, 0, 16, 16, '#e9d8b4');36    r(ctx, 0, 0, 16, 3, '#c9a677');37    r(ctx, 0, 8, 16, 1, '#d9c39c');38    r(ctx, 0, 15, 16, 1, '#d5bd93');39  },40  window(ctx) {41    DRAW.wall(ctx);42    r(ctx, 2, 3, 12, 9, '#8fd3f4');43    r(ctx, 3, 4, 3, 2, '#c9f0ff');44    r(ctx, 2, 3, 12, 1, '#5b3a1e');45    r(ctx, 2, 11, 12, 1, '#5b3a1e');46    r(ctx, 2, 3, 1, 9, '#5b3a1e');47    r(ctx, 13, 3, 1, 9, '#5b3a1e');48    r(ctx, 7, 3, 2, 9, '#5b3a1e');49  },50  wood(ctx) {51    r(ctx, 0, 0, 16, 16, '#b7834f');52    for (const y of [3, 7, 11, 15]) r(ctx, 0, y, 16, 1, '#9a6a3c');53    r(ctx, 5, 0, 1, 3, '#9a6a3c');54    r(ctx, 12, 4, 1, 3, '#9a6a3c');55    r(ctx, 3, 8, 1, 3, '#9a6a3c');56    r(ctx, 9, 12, 1, 3, '#9a6a3c');57  },58  kitchen(ctx) {59    r(ctx, 0, 0, 16, 16, '#efeadf');60    r(ctx, 0, 0, 8, 8, '#cfc7b5');61    r(ctx, 8, 8, 8, 8, '#cfc7b5');62  },63  rug(ctx) {64    r(ctx, 0, 0, 16, 16, '#7d4a3a');65    r(ctx, 1, 1, 14, 14, '#8f5a48');66    r(ctx, 3, 3, 10, 10, '#7d4a3a');67    r(ctx, 7, 3, 2, 10, '#c9a25a');68    r(ctx, 3, 7, 10, 2, '#c9a25a');69  },70  counter: counterBase,71  sink(ctx) {72    counterBase(ctx);73    r(ctx, 4, 6, 8, 6, '#9aa5b1');74    r(ctx, 5, 7, 6, 4, '#6c7a89');75    r(ctx, 7, 1, 2, 3, '#c0c8d0');76  },77  stove(ctx) {78    counterBase(ctx);79    r(ctx, 2, 6, 12, 9, '#2d2d2d');80    r(ctx, 4, 8, 3, 3, '#777');81    r(ctx, 9, 8, 3, 3, '#777');82    r(ctx, 4, 12, 3, 2, '#777');83    r(ctx, 9, 12, 3, 2, '#777');84  },85  oven(ctx) {86    counterBase(ctx);87    r(ctx, 1, 5, 14, 10, '#c8c8c8');88    r(ctx, 3, 7, 10, 6, '#333');89    r(ctx, 4, 8, 8, 4, '#8a4b22');90    r(ctx, 6, 6, 4, 1, '#222');91  },92  fridge(ctx) {93    r(ctx, 0, 0, 16, 16, '#f4f6f8');94    r(ctx, 0, 0, 16, 1, '#c9d1d8');95    r(ctx, 0, 15, 16, 1, '#c9d1d8');96    r(ctx, 0, 7, 16, 1, '#aab4bd');97    r(ctx, 12, 3, 1, 3, '#8a96a0');98    r(ctx, 12, 9, 1, 4, '#8a96a0');99  },100  board(ctx) {101    counterBase(ctx);102    r(ctx, 3, 5, 10, 7, '#c8985a');103    r(ctx, 3, 5, 10, 1, '#e2b57c');104    r(ctx, 5, 8, 6, 1, '#a8733f');105  },106  bowl(ctx) {107    counterBase(ctx);108    r(ctx, 3, 6, 10, 6, '#f2ede0');109    r(ctx, 4, 11, 8, 1, '#cfc7b5');110    r(ctx, 5, 7, 2, 2, '#5f9b4a');111    r(ctx, 9, 7, 2, 2, '#e07b39');112  },113  greens(ctx) {114    r(ctx, 0, 0, 16, 16, '#7a5230');115    r(ctx, 1, 1, 14, 14, '#8f623b');116    r(ctx, 2, 5, 12, 1, '#5c3a22');117    r(ctx, 3, 2, 4, 4, '#3f9a4a');118    r(ctx, 8, 3, 5, 4, '#56b35f');119    r(ctx, 4, 9, 4, 4, '#2f7d3a');120    r(ctx, 9, 9, 4, 4, '#3f9a4a');121  },122  loaf(ctx) {123    r(ctx, 0, 0, 16, 16, '#7a5230');124    r(ctx, 1, 1, 14, 14, '#8f623b');125    r(ctx, 2, 5, 12, 1, '#5c3a22');126    r(ctx, 2, 9, 12, 1, '#5c3a22');127    r(ctx, 3, 2, 10, 3, '#d9a25b');128    r(ctx, 3, 6, 10, 3, '#c98c46');129    r(ctx, 3, 10, 10, 3, '#d9a25b');130  },131  table(ctx) {132    r(ctx, 0, 0, 16, 16, '#7a4a22');133    r(ctx, 1, 1, 14, 14, '#9a6236');134    r(ctx, 0, 0, 16, 1, '#5c3517');135    r(ctx, 0, 15, 16, 1, '#5c3517');136  },137  chair(ctx) {138    r(ctx, 3, 2, 10, 3, '#6e4020');139    r(ctx, 2, 5, 12, 8, '#b07a45');140    r(ctx, 2, 5, 12, 1, '#8f5d30');141    r(ctx, 3, 13, 2, 3, '#5a3517');142    r(ctx, 11, 13, 2, 3, '#5a3517');143  },144  cabinet(ctx) {145    r(ctx, 0, 0, 16, 16, '#8a5a30');146    r(ctx, 0, 0, 16, 1, '#5c3517');147    r(ctx, 7, 1, 1, 14, '#5a3517');148    r(ctx, 5, 7, 1, 2, '#f0d070');149    r(ctx, 10, 7, 1, 2, '#f0d070');150  },151  plant(ctx) {152    r(ctx, 4, 10, 8, 1, '#c9663b');153    r(ctx, 5, 11, 6, 5, '#b5562f');154    r(ctx, 4, 2, 8, 8, '#3f9a4a');155    r(ctx, 6, 0, 4, 3, '#56b35f');156    r(ctx, 2, 5, 3, 4, '#2f7d3a');157    r(ctx, 11, 5, 3, 4, '#2f7d3a');158  },159  couch(ctx) {160    r(ctx, 0, 1, 16, 15, '#2e6f8e');161    r(ctx, 0, 1, 16, 1, '#1f4d63');162    r(ctx, 1, 2, 14, 4, '#3a86ad');163    r(ctx, 1, 8, 14, 6, '#3a86ad');164    r(ctx, 0, 13, 16, 3, '#24566f');165  },166  coffee(ctx) {167    r(ctx, 1, 3, 14, 11, '#6b4424');168    r(ctx, 1, 3, 14, 1, '#8b5a33');169    r(ctx, 2, 12, 2, 2, '#4a2e18');170    r(ctx, 12, 12, 2, 2, '#4a2e18');171    r(ctx, 5, 6, 6, 4, '#e8dcc0');172  },173};174175export const TILE_NAMES = Object.keys(DRAW);176177// Returns a canvas with every tile laid out in a row, plus the tile names in order.178export function buildTileCanvas() {179  const canvas = document.createElement('canvas');180  canvas.width = TILE * TILE_NAMES.length;181  canvas.height = TILE;182  const ctx = canvas.getContext('2d');183  TILE_NAMES.forEach((name, i) => {184    ctx.save();185    ctx.translate(i * TILE, 0);186    DRAW[name](ctx);187    ctx.restore();188  });189  return canvas;190}