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');
|
2022-08-06 18:33:10 +02:00
|
|
|
var share = document.getElementById('share')
|
2022-07-28 17:39:51 +02:00
|
|
|
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onLeave() {
|
|
|
|
GUI.activate(false, [Grid.get().element, Toolbox.get(), save]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 18:33:10 +02:00
|
|
|
share.href = '?game=' + Share.naiveEncode(Grid.get().data);
|
2022-07-28 17:39:51 +02:00
|
|
|
}
|
|
|
|
}
|