UNPKG

tetris-fumen

Version:
106 lines (105 loc) 3.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseRotation = exports.parseRotationName = exports.Rotation = exports.parsePiece = exports.parsePieceName = exports.isMinoPiece = exports.Piece = void 0; var Piece; (function (Piece) { Piece[Piece["Empty"] = 0] = "Empty"; Piece[Piece["I"] = 1] = "I"; Piece[Piece["L"] = 2] = "L"; Piece[Piece["O"] = 3] = "O"; Piece[Piece["Z"] = 4] = "Z"; Piece[Piece["T"] = 5] = "T"; Piece[Piece["J"] = 6] = "J"; Piece[Piece["S"] = 7] = "S"; Piece[Piece["Gray"] = 8] = "Gray"; })(Piece = exports.Piece || (exports.Piece = {})); function isMinoPiece(piece) { return piece !== Piece.Empty && piece !== Piece.Gray; } exports.isMinoPiece = isMinoPiece; function parsePieceName(piece) { switch (piece) { case Piece.I: return 'I'; case Piece.L: return 'L'; case Piece.O: return 'O'; case Piece.Z: return 'Z'; case Piece.T: return 'T'; case Piece.J: return 'J'; case Piece.S: return 'S'; case Piece.Gray: return 'X'; case Piece.Empty: return '_'; } throw new Error("Unknown piece: ".concat(piece)); } exports.parsePieceName = parsePieceName; function parsePiece(piece) { switch (piece.toUpperCase()) { case 'I': return Piece.I; case 'L': return Piece.L; case 'O': return Piece.O; case 'Z': return Piece.Z; case 'T': return Piece.T; case 'J': return Piece.J; case 'S': return Piece.S; case 'X': case 'GRAY': return Piece.Gray; case ' ': case '_': case 'EMPTY': return Piece.Empty; } throw new Error("Unknown piece: ".concat(piece)); } exports.parsePiece = parsePiece; var Rotation; (function (Rotation) { Rotation[Rotation["Spawn"] = 0] = "Spawn"; Rotation[Rotation["Right"] = 1] = "Right"; Rotation[Rotation["Reverse"] = 2] = "Reverse"; Rotation[Rotation["Left"] = 3] = "Left"; })(Rotation = exports.Rotation || (exports.Rotation = {})); function parseRotationName(rotation) { switch (rotation) { case Rotation.Spawn: return 'spawn'; case Rotation.Left: return 'left'; case Rotation.Right: return 'right'; case Rotation.Reverse: return 'reverse'; } throw new Error("Unknown rotation: ".concat(rotation)); } exports.parseRotationName = parseRotationName; function parseRotation(rotation) { switch (rotation.toLowerCase()) { case 'spawn': return Rotation.Spawn; case 'left': return Rotation.Left; case 'right': return Rotation.Right; case 'reverse': return Rotation.Reverse; } throw new Error("Unknown rotation: ".concat(rotation)); } exports.parseRotation = parseRotation;