3 ms·
I made a JS snippet to parse/execute moves formatted like this: function parseMoves(str) { const toks = str.split(',') const moves = [] for (cons
by shhsshs 7y ago
I made a JS snippet to parse/execute moves formatted like this:
function parseMoves(str) {
const toks = str.split(',')
const moves = []
for (const tok of toks) {
const [dir, num] = tok.trim().split(' ')
moves.push(...new Array(num - moves.length).fill(dir))
}
return moves
}
function toCharCode(key) {
switch (key) {
case 'down':
return 40
case 'up':
return 38
case 'right':
return 39
case 'left':
return 37
}
}
async function doMoves(str) {
const moves = parseMoves(str)
for (const move of moves) {
await new Promise(resolve => setTimeout(resolve, 100))
myRPG.parseKeyPress({
keyCode: toCharCode(move)
})
}
}
doMoves('left 26, up 27, right 30, up 32, right 33, up 35, left 38, down 41, left 42, down 45, right 50, up 53, right 54, up 58, right 59, up 60, right 61, up 66, right 67, up 69, right 71, up 73, right 78, down 81, right 82, down 83, right 84, down 85, right 87, down 88, right 90, down 93, right 94, down 95, right 99, up 100, right 103, down 109, left 112, down 113, left 114, down 115, left 116, down 119, left 123, down 127, left 130, down 131, right 132, down 135, left 136, down 137, left 142, up 145, left 148, up 151, left 161, up 169, right 172, up 177, left 178, up 179, right 182, up 191, right 200, down 203, right 205, down 207, right 211, down 215, right 222, down 227, left 228, down 229, right 233, down 234, right 235, down 240')