56 lines
2.4 KiB
JavaScript
56 lines
2.4 KiB
JavaScript
// 关卡数据格式校验
|
|
import tutorial from '../js/levels/tutorial.js';
|
|
import jump from '../js/levels/jump.js';
|
|
import endurance from '../js/levels/endurance.js';
|
|
import boss from '../js/levels/boss.js';
|
|
import troll from '../js/levels/troll.js';
|
|
|
|
const KNOWN = new Set([...'#@=M%~-*V^v<>SGFXPJWTOCBD! .']);
|
|
const ALL = [...tutorial, ...jump, ...endurance, ...boss, ...troll];
|
|
let bad = 0;
|
|
|
|
console.log('=== 关卡格式 ===');
|
|
for (const l of ALL) {
|
|
const w = l.width;
|
|
const h = l.grid.length;
|
|
const tag = `${l.id} ${l.name}`;
|
|
if (h < 19) { console.log(`! ${tag}: 高度 ${h} 行(建议 >=19,画布高 19 格)`); bad++; }
|
|
if (h > 60) { console.log(`! ${tag}: 高度 ${h} 行过大`); bad++; }
|
|
l.grid.forEach((row, y) => {
|
|
if (row.length !== w) { console.log(`! ${tag} row${y}: len=${row.length} 应为 ${w}`); bad++; }
|
|
for (const ch of row) if (!KNOWN.has(ch)) { console.log(`! ${tag} row${y}: 未知字符 '${ch}'`); bad++; }
|
|
});
|
|
const all = l.grid.join('');
|
|
const cnt = c => all.split(c).length - 1;
|
|
const s = cnt('S'), x = cnt('X'), b = cnt('B');
|
|
if (s !== 1) { console.log(`! ${tag}: S=${s}(必须且只能有一个出生点)`); bad++; }
|
|
if (l.type === 'boss') { if (b < 1) { console.log(`! ${tag}: BOSS关缺 B`); bad++; } }
|
|
else if (x < 1) { console.log(`! ${tag}: X=${x}(缺终点)`); bad++; }
|
|
|
|
if (l.turrets) {
|
|
const o = cnt('O');
|
|
if (o !== l.turrets.length) { console.log(`! ${tag}: O=${o} 但 turrets=${l.turrets.length}`); bad++; }
|
|
}
|
|
if (l.camzones) {
|
|
const c = cnt('C');
|
|
if (c > l.camzones.length) { console.log(`! ${tag}: C=${c} camzones=${l.camzones.length}`); bad++; }
|
|
}
|
|
if (l.warps) {
|
|
const ww = cnt('W');
|
|
if (ww !== l.warps.length) { console.log(`! ${tag}: W=${ww} 但 warps=${l.warps.length}`); bad++; }
|
|
}
|
|
if (l.bosses) {
|
|
if (b !== l.bosses.length) { console.log(`! ${tag}: B=${b} 但 bosses=${l.bosses.length}`); bad++; }
|
|
}
|
|
if (l.messages) {
|
|
const t = cnt('T');
|
|
if (t > l.messages.length) { console.log(`! ${tag}: T=${t} 但 messages=${l.messages.length}`); bad++; }
|
|
}
|
|
const g = cnt('G'), f = cnt('F');
|
|
console.log(` ${tag.padEnd(24)} ${String(w).padStart(3)}x${String(h).padStart(2)} S=${s} X=${x} G=${g} F=${f} B=${b} ${l.type}`);
|
|
}
|
|
|
|
console.log(`\n共 ${ALL.length} 关`);
|
|
console.log(bad ? `❌ 发现 ${bad} 个问题` : '✅ 全部关卡格式 OK');
|
|
process.exit(bad ? 1 : 0);
|