38 lines
997 B
JavaScript
38 lines
997 B
JavaScript
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: {
|
|
N: 'spawn',
|
|
E: 'right',
|
|
S: 'reverse',
|
|
W: 'left',
|
|
}[move.r],
|
|
x: move.x,
|
|
y: move.y,
|
|
};
|
|
pages.push(sim.play(mino));
|
|
}
|
|
|
|
console.log(fumenEncoder.encode(pages));
|
|
}
|
|
|
|
main(argv.slice(2));
|