UNPKG

@logic-pad/core

Version:
56 lines (55 loc) 2.53 kB
import { Orientation } from '../../../primitives.js'; import { BTTile } from '../data.js'; import DirectionLinkerBTModule from './directionLinker.js'; export default class LotusBTModule extends DirectionLinkerBTModule { instr; constructor(instr) { super(instr); this.instr = instr; } // Translate a position in relative to a lotus symbol movePos(grid, x, y) { const symbol = this.instr; let pos; if (symbol.orientation === Orientation.Up || symbol.orientation === Orientation.Down) { pos = { x: 2 * symbol.x - x, y }; } else if (symbol.orientation === Orientation.UpRight || symbol.orientation === Orientation.DownLeft) { pos = { x: symbol.y + symbol.x - y, y: symbol.y + symbol.x - x }; } else if (symbol.orientation === Orientation.Right || symbol.orientation === Orientation.Left) { pos = { x, y: 2 * symbol.y - y }; } else if (symbol.orientation === Orientation.DownRight || symbol.orientation === Orientation.UpLeft) { pos = { x: symbol.x - symbol.y + y, y: symbol.y - symbol.x + x }; } return grid.isInBound(pos.x, pos.y) ? pos : null; } getTileSafe(grid, x, y) { return grid.isInBound(x, y) ? grid.getTile(x, y) : BTTile.NonExist; } checkGlobal(grid) { if (this.instr.orientation === Orientation.DownLeft || this.instr.orientation === Orientation.DownRight || this.instr.orientation === Orientation.UpLeft || this.instr.orientation === Orientation.UpRight) { if (this.instr.x % 1 === 0 || this.instr.y % 1 === 0) if (this.instr.x % 1 !== 0 || this.instr.y % 1 !== 0) { if (this.getTileSafe(grid, Math.floor(this.instr.x), Math.floor(this.instr.y)) === BTTile.NonExist && this.getTileSafe(grid, Math.ceil(this.instr.x), Math.ceil(this.instr.y)) === BTTile.NonExist && this.getTileSafe(grid, Math.floor(this.instr.x), Math.ceil(this.instr.y)) === BTTile.NonExist && this.getTileSafe(grid, Math.ceil(this.instr.x), Math.floor(this.instr.y)) === BTTile.NonExist) { return { tilesNeedCheck: null, ratings: null }; } else { return false; } } } return super.checkGlobal(grid); } }