UNPKG

@haelp/teto

Version:

A typescript-based controllable TETR.IO client.

71 lines (70 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get }); } _export(exports, { get kickData () { return _data.kicks; }, get legal () { return legal; }, get performKick () { return performKick; } }); const _data = require("./data"); 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; }; 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 = _data.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