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 i = bodyStart; i < source.length; i++) { if (source[i] === '[') depth++; if (source[i] === ']' && --depth === 0) return source.slice(bodyStart, i + 1); } throw new Error(`Unclosed ${name}`); } const roomLayouts = Function(`return ${arrayLiteral('ROOM_LAYOUTS')}`)(); const fragments = Function(`return ${arrayLiteral('fragments')}`)(); const relays = Function(`return ${arrayLiteral('relays')}`)(); const benches = Function(`return ${arrayLiteral('benches')}`)(); const terminals = Function(`return ${arrayLiteral('terminals')}`)(); const shrine = Function(`return ${source.match(/const shrine = (\{[^;]+\});/)?.[1]}`)(); const airShrine = Function(`return ${source.match(/const airShrine = (\{[^;]+\});/)?.[1]}`)(); const door = Function(`return ${source.match(/const door = (\{[^;]+\});/)?.[1]}`)(); const mobilityGate = Function(`return ${source.match(/const mobilityGate = (\{[^;]+\});/)?.[1]}`)(); const maxRise = Number(source.match(/const MAX_SAFE_RISE = (\d+)/)?.[1]); const maxGap = Number(source.match(/MAX_SAFE_GAP = (\d+)/)?.[1]); const jumpSpeed = Number(source.match(/JUMP_SPEED = (\d+)/)?.[1]); const gravity = Number(source.match(/GRAVITY = (\d+)/)?.[1]); const roomWidth = Number(source.match(/ROOM_W = (\d+)/)?.[1]); const platforms = roomLayouts.flatMap((layout, index) => { const start = index * roomWidth; return [ ...layout.ground.map(([x, w]) => ({ x: start + x, y: 610, w, h: 130 })), ...layout.ledges.map(([x, y, w]) => ({ x: start + x, y, w, h: 24 })) ]; }); const spikes = Function(`return ${arrayLiteral('spikes')}`)(); const safeZones = Function(`return ${arrayLiteral('safeZones')}`)(); const theoreticalRise = jumpSpeed ** 2 / (2 * gravity); const horizontalGap = (a, b) => Math.max(0, Math.max(a.x, b.x) - Math.min(a.x + a.w, b.x + b.w) ); const jumpReach = rise => { const discriminant = jumpSpeed ** 2 - 2 * gravity * Math.max(0, rise); if (discriminant < 0) return 0; const airTime = (jumpSpeed + Math.sqrt(discriminant)) / gravity; return 260 * airTime + 38; }; const reachable = new Set([0]); const queue = [0]; while (queue.length) { const from = platforms[queue.shift()]; platforms.forEach((to, index) => { if (reachable.has(index)) return; const rise = from.y - to.y; const gap = horizontalGap(from, to); if (rise <= maxRise && gap <= maxGap && gap <= jumpReach(rise)) { reachable.add(index); queue.push(index); } }); } const unreachable = platforms.map((_, index) => index).filter(index => !reachable.has(index)); const missedFragments = fragments.filter(fragment => !platforms.some(platform => fragment.x >= platform.x && fragment.x <= platform.x + platform.w && Math.abs(fragment.y - (platform.y - 39)) <= 62 )); const unsupportedRelays = relays.filter(relay => !platforms.some(platform => relay.x + relay.w >= platform.x && relay.x <= platform.x + platform.w && Math.abs(relay.y + relay.h - platform.y) <= 5 )); const unsupportedProps = [...benches, ...terminals].filter(prop => !platforms.some(platform => prop.x + prop.w >= platform.x && prop.x <= platform.x + platform.w && Math.abs(prop.y + prop.h - platform.y) <= 5 )); const shrineSupported = platforms.some(platform => shrine.x + shrine.w >= platform.x && shrine.x <= platform.x + platform.w && Math.abs(shrine.y + shrine.h - platform.y) <= 5 ); const airShrineSupported = platforms.some(platform => airShrine.x + airShrine.w >= platform.x && airShrine.x <= platform.x + platform.w && Math.abs(airShrine.y + airShrine.h - platform.y) <= 5 ); const backtrackingOrder = Math.floor(shrine.x / roomWidth) === 4 && Math.floor(door.x / roomWidth) === 6 && Math.floor(airShrine.x / roomWidth) === 14 && Math.floor(mobilityGate.x / roomWidth) === 16; const unsupportedSpikes = spikes.filter(spike => !platforms.some(platform => spike.x >= platform.x && spike.x + spike.w <= platform.x + platform.w && Math.abs(spike.y + 18 - platform.y) <= 2 )); const badRoomGround = roomLayouts.flatMap((layout, room) => { const sorted = [...layout.ground].sort((a, b) => a[0] - b[0]); const failures = []; if (sorted[0][0] !== 0 || sorted.at(-1)[0] + sorted.at(-1)[1] !== roomWidth) failures.push(`room ${room}: entry/exit floor missing`); for (let index = 1; index < sorted.length; index++) { const gap = sorted[index][0] - (sorted[index - 1][0] + sorted[index - 1][1]); if (gap > maxGap) failures.push(`room ${room}: ground gap ${gap}px`); } return failures; }); const unsafeProps = [...benches, ...terminals].filter(prop => !safeZones.some(zone => prop.x >= zone.x && prop.x + prop.w <= zone.x + zone.w && prop.y + prop.h <= zone.y + zone.h )); console.log(`Theoretical jump rise: ${theoreticalRise.toFixed(1)}px; authored safe rise: ${maxRise}px`); console.log(`Reachable platforms: ${reachable.size}/${platforms.length}`); console.log(`Reachable lyric fragments: ${fragments.length - missedFragments.length}/${fragments.length}`); console.log(`Supported echo relays: ${relays.length - unsupportedRelays.length}/${relays.length}`); console.log(`Supported interactive props: ${benches.length + terminals.length - unsupportedProps.length}/${benches.length + terminals.length}`); console.log(`Safe interactive props: ${benches.length + terminals.length - unsafeProps.length}/${benches.length + terminals.length}`); console.log(`Metroidvania route order: ${backtrackingOrder && shrineSupported ? 'valid' : 'invalid'}`); if (unreachable.length || missedFragments.length || unsupportedRelays.length || unsupportedProps.length || unsupportedSpikes.length || badRoomGround.length || unsafeProps.length || !shrineSupported || !airShrineSupported || !backtrackingOrder) { if (unreachable.length) console.error('Unreachable platform indices:', unreachable); if (missedFragments.length) console.error('Unreachable fragments:', missedFragments); if (unsupportedRelays.length) console.error('Unsupported relays:', unsupportedRelays); if (unsupportedProps.length) console.error('Unsupported interactive props:', unsupportedProps); if (unsupportedSpikes.length) console.error('Unsupported spikes:', unsupportedSpikes); if (badRoomGround.length) console.error('Unsafe room ground:', badRoomGround); if (unsafeProps.length) console.error('Interactive props outside safe zones:', unsafeProps); if (!shrineSupported) console.error('Ability shrine is not supported by a platform'); if (!airShrineSupported) console.error('Air-echo shrine is not supported by a platform'); if (!backtrackingOrder) console.error('Each ability shrine must precede its matching traversal gate'); process.exitCode = 1; }