Something went wrong. Try again.
A Social Deduction / Deception Game
Something went wrong. Try again.
3.0 kB · 66 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667// Headless smoke test for map import: resolve a `world.tilemap.map` AT-URI into a// render-ready MapExport and assert it is structurally valid + the atlas is// reachable. Proves the record → MapExport path without needing a browser/WebGL.//// tsx scripts/smoke-map.ts [at-uri]//// Defaults to the baseline map Chris shared.
import { loadMapExport } from '../client/src/map-import.js'
const DEFAULT_URI = 'at://did:plc:dp7v5b5kejmmzzpwmqyf5wj6/world.tilemap.map/3mnkrgzpfiw22'const uri = process.argv[2] ?? DEFAULT_URI
async function main() { console.log(`loading ${uri}`) const { exp, atlasUrl } = await loadMapExport(uri)
let ok = true const check = (cond: boolean, msg: string) => { console.log(` ${cond ? '✓' : '✗'} ${msg}`) if (!cond) ok = false }
check(exp.version === 1, `MapExport version is 1 (got ${exp.version})`) check(exp.cell?.w > 0 && exp.cell?.h > 0, `cell size ${exp.cell?.w}×${exp.cell?.h}`) check(exp.depthAxis === 'x' || exp.depthAxis === 'y', `depthAxis = ${exp.depthAxis}`) check(Array.isArray(exp.nodes) && exp.nodes.length > 0, `${exp.nodes?.length} scene nodes`) check(Array.isArray(exp.objectDefs), `${exp.objectDefs?.length} object defs`) check(Array.isArray(exp.sheet?.entries) && exp.sheet.entries.length > 0, `${exp.sheet?.entries?.length} atlas entries`)
// node-kind breakdown (the engine handles canvas/object/collision/area/marker) const counts: Record<string, number> = {} for (const n of exp.nodes ?? []) counts[n.kind] = (counts[n.kind] ?? 0) + 1 console.log(' · node kinds:', JSON.stringify(counts))
// every object node must resolve to a def the engine can draw const defIds = new Set(exp.objectDefs.map((d) => d.id)) const danglingDefs = exp.nodes.filter((n) => n.kind === 'object' && !defIds.has(n.defId)) check(danglingDefs.length === 0, `all object nodes resolve a def (${danglingDefs.length} dangling)`)
// every atlas-referencing frame id must be in range const maxEntry = exp.sheet.entries.length - 1 const badFrames = exp.objectDefs.flatMap((d) => d.frames).filter((f) => f < 0 || f > maxEntry) check(badFrames.length === 0, `object frame ids in atlas range (${badFrames.length} out of range)`)
// atlas blob reachable + actually a PNG if (atlasUrl) { const res = await fetch(atlasUrl) const buf = new Uint8Array(await res.arrayBuffer()) const isPng = buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4e && buf[3] === 0x47 check(res.ok && isPng, `atlas reachable & PNG (${buf.length} bytes, sheet says ${exp.sheet.width}×${exp.sheet.height})`) } else { console.log(' · no atlas (colour-only map)') }
// bounds (handy sanity for camera framing) if (exp.bounds) console.log(` · painted bounds: ${exp.bounds.w}×${exp.bounds.h} at (${exp.bounds.x},${exp.bounds.y})`)
console.log(ok ? '\nMAP IMPORT SMOKE PASS' : '\nMAP IMPORT SMOKE FAIL') process.exit(ok ? 0 : 1)}
main().catch((e) => { console.error(e) process.exit(1)})