Skip to content

Commit

Permalink
added double click feature
Browse files Browse the repository at this point in the history
  • Loading branch information
partha120804 committed Jul 5, 2024
1 parent 65ea81a commit 03d4885
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ var lastrand=-1;
var sound=true;
var moves=localStorage.getItem('sfa_moves') ? localStorage.getItem('sfa_moves') : 0;
var D={};

let lastClickTime = 0;
let doubleClickThreshold = 300;

findResult=(id1,id2)=>{
for (var i=0; i<recipes.length; i++){
if ((recipes[i].i[0] == id1) && (recipes[i].i[1] == id2)) return [recipes[i].r,recipes[i].m];
Expand Down Expand Up @@ -234,6 +238,10 @@ play=()=>{
bugfix();
}
pointerdown = e => {
let currentTime = new Date().getTime();
let timeDiff = currentTime - lastClickTime;
lastClickTime = currentTime;
let doubleClicked = timeDiff < doubleClickThreshold;
if (touchinprogress) return;
touchinprogress = true;
e.preventDefault();
Expand Down Expand Up @@ -291,7 +299,7 @@ play=()=>{
D.n = document.body.appendChild(D.g.cloneNode(true));
D.n.className = D.n.className.replace(/pantryIngredient/, 'ingredient');
D.n.id = 'i' + ingredients.length++;
if (D.g.parentNode.classList.contains("move")) {
if (D.g.parentNode.classList.contains("move") && !doubleClicked) {
D.g.style.visibility = "hidden";
D.g.m = D.g;
}
Expand Down

0 comments on commit 03d4885

Please sign in to comment.