UNPKG

@logic-pad/core

Version:
64 lines (63 loc) 1.84 kB
import Instruction from '../instruction.js'; export default class Symbol extends Instruction { constructor(x, y) { super(); Object.defineProperty(this, "x", { enumerable: true, configurable: true, writable: true, value: x }); Object.defineProperty(this, "y", { enumerable: true, configurable: true, writable: true, value: y }); this.x = x; this.y = y; } modeVariant(_mode) { return this; } onGridResize(_grid, mode, direction, index) { if (mode === 'insert') { return this.copyWith({ x: direction === 'column' && this.x >= index ? this.x + 1 : this.x, y: direction === 'row' && this.y >= index ? this.y + 1 : this.y, }); } else { if (direction === 'column' && this.x === index) return null; if (direction === 'row' && this.y === index) return null; return this.copyWith({ x: direction === 'column' && this.x > index ? this.x - 1 : this.x, y: direction === 'row' && this.y > index ? this.y - 1 : this.y, }); } } /** * The step size for the x and y coordinates of the symbol. */ get placementStep() { return 0.5; } /** * The order in which symbols are displayed on the instruction list. Lower values are displayed first. */ get sortOrder() { return this.id.charCodeAt(0); } withX(x) { return this.copyWith({ x }); } withY(y) { return this.copyWith({ y }); } withPosition(x, y) { return this.copyWith({ x, y }); } } export const instance = undefined;