38 lines
811 B
JavaScript
38 lines
811 B
JavaScript
import * as CellSet from Geometry.CellSet;
|
|
import Grid;
|
|
import {at, iter, set} from Grid.Util;
|
|
import Toolbox;
|
|
import Mode;
|
|
|
|
return {
|
|
ize: colorize,
|
|
paint: paint,
|
|
setColors: setColors
|
|
};
|
|
|
|
function colorize(cell, color) {
|
|
var grid = Grid.get();
|
|
set(grid.colors, cell, color ?? Toolbox.color());
|
|
at(Grid.get().cells, cell).className = 'color' + at(grid.colors, cell);
|
|
grid.missing.remove(cell);
|
|
}
|
|
|
|
function paint(origin) {
|
|
CellSet.isochrome(Grid.get().colors, origin)
|
|
.iter(function(cell) {colorize(cell);});
|
|
}
|
|
|
|
function setColors(coloring) {
|
|
if(coloring != undefined) {
|
|
iter(coloring, function(color, cell) {
|
|
if(color != undefined) {
|
|
colorize(cell, color);
|
|
}
|
|
});
|
|
if(Grid.get().missing.size() > 0) {
|
|
Mode.set('edit');
|
|
} else {
|
|
Mode.setEnabled(true, ['play', 'solve']);
|
|
}
|
|
}
|
|
}
|