Fix petting on mobile

This commit is contained in:
Idrees Hassan
2025-10-25 20:40:25 -04:00
parent e55f0e7412
commit f45eb0ce61
6 changed files with 146 additions and 45 deletions

32
birb.js
View File

@@ -943,6 +943,10 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
});
onClick(canvas, () => {
if (currentAnimation === Animations.HEART) {
// Currently being pet, don't open menu
return;
}
insertMenu();
});
@@ -955,13 +959,17 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
}
const pets = petStack.filter((time) => Date.now() - time < 1000).length;
if (pets >= 3) {
setAnimation(Animations.HEART);
pet();
// Clear the stack
petStack = [];
}
}
});
canvas.addEventListener("touchmove", (e) => {
pet();
});
drawStickyNotes();
let lastUrl = (window.location.href ?? "").split("?")[0];
@@ -1448,7 +1456,23 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
*/
function onClick(element, action) {
element.addEventListener("click", (e) => action(e));
element.addEventListener("touchstart", (e) => action(e));
element.addEventListener("touchend", (e) => {
if (e instanceof TouchEvent === false) {
return;
} else if (element instanceof HTMLElement === false) {
return;
}
const touch = e.changedTouches[0];
const rect = element.getBoundingClientRect();
if (
touch.clientX >= rect.left &&
touch.clientX <= rect.right &&
touch.clientY >= rect.top &&
touch.clientY <= rect.bottom
) {
action(e);
}
});
}
/**
@@ -1608,7 +1632,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
function getFullWindowHeight() {
return document.documentElement.clientHeight;
}
function focusOnGround() {
console.log("Focusing on ground");
focusedElement = null;
@@ -1678,7 +1702,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
}
function pet() {
if (currentState === States.IDLE) {
if (currentState === States.IDLE && currentAnimation !== Animations.HEART) {
setAnimation(Animations.HEART);
lastPetTimestamp = Date.now();
}