Files
kidgo/tmp/dump_levels.mjs
T

26 lines
987 B
JavaScript

// One-off: export all built-in levels to JSON for the Flutter port.
import { LEVELS, TYPE_LABEL, TYPE_CLASS } from './js/levels/index.js';
import { writeFileSync } from 'fs';
// Sanity: ensure serializable and report shapes.
function deepCheck(v, path) {
if (v === null || v === undefined) return;
if (typeof v === 'function') throw new Error('function at ' + path);
if (typeof v === 'object') {
if (Array.isArray(v)) { v.forEach((e, i) => deepCheck(e, path + '[' + i + ']')); }
else { for (const k of Object.keys(v)) deepCheck(v[k], path + '.' + k); }
}
}
for (const l of LEVELS) deepCheck(l, l.id || '?');
const out = {
levels: LEVELS,
typeLabel: TYPE_LABEL,
typeClass: TYPE_CLASS,
};
writeFileSync('levels_dump.json', JSON.stringify(out));
console.log('OK levels=', LEVELS.length, 'bytes=', JSON.stringify(out).length);
for (const l of LEVELS) {
console.log(' -', l.id, l.name, 'type=' + l.type, 'w=' + l.width, 'rows=' + (l.grid ? l.grid.length : '?'));
}