2023-04-13 19:25:32 +00:00
|
|
|
import { argv } from 'node:process'
|
|
|
|
import { readFile } from 'node:fs/promises'
|
|
|
|
import { encoder as fumenEncoder } from 'tetris-fumen'
|
|
|
|
import { Simul } from './lib/sim.js'
|
|
|
|
|
|
|
|
export async function main(args) {
|
|
|
|
if (args.length < 1) {
|
|
|
|
throw new Error('no input file specified');
|
|
|
|
}
|
|
|
|
|
|
|
|
let buf = await readFile(args[0]);
|
|
|
|
let data = JSON.parse(buf.toString('utf-8'));
|
|
|
|
if (!data.moves) {
|
|
|
|
throw new Error('cannot generate replay without moves; pass --list-moves flag to tidepool');
|
|
|
|
}
|
|
|
|
|
|
|
|
let sim = new Simul(data.seed, data.config);
|
|
|
|
let pages = [];
|
|
|
|
for (let move of data.moves) {
|
|
|
|
let mino = {
|
|
|
|
type: move.type,
|
|
|
|
rotation: {
|
2023-04-14 00:07:00 +00:00
|
|
|
N: 'spawn',
|
|
|
|
E: 'right',
|
|
|
|
S: 'reverse',
|
|
|
|
W: 'left',
|
|
|
|
}[move.r],
|
2023-04-13 19:25:32 +00:00
|
|
|
x: move.x,
|
|
|
|
y: move.y,
|
|
|
|
};
|
|
|
|
pages.push(sim.play(mino));
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(fumenEncoder.encode(pages));
|
|
|
|
}
|
|
|
|
|
|
|
|
main(argv.slice(2));
|