Increase CAT_TOLERANCE and update event listeners for animeCat.js
This commit is contained in:
28
animeCat.js
28
animeCat.js
@@ -138,9 +138,8 @@ _bindMouseHold() {
|
|||||||
let lastPos = null;
|
let lastPos = null;
|
||||||
let moveDist = 0;
|
let moveDist = 0;
|
||||||
|
|
||||||
const CAT_TOLERANCE = 15;
|
const CAT_TOLERANCE = 36;
|
||||||
|
|
||||||
// Prüfen ob die Maus noch im erlaubten Streichelbereich ist
|
|
||||||
const isMouseNearCat = (e) => {
|
const isMouseNearCat = (e) => {
|
||||||
const rect = this.img.getBoundingClientRect();
|
const rect = this.img.getBoundingClientRect();
|
||||||
return (
|
return (
|
||||||
@@ -160,7 +159,6 @@ _bindMouseHold() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mousedown nur auf Katze selbst!
|
|
||||||
this.img.addEventListener('mousedown', (e) => {
|
this.img.addEventListener('mousedown', (e) => {
|
||||||
if (this._isSpeaking || joyActive) return;
|
if (this._isSpeaking || joyActive) return;
|
||||||
if (!isMouseNearCat(e)) return;
|
if (!isMouseNearCat(e)) return;
|
||||||
@@ -170,13 +168,17 @@ _bindMouseHold() {
|
|||||||
moveDist = 0;
|
moveDist = 0;
|
||||||
closeEyes();
|
closeEyes();
|
||||||
|
|
||||||
// Maus-Events für das ganze Fenster aktivieren!
|
// *** Blinken pausieren ***
|
||||||
|
clearTimeout(this._blinkTimeout);
|
||||||
|
|
||||||
function onMove(ev) {
|
function onMove(ev) {
|
||||||
if (!mouseDown) return;
|
if (!mouseDown) return;
|
||||||
if (!isMouseNearCat(ev)) {
|
if (!isMouseNearCat(ev)) {
|
||||||
cleanup();
|
cleanup();
|
||||||
reopenEyes();
|
reopenEyes();
|
||||||
mouseDown = false;
|
mouseDown = false;
|
||||||
|
// *** Nach Streichelspiel Blinken neu starten ***
|
||||||
|
this._startBlinking();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (lastPos) {
|
if (lastPos) {
|
||||||
@@ -187,21 +189,27 @@ _bindMouseHold() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onMoveBound = onMove.bind(this);
|
||||||
|
|
||||||
function onUp() {
|
function onUp() {
|
||||||
cleanup();
|
cleanup();
|
||||||
if (!joyActive) reopenEyes();
|
if (!joyActive) reopenEyes();
|
||||||
mouseDown = false;
|
mouseDown = false;
|
||||||
|
// *** Nach Streichelspiel Blinken neu starten ***
|
||||||
|
this._startBlinking();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onUpBound = onUp.bind(this);
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
window.removeEventListener('mousemove', onMove);
|
window.removeEventListener('mousemove', onMoveBound);
|
||||||
window.removeEventListener('mouseup', onUp);
|
window.removeEventListener('mouseup', onUpBound);
|
||||||
if (holdTimer) clearTimeout(holdTimer);
|
if (holdTimer) clearTimeout(holdTimer);
|
||||||
holdTimer = null;
|
holdTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('mousemove', onMove);
|
window.addEventListener('mousemove', onMoveBound);
|
||||||
window.addEventListener('mouseup', onUp);
|
window.addEventListener('mouseup', onUpBound);
|
||||||
|
|
||||||
holdTimer = setTimeout(() => {
|
holdTimer = setTimeout(() => {
|
||||||
if (moveDist >= 75) {
|
if (moveDist >= 75) {
|
||||||
@@ -210,10 +218,14 @@ _bindMouseHold() {
|
|||||||
this._runJoyAnimation(() => {
|
this._runJoyAnimation(() => {
|
||||||
joyActive = false;
|
joyActive = false;
|
||||||
reopenEyes();
|
reopenEyes();
|
||||||
|
// *** Nach Streichelspiel Blinken neu starten ***
|
||||||
|
this._startBlinking();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
cleanup();
|
cleanup();
|
||||||
reopenEyes();
|
reopenEyes();
|
||||||
|
// *** Nach Streichelspiel Blinken neu starten ***
|
||||||
|
this._startBlinking();
|
||||||
}
|
}
|
||||||
mouseDown = false;
|
mouseDown = false;
|
||||||
}, 4000);
|
}, 4000);
|
||||||
|
|||||||
Reference in New Issue
Block a user