Mouse hold functionality

This commit is contained in:
synth-ruiner 2015-03-06 10:41:53 +00:00
parent 0272c62f6c
commit b4a037c0cb
1 changed files with 36 additions and 12 deletions

View File

@ -217,6 +217,9 @@
var currentlyIterating = false;
var mineChance = 0.2;
var inputEnabled = true;
var clickholdMs = 200;
var timeout; //hold timer
var mouseHeld = false;
$(document).ready(function() {
function drawGameBoard() {
@ -309,10 +312,10 @@
});
//refresh last row to reflect new rows beneath
$('li.revealed').last().parent().children('li.revealed').mousedown();
$('li.revealed').last().parent().children('li.revealed').mouseup();
//click blank tiles
$('li.revealed:not(.mine):empty').mousedown();
$('li.revealed:not(.mine):empty').mouseup();
//this is a bit of a hack :( oh well
$('ul:gt(' + gameBoardHeight + ')').remove();
@ -497,16 +500,13 @@
//game over, or lose a life, or whatever
//...
} else if (parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged').length) {
} else if (!automated && parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) {
//already clicked; use middle click reveal functionality
//$(this).middleClick();
//number of flags matches number of adjacent mines
if (!automated && parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) {
$(this).getAdjacentTiles().filter(':not(.flagged)').each(function() {
$(this).mousedown();
});
}
$(this).getAdjacentTiles().filter(':not(.flagged, .revealed)').each(function() {
$(this).mouseup();
});
} else {
$(this).addClass("revealed");
@ -518,7 +518,7 @@
//if no mines adjacent, cascade!
if ($(this).countMinesAdjacent() == 0) {
$(this).getAdjacentTiles().filter(':not(.revealed)').mousedown();
$(this).getAdjacentTiles().filter(':not(.revealed)').mouseup();
}
}
@ -529,7 +529,7 @@
//number of flags matches number of adjacent mines
if (parseInt($(this).text()) === $(this).getAdjacentTiles().filter('.flagged, .revealed.mine').length) {
$(this).getAdjacentTiles().filter(':not(.flagged)').each(function() {
$(this).mousedown();
$(this).mouseup();
});
}
}
@ -541,17 +541,41 @@
} else {
$(this).toggleClass("flagged");
}
clearTimeout(timeout);
}
$(document).on("contextmenu", "li", function(event) {
event.preventDefault();
});
$(document).on("mousedown", "li", function(event) {
var x = $(this).getX();
var y = $(this).getY();
timeout = setTimeout(function() {
$('ul:eq(' + y + ') li:eq(' + x + ')').rightClick();
mouseHeld = true;
}, clickholdMs);
});
$(document).on("mouseleave", "li", function(event) {
clearTimeout(timeout);
});
$(document).on("mouseup", "li", function(event) {
event.preventDefault();
clearTimeout(timeout);
if (!inputEnabled) return;
if (mouseHeld) {
mouseHeld = false;
return;
}
switch (event.which) {
case 3:
$(this).rightClick();