2022-08-10 21:12:39 +02:00
|
|
|
import * as CellSet from Geometry.CellSet;
|
2022-07-28 17:39:51 +02:00
|
|
|
import Grid;
|
2022-08-10 21:12:39 +02:00
|
|
|
import {at, iter, set} from Grid.Util;
|
2022-07-28 17:39:51 +02:00
|
|
|
import Toolbox;
|
2022-08-06 20:18:30 +02:00
|
|
|
import Mode;
|
2022-07-28 17:39:51 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
ize: colorize,
|
2022-08-06 20:18:30 +02:00
|
|
|
paint: paint,
|
2022-08-10 21:12:39 +02:00
|
|
|
setColors: setColors
|
2022-07-28 17:39:51 +02:00
|
|
|
};
|
|
|
|
|
2022-08-10 21:12:39 +02:00
|
|
|
function colorize(cell, color) {
|
2022-07-28 17:39:51 +02:00
|
|
|
var grid = Grid.get();
|
2022-08-10 21:12:39 +02:00
|
|
|
set(grid.colors, cell, color || Toolbox.color());
|
|
|
|
at(Grid.get().cells, cell).className = 'color' + at(grid.colors, cell);
|
|
|
|
grid.missing.remove(cell);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
|
2022-08-10 21:12:39 +02:00
|
|
|
function paint(origin) {
|
2022-07-31 16:11:22 +02:00
|
|
|
var cellSet = CellSet.make(
|
2022-08-10 21:12:39 +02:00
|
|
|
{type: 'isochrome', grid: Grid.get().colors, origin: origin}
|
2022-07-31 16:11:22 +02:00
|
|
|
);
|
|
|
|
cellSet.iter(colorize);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
2022-08-06 20:18:30 +02:00
|
|
|
|
2022-08-10 21:12:39 +02:00
|
|
|
function setColors(grid) {
|
2022-08-06 20:18:30 +02:00
|
|
|
if(grid != undefined) {
|
2022-08-10 21:12:39 +02:00
|
|
|
iter(grid, function(cell) {
|
|
|
|
if(at(grid, cell) != undefined) {
|
|
|
|
colorize(cell, at(grid, cell));
|
2022-08-06 20:18:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
if(Grid.get().missing.isEmpty()) {
|
|
|
|
Mode.setEnabled(true, ['play', 'solve']);
|
|
|
|
} else {
|
|
|
|
Mode.set('edit');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|