UNPKG

@logic-pad/core

Version:
69 lines (68 loc) 1.91 kB
import { Color } from './primitives.js'; export default class TileData { constructor(exists, fixed, color) { Object.defineProperty(this, "exists", { enumerable: true, configurable: true, writable: true, value: exists }); Object.defineProperty(this, "fixed", { enumerable: true, configurable: true, writable: true, value: fixed }); Object.defineProperty(this, "color", { enumerable: true, configurable: true, writable: true, value: color }); this.exists = exists; this.fixed = fixed; this.color = color; } /** * Create a gray tile. */ static empty() { return new TileData(true, false, Color.Gray); } /** * Create a non-existent tile. */ static doesNotExist() { return new TileData(false, false, Color.Gray); } copyWith({ exists, fixed, color, }) { return new TileData(exists ?? this.exists, fixed ?? this.fixed, color ?? this.color); } withExists(exists) { return this.copyWith({ exists }); } withFixed(fixed) { return this.copyWith({ fixed }); } withColor(color) { return this.copyWith({ color }); } get isFixed() { return this.fixed; } equals(other) { return (this.exists === other.exists && this.fixed === other.fixed && this.color === other.color); } static create(char) { const exists = char !== '.'; const fixed = char.toUpperCase() === char; const color = char.toLowerCase() === 'n' ? Color.Gray : char.toLowerCase() === 'b' ? Color.Dark : Color.Light; return new TileData(exists, fixed, color); } }