UNPKG

@haelp/teto

Version:

A typescript-based controllable TETR.IO client.

51 lines (50 loc) 1.91 kB
import { kicks } from "./data.mjs"; export { kicks as kickData }; export const legal = (blocks, board)=>{ if (board.length === 0) return false; for (const block of blocks){ if (block[0] < 0) return false; if (block[0] >= board[0].length) return false; if (block[1] < 0) return false; if (block[1] >= board.length) return false; if (board[block[1]][block[0]]) return false; } return true; }; export const performKick = (kicktable, piece, pieceLocation, ao, maxMovement, blocks, startRotation, endRotation, board)=>{ try { if (legal(blocks.map((block)=>[ pieceLocation[0] + block[0] - ao[0], Math.floor(pieceLocation[1]) - block[1] - ao[1] ]), board)) return true; const kickID = `${startRotation}${endRotation}`; const table = kicks[kicktable]; const customKicksetID = `${piece.toLowerCase()}_kicks`; const kickset = customKicksetID in table ? table[customKicksetID][kickID] : table.kicks[kickID]; for(let i = 0; i < kickset.length; i++){ const [dx, dy] = kickset[i]; const newY = maxMovement ? pieceLocation[1] - dy - ao[1] : Math.ceil(pieceLocation[1]) - 0.1 - dy - ao[1]; if (legal(blocks.map((block)=>[ pieceLocation[0] + block[0] + dx - ao[0], Math.floor(newY) - block[1] ]), board)) { return { newLocation: [ pieceLocation[0] + dx - ao[0], newY ], kick: [ dx, -dy ], id: kickID, index: i }; } } return false; } catch { return false; } }; //# sourceMappingURL=index.js.map