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-09-01 21:51:48 +02:00
|
|
|
set(grid.colors, cell, color ?? Toolbox.color());
|
2022-08-10 21:12:39 +02:00
|
|
|
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-09-01 21:51:48 +02:00
|
|
|
CellSet.isochrome(Grid.get().colors, origin)
|
|
|
|
.iter(function(cell) {colorize(cell);});
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
2022-08-06 20:18:30 +02:00
|
|
|
|
2022-09-01 21:51:48 +02:00
|
|
|
function setColors(coloring) {
|
|
|
|
if(coloring != undefined) {
|
|
|
|
iter(coloring, function(color, cell) {
|
|
|
|
if(color != undefined) {
|
|
|
|
colorize(cell, color);
|
2022-08-06 20:18:30 +02:00
|
|
|
}
|
|
|
|
});
|
2022-09-01 21:51:48 +02:00
|
|
|
if(Grid.get().missing.size() > 0) {
|
2022-08-06 20:18:30 +02:00
|
|
|
Mode.set('edit');
|
2022-09-01 21:51:48 +02:00
|
|
|
} else {
|
|
|
|
Mode.setEnabled(true, ['play', 'solve']);
|
2022-08-06 20:18:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|