2022-07-28 17:39:51 +02:00
|
|
|
import GUI;
|
|
|
|
import Grid;
|
|
|
|
import Grid.Color;
|
|
|
|
import Mode;
|
|
|
|
import Toolbox;
|
2022-08-06 18:33:10 +02:00
|
|
|
import Share;
|
2022-07-28 17:39:51 +02:00
|
|
|
|
|
|
|
var down = false;
|
|
|
|
Grid.get().element.addEventListener('mouseleave', function() {
|
|
|
|
down = false;
|
|
|
|
});
|
|
|
|
var save = document.getElementById('save');
|
|
|
|
|
|
|
|
return {
|
|
|
|
events: {
|
|
|
|
onEnter: onEnter,
|
|
|
|
onLeave: onLeave,
|
|
|
|
onMousedown: onMousedown,
|
|
|
|
onMouseup: onMouseup,
|
|
|
|
onMouseenter: onMouseenter
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function onEnter() {
|
|
|
|
GUI.activate(true, [Grid.get().element, Toolbox.get(), save]);
|
|
|
|
if(!Grid.get().missing.isEmpty()) {
|
|
|
|
Mode.setEnabled(false, ['play', 'solve']);
|
2022-08-06 20:18:30 +02:00
|
|
|
} else {
|
|
|
|
Share.link(Grid.get().colors);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onLeave() {
|
2022-08-06 20:18:30 +02:00
|
|
|
GUI.activate(false, [Grid.get().element, Toolbox.get(), save, Share.get()]);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onMousedown(e, row, column) {
|
|
|
|
if(e.button == GUI.mouse.left) {
|
|
|
|
down = true;
|
|
|
|
if(Toolbox.tool() == 'draw') {
|
|
|
|
colorCell(row, column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseup(e, row, column) {
|
|
|
|
if(e.button == GUI.mouse.left) {
|
|
|
|
down = false;
|
|
|
|
if(Toolbox.tool() == 'paint') {
|
|
|
|
Grid.Color.paint(row, column);
|
|
|
|
checkCompleteness();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMouseenter(e, row, column) {
|
|
|
|
if(down && Toolbox.tool() == 'draw') {
|
|
|
|
colorCell(row, column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function colorCell(row, column) {
|
|
|
|
Grid.Color.ize(row, column);
|
|
|
|
checkCompleteness();
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkCompleteness() {
|
|
|
|
if(Grid.get().missing.isEmpty()) {
|
|
|
|
Mode.setEnabled(true, ['play', 'solve']);
|
2022-08-06 20:18:30 +02:00
|
|
|
Share.link(Grid.get().colors);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
}
|