Skip to main content

Floors

Floor tiles are 16×16 pixel grayscale patterns that are colorized at runtime using HSL transformations. This allows a small set of patterns to produce a wide range of floor appearances.

Tile Types

The TileType enum defines all tile states:

ValueNameDescription
0WALLNot a floor — renders as a wall
1–9FLOOR_1FLOOR_9Floor patterns
255VOIDTransparent / empty

Nine floor patterns are available, stored as numbered PNGs:

webview-ui/public/assets/floors/
floor_0.png # solid gray (fallback)
floor_1.png # through floor_8.png — distinct patterns

Colorization

Floors use a Photoshop-style colorize mode to transform grayscale patterns into colored tiles:

  1. Read the perceived luminance from the grayscale pixel: 0.299×R + 0.587×G + 0.114×B
  2. Apply contrast: lightness = 0.5 + (lightness - 0.5) × (100 + c) / 100
  3. Apply brightness: lightness = lightness + b / 200
  4. Convert to HSL using the user's hue and saturation values
  5. Output the recolored pixel

Each tile in the layout stores its own FloorColor:

interface FloorColor {
h: number // Hue: 0–360
s: number // Saturation: 0–100
b: number // Brightness: -100 to +100
c: number // Contrast: -100 to +100
}

Colorized sprites are cached by key: floor-{patternIndex}-{h}-{s}-{b}-{c}.

Rendering

Floor tiles are rendered as part of renderTileGrid() before furniture and characters. Each floor tile is:

  1. Looked up by its TileType → pattern index
  2. Colorized with the tile's FloorColor
  3. Drawn at (col × TILE_SIZE, row × TILE_SIZE)

VOID tiles are skipped (transparent), and WALL tiles are handled by the wall rendering system instead.

Key Files

FilePurpose
webview-ui/src/office/floorTiles.tsFloor pattern storage, colorized sprite caching
webview-ui/src/office/colorize.tsHSL colorization engine (colorize + adjust modes)
shared/assets/pngDecoder.tsdecodeFloorPng() — PNG buffer to SpriteData
webview-ui/src/office/engine/renderer.tsrenderTileGrid() — floor and wall rendering