UNPKG

@logic-pad/core

Version:
75 lines (74 loc) 2.17 kB
import { ConfigType } from '../config.js'; import GridData from '../grid.js'; import { Direction } from '../primitives.js'; import DirectionLinkerSymbol from './directionLinkerSymbol.js'; class GalaxySymbol extends DirectionLinkerSymbol { /** * **Galaxies are centers of rotational symmetry** * * @param x - The x-coordinate of the symbol. * @param y - The y-coordinate of the symbol. */ constructor(x, y) { super(x, y); Object.defineProperty(this, "x", { enumerable: true, configurable: true, writable: true, value: x }); Object.defineProperty(this, "y", { enumerable: true, configurable: true, writable: true, value: y }); super.changeDirections(GalaxySymbol.linkedDirections); } get id() { return `galaxy`; } get explanation() { return `*Galaxies* are centers of rotational symmetry`; } 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, }, ]); } createExampleGrid() { return Object.freeze(GridData.create(['wbbbb', 'wbwww', 'bbwbb', 'wwwbb']).addSymbol(new GalaxySymbol(2, 2))); } validateSymbol(grid) { return super.validateSymbol(grid); } copyWith({ x, y }) { return new GalaxySymbol(x ?? this.x, y ?? this.y); } } Object.defineProperty(GalaxySymbol, "linkedDirections", { enumerable: true, configurable: true, writable: true, value: { [Direction.Left]: Direction.Right, [Direction.Up]: Direction.Down, [Direction.Right]: Direction.Left, [Direction.Down]: Direction.Up, } }); export default GalaxySymbol; export const instance = new GalaxySymbol(0, 0);