@logic-pad/core
Version:
108 lines (107 loc) • 3.42 kB
JavaScript
import { ConfigType } from '../config.js';
import GridData from '../grid.js';
import { State, Mode } from '../primitives.js';
import CustomIconSymbol from '../symbols/customIconSymbol.js';
import Rule from './rule.js';
export default class ForesightRule extends Rule {
count;
regenInterval;
startFull;
solvePath;
title = 'Foresight';
get configExplanation() {
return 'Provide automatic hints to the player.';
}
static EXAMPLE_GRID = Object.freeze(GridData.create(['.']).addSymbol(new CustomIconSymbol('', GridData.create([]), 0, 0, 'MdRemoveRedEye')));
static CONFIGS = Object.freeze([
{
type: ConfigType.Number,
default: 5,
min: 1,
field: 'count',
description: 'Foresight count',
explanation: 'Maximum number of foresight charges that can be stored.',
configurable: true,
},
{
type: ConfigType.Number,
default: 30,
min: 1,
field: 'regenInterval',
description: 'Regen Interval (seconds)',
explanation: 'Time taken for one foresight charge to regenerate.',
configurable: true,
},
{
type: ConfigType.Boolean,
default: false,
field: 'startFull',
description: 'Start with full foresight',
explanation: 'Whether to start with all foresight charges available.',
configurable: true,
},
{
type: ConfigType.SolvePath,
default: [],
field: 'solvePath',
description: 'Intended solve path',
explanation: 'A logical solve path of the puzzle. Foresight will hint at the location of the next tile if this is available.',
configurable: true,
},
]);
static SEARCH_VARIANTS = [
new ForesightRule(5, 30, false).searchVariant(),
];
/**
* **Foresight: Show hints**
*/
constructor(count, regenInterval, startFull, solvePath = []) {
super();
this.count = count;
this.regenInterval = regenInterval;
this.startFull = startFull;
this.solvePath = solvePath;
this.count = count;
this.regenInterval = regenInterval;
this.startFull = startFull;
this.solvePath = solvePath;
}
get id() {
return `foresight`;
}
get explanation() {
return `*Foresight:* Show hints`;
}
get visibleWhenSolving() {
return false;
}
get configs() {
return ForesightRule.CONFIGS;
}
createExampleGrid() {
return ForesightRule.EXAMPLE_GRID;
}
get searchVariants() {
return ForesightRule.SEARCH_VARIANTS;
}
validateGrid(_grid) {
return { state: State.Incomplete };
}
get necessaryForCompletion() {
return false;
}
get isSingleton() {
return true;
}
modeVariant(mode) {
// foresight is disabled in perfection mode
if (mode === Mode.Perfection) {
return null;
}
return this;
}
copyWith({ count, regenInterval, startFull, solvePath, }) {
return new ForesightRule(count ?? this.count, regenInterval ?? this.regenInterval, startFull ?? this.startFull, solvePath ?? this.solvePath);
}
}
export const instance = new ForesightRule(5, 30, false);