| 123456789101112131415161718192021222324 |
- import { readFileSync } from 'node:fs';
- import { resolve } from 'node:path';
- import { parseMaterials, type MaterialRegistry } from '../src/shared/materials';
- import { TerrainBitmap } from '../src/shared/terrain/bitmap';
- export const ASSETS = resolve(import.meta.dirname, '../assets');
- export function realMaterials(): MaterialRegistry {
- return parseMaterials(JSON.parse(readFileSync(resolve(ASSETS, 'materials/materials.json'), 'utf8')));
- }
- /** Builds a bitmap from ASCII art: '.' = empty, digits = material id, '#' = plate (255). */
- export function bitmapFrom(rows: string[]): TerrainBitmap {
- const h = rows.length;
- const w = rows[0].length;
- const bm = new TerrainBitmap(w, h);
- rows.forEach((row, y) => {
- for (let x = 0; x < w; x++) {
- const c = row[x];
- bm.data[y * w + x] = c === '.' ? 0 : c === '#' ? 255 : Number(c);
- }
- });
- return bm;
- }
|