UNPKG

@logic-pad/core

Version:
133 lines (132 loc) 4.82 kB
import { ConfigType } from '../config.js'; import GridData from '../grid.js'; import { Direction, Orientation, State } from '../primitives.js'; import DirectionLinkerSymbol from './directionLinkerSymbol.js'; export default class LotusSymbol extends DirectionLinkerSymbol { x; y; orientation; title = 'Lotus'; static linkedDirectionsFromOrientation = { [Orientation.Up]: { [Direction.Left]: Direction.Right, [Direction.Up]: Direction.Up, [Direction.Right]: Direction.Left, [Direction.Down]: Direction.Down, }, [Orientation.UpRight]: { [Direction.Left]: Direction.Down, [Direction.Up]: Direction.Right, [Direction.Right]: Direction.Up, [Direction.Down]: Direction.Left, }, [Orientation.Right]: { [Direction.Left]: Direction.Left, [Direction.Up]: Direction.Down, [Direction.Right]: Direction.Right, [Direction.Down]: Direction.Up, }, [Orientation.DownRight]: { [Direction.Left]: Direction.Up, [Direction.Up]: Direction.Left, [Direction.Right]: Direction.Down, [Direction.Down]: Direction.Right, }, [Orientation.Down]: { [Direction.Left]: Direction.Right, [Direction.Up]: Direction.Up, [Direction.Right]: Direction.Left, [Direction.Down]: Direction.Down, }, [Orientation.DownLeft]: { [Direction.Left]: Direction.Down, [Direction.Up]: Direction.Right, [Direction.Right]: Direction.Up, [Direction.Down]: Direction.Left, }, [Orientation.Left]: { [Direction.Left]: Direction.Left, [Direction.Up]: Direction.Down, [Direction.Right]: Direction.Right, [Direction.Down]: Direction.Up, }, [Orientation.UpLeft]: { [Direction.Left]: Direction.Up, [Direction.Up]: Direction.Left, [Direction.Right]: Direction.Down, [Direction.Down]: Direction.Right, }, }; /** * **Areas containing this symbol must be symmetrical** * * @param x - The x-coordinate of the symbol. * @param y - The y-coordinate of the symbol. * @param orientation - The orientation of the symbol. */ constructor(x, y, orientation) { super(x, y); this.x = x; this.y = y; this.orientation = orientation; super.changeDirections(LotusSymbol.linkedDirectionsFromOrientation[orientation]); } get id() { return `lotus`; } get explanation() { return `Areas containing this symbol must be *symmetrical*`; } get configs() { return Object.freeze([ { type: ConfigType.Number, default: 0, field: 'x', description: 'X', configurable: false, }, { type: ConfigType.Number, default: 0, field: 'y', description: 'Y', configurable: false, }, { type: ConfigType.Orientation, default: Orientation.Up, field: 'orientation', description: 'Orientation', configurable: true, }, ]); } createExampleGrid() { return Object.freeze(GridData.create(['wwbww', 'bwbwb', 'bwwwb', 'bwwwb']).addSymbol(new LotusSymbol(2, 2, Orientation.Up))); } validateSymbol(grid) { if (this.orientation === Orientation.DownLeft || this.orientation === Orientation.DownRight || this.orientation === Orientation.UpLeft || this.orientation === Orientation.UpRight) { if (this.x % 1 === 0 || this.y % 1 === 0) if (this.x % 1 !== 0 || this.y % 1 !== 0) { if (!grid.getTile(Math.floor(this.x), Math.floor(this.y)).exists && !grid.getTile(Math.ceil(this.x), Math.ceil(this.y)).exists && !grid.getTile(Math.floor(this.x), Math.ceil(this.y)).exists && !grid.getTile(Math.ceil(this.x), Math.floor(this.y)).exists) { return State.Satisfied; } else { return State.Error; } } } return super.validateSymbol(grid); } copyWith({ x, y, orientation, }) { return new LotusSymbol(x ?? this.x, y ?? this.y, orientation ?? this.orientation); } } export const instance = new LotusSymbol(0, 0, Orientation.Up);