@logic-pad/core
Version:
114 lines (113 loc) • 3.77 kB
JavaScript
import { ConfigType } from '../config.js';
import GridData from '../grid.js';
import { Color, State } from '../primitives.js';
import CustomIconSymbol from './customIconSymbol.js';
import Symbol from './symbol.js';
export default class HiddenSymbol extends Symbol {
x;
y;
revealLocation;
title = 'Hidden Symbol Marker';
get configExplanation() {
return 'Other symbols in the same location will be hidden until this tile is colored correctly.';
}
static CONFIGS = 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.Boolean,
default: false,
field: 'revealLocation',
description: 'Reveal symbol location',
explanation: 'Whether to show this symbol when the tile is not yet colored correctly.',
configurable: true,
},
]);
static EXAMPLE_GRID = Object.freeze(GridData.create(['w']).addSymbol(new CustomIconSymbol('', GridData.create(['.']), 0, 0, 'MdHideSource') // Not using HiddenSymbol here because it is meant to be hidden in non-edit mode
));
/**
* **Hidden Symbols: color cells correctly to reveal more clues**
*
* @param x - The x-coordinate of the symbol.
* @param y - The y-coordinate of the symbol.
* @param revealLocation - Whether to reveal the location of the symbol.
*/
constructor(x, y, revealLocation = false) {
super(x, y);
this.x = x;
this.y = y;
this.revealLocation = revealLocation;
this.revealLocation = revealLocation;
}
get id() {
return `hidden`;
}
get explanation() {
return '*Hidden Symbols*: color cells correctly to reveal more clues';
}
get configs() {
return HiddenSymbol.CONFIGS;
}
createExampleGrid() {
return HiddenSymbol.EXAMPLE_GRID;
}
get necessaryForCompletion() {
return false;
}
get visibleWhenSolving() {
return this.revealLocation;
}
get sortOrder() {
return 0;
}
validateSymbol(grid, solution) {
const thisX = Math.floor(this.x);
const thisY = Math.floor(this.y);
const thisColor = grid.getTile(thisX, thisY).color;
if (solution) {
return thisColor === solution.getTile(thisX, thisY).color
? State.Satisfied
: State.Incomplete;
}
else {
return thisColor !== Color.Gray ? State.Satisfied : State.Incomplete;
}
}
onSymbolDisplay(grid, solution, symbol, editing) {
if (editing)
return true;
const thisX = Math.floor(this.x);
const thisY = Math.floor(this.y);
const symX = Math.floor(symbol.x);
const symY = Math.floor(symbol.y);
if (thisX !== symX || thisY !== symY)
return true;
const thisColor = grid.getTile(thisX, thisY).color;
const colorMatch = solution
? thisColor === solution.getTile(thisX, thisY).color
: thisColor !== Color.Gray;
if (symbol.id === this.id) {
return !colorMatch;
}
return colorMatch;
}
copyWith({ x, y, revealLocation, }) {
return new HiddenSymbol(x ?? this.x, y ?? this.y, revealLocation ?? this.revealLocation);
}
withRevealLocation(revealLocation) {
return this.copyWith({ revealLocation });
}
}
export const instance = new HiddenSymbol(0, 0);