Constellations/js/Grid/Color.js

39 lines
811 B
JavaScript
Raw Normal View History

2022-08-10 21:12:39 +02:00
import * as CellSet from Geometry.CellSet;
import Grid;
2022-08-10 21:12:39 +02:00
import {at, iter, set} from Grid.Util;
import Toolbox;
import Mode;
return {
ize: colorize,
paint: paint,
2022-08-10 21:12:39 +02:00
setColors: setColors
};
2022-08-10 21:12:39 +02:00
function colorize(cell, color) {
var grid = Grid.get();
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-08-10 21:12:39 +02:00
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']);
}
}
}