import { readFileSync } from 'node:fs'; const source = readFileSync(new URL('../game.js', import.meta.url), 'utf8'); function arrayLiteral(name) { const marker = `const ${name} = [`; const start = source.indexOf(marker); if (start < 0) throw new Error(`Missing ${name}`); const bodyStart = start + marker.length - 1; let depth = 0; for (let index = bodyStart; index < source.length; index++) { if (source[index] === '[') depth++; if (source[index] === ']' && --depth === 0) return source.slice(bodyStart, index + 1); } throw new Error(`Unclosed ${name}`); } const rooms = Function(`return ${arrayLiteral('ROOMS')}`)(); const benches = Function(`return ${arrayLiteral('benches')}`)(); const relays = Function(`return ${arrayLiteral('relays')}`)(); const terminals = Function(`return ${arrayLiteral('terminals')}`)(); const safeZones = Function(`return ${arrayLiteral('safeZones')}`)(); const lamps = Function(`return ${arrayLiteral('memoryLamps')}`)(); const layouts = Function(`return ${arrayLiteral('ROOM_LAYOUTS')}`)(); const shrine = Function(`return ${source.match(/const shrine = (\{[^;]+\});/)?.[1]}`)(); const airShrine = Function(`return ${source.match(/const airShrine = (\{[^;]+\});/)?.[1]}`)(); const roomWidth = Number(source.match(/ROOM_W = (\d+)/)?.[1]); const roomCount = Number(source.match(/ROOM_COUNT = (\d+)/)?.[1]); const canvasWidth = Number(source.match(/const W = canvas\.width, H = canvas\.height/) ? 1280 : 0); const roomGeometryValid = rooms.length === roomCount && rooms.every((room, index) => room.start === index * roomWidth && room.end === (index + 1) * roomWidth && room.end - room.start >= canvasWidth ); const interactions = [...benches, ...relays, ...terminals, ...lamps, shrine, airShrine]; const density = rooms.map(room => interactions.filter(item => item.x >= room.start && item.x < room.end).length); const sparseInteractions = Math.max(...density) <= 3; const richRooms = layouts.every(layout => layout.ground.length + layout.ledges.length >= 5); const safeInteractions = [...benches, ...terminals].every(item => safeZones.some(zone => item.x >= zone.x && item.x + item.w <= zone.x + zone.w && item.y + item.h <= zone.y + zone.h )); const boundariesClear = interactions.every(item => { const room = rooms[Math.floor(item.x / roomWidth)]; return item.x - room.start >= 80 && room.end - (item.x + item.w) >= 80; }); const isolatedRendering = source.includes('ctx.rect(room.start,-120,room.end-room.start,H+240)') && source.includes('ctx.clip()'); const boundaryTransitions = source.includes('checkRoomBoundary') && source.includes('startRoomTransition(currentRoom+1,1)') && source.includes('startRoomTransition(currentRoom-1,-1)'); const roomCameraLock = source.includes('roomCameraTarget') && source.includes('Math.min(room.end-W'); const checks = [ [`${rooms.length} contiguous rooms at least one screen wide`, roomGeometryValid], ['at most three well-spaced interactions per 2400px room', sparseInteractions], ['every room has layered traversal content', richRooms], ['benches and terminals are inside safe zones', safeInteractions], ['interactions stay away from transition edges', boundariesClear], ['world rendering clipped to current room', isolatedRendering], ['both room-boundary directions transition', boundaryTransitions], ['camera clamped inside current room', roomCameraLock] ]; console.log(`Room width: ${roomWidth}px; interaction density: ${density.join('/')}`); for (const [label, passed] of checks) console.log(`${passed ? 'PASS' : 'FAIL'} ${label}`); if (checks.some(([, passed]) => !passed)) process.exitCode = 1;