Refactor mouse hold logic in animeCat.js
This commit is contained in:
13
animeCat.js
13
animeCat.js
@@ -138,10 +138,10 @@ _bindMouseHold() {
|
|||||||
let holdTimer = null;
|
let holdTimer = null;
|
||||||
let joyTimeout = null;
|
let joyTimeout = null;
|
||||||
let joyActive = false;
|
let joyActive = false;
|
||||||
// Neu:
|
let mouseDown = false; // <---- NEU! Initialisieren
|
||||||
let mouseDownAt = null;
|
let mouseDownAt = null; // <---- NEU!
|
||||||
let lastPos = null;
|
let lastPos = null; // <---- NEU!
|
||||||
let mouseMoved = 0;
|
let moveDist = 0; // <---- NEU!
|
||||||
|
|
||||||
const CAT_TOLERANCE = 15;
|
const CAT_TOLERANCE = 15;
|
||||||
const MOVE_THRESHOLD = 300;
|
const MOVE_THRESHOLD = 300;
|
||||||
@@ -193,7 +193,6 @@ _bindMouseHold() {
|
|||||||
|
|
||||||
const onMoveBound = onMove.bind(this);
|
const onMoveBound = onMove.bind(this);
|
||||||
|
|
||||||
// Nach 4 Sekunden wird entschieden, unabhängig vom Mauszustand
|
|
||||||
holdTimer = setTimeout(() => {
|
holdTimer = setTimeout(() => {
|
||||||
if (!mouseDown) return; // Schon abgebrochen
|
if (!mouseDown) return; // Schon abgebrochen
|
||||||
|
|
||||||
@@ -227,7 +226,6 @@ _bindMouseHold() {
|
|||||||
}
|
}
|
||||||
}, 4000);
|
}, 4000);
|
||||||
|
|
||||||
// Beim Loslassen: Falls früher losgelassen, normale Logik
|
|
||||||
function onUp() {
|
function onUp() {
|
||||||
if (!mouseDown) return;
|
if (!mouseDown) return;
|
||||||
cleanup();
|
cleanup();
|
||||||
@@ -250,7 +248,7 @@ _bindMouseHold() {
|
|||||||
this.img.src = this.images.mouthOpen || this.images.default;
|
this.img.src = this.images.mouthOpen || this.images.default;
|
||||||
this._startBlinking();
|
this._startBlinking();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (!joyActive && !this._isSpeaking) this.img.src = this.images.default;
|
if (!joyActive && !this._isSpeaking && !this._pettingActive) this.img.src = this.images.default;
|
||||||
}, mouthOpenTime);
|
}, mouthOpenTime);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -270,6 +268,7 @@ _bindMouseHold() {
|
|||||||
window.removeEventListener('mouseup', onUpBound);
|
window.removeEventListener('mouseup', onUpBound);
|
||||||
if (holdTimer) clearTimeout(holdTimer);
|
if (holdTimer) clearTimeout(holdTimer);
|
||||||
holdTimer = null;
|
holdTimer = null;
|
||||||
|
this._pettingActive = false; // <--- Hier sauber zurücksetzen!
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener('mousemove', onMoveBound);
|
window.addEventListener('mousemove', onMoveBound);
|
||||||
|
|||||||
Reference in New Issue
Block a user