@logic-pad/core
Version:
75 lines (74 loc) • 2.29 kB
JavaScript
import { ConfigType } from '../config.js';
import GridData from '../grid.js';
import { State } from '../primitives.js';
import Rule from './rule.js';
export default class CustomRule extends Rule {
description;
grid;
title = 'Custom Rule';
get configExplanation() {
return 'A customizable rule. Your provided solution may override auto-validation.';
}
static EXAMPLE_GRID = Object.freeze(GridData.create(5, 4));
static configs = Object.freeze([
{
type: ConfigType.String,
default: 'A *custom* rule',
field: 'description',
description: 'Description',
explanation: 'A short descriptive text. Use *asterisks* to highlight keywords.',
configurable: true,
},
{
type: ConfigType.Grid,
default: CustomRule.EXAMPLE_GRID,
field: 'grid',
description: 'Thumbnail Grid',
explanation: 'An example grid showing the rule.',
configurable: true,
},
]);
static SEARCH_VARIANTS = [
new CustomRule('A *custom* rule', CustomRule.EXAMPLE_GRID).searchVariant(),
];
/**
* A custom rule with a description and thumbnail grid.
*
* This rule validates answers based on the provided solution.
*
* @param description - The description of the rule.
* @param grid - The thumbnail grid of the rule, preferably 5x4 in size.
*/
constructor(description, grid) {
super();
this.description = description;
this.grid = grid;
this.description = description;
this.grid = grid;
}
get id() {
return `custom`;
}
get explanation() {
return this.description;
}
get configs() {
return CustomRule.configs;
}
createExampleGrid() {
return this.grid;
}
get searchVariants() {
return CustomRule.SEARCH_VARIANTS;
}
validateGrid(_grid) {
return { state: State.Incomplete };
}
copyWith({ description, grid, }) {
return new CustomRule(description ?? this.description, grid ?? this.grid);
}
get validateWithSolution() {
return true;
}
}
export const instance = new CustomRule('', GridData.create([]));