Refactor and improve consolation logic in animeCat.js
This commit is contained in:
76
animeCat.js
76
animeCat.js
@@ -138,6 +138,41 @@ window.AnimeCat = class AnimeCat {
|
||||
}, delay);
|
||||
}
|
||||
|
||||
_consolation({ cleanup, mouseDown, mouseDownAt, reopenEyes, joyActive }) {
|
||||
cleanup();
|
||||
mouseDown = false;
|
||||
reopenEyes();
|
||||
const heldFor = Date.now() - mouseDownAt;
|
||||
|
||||
if (heldFor > 1000) {
|
||||
// mind. 1000ms oder (heldFor - 1000), je nachdem was größer ist
|
||||
const mouthOpenTime = Math.max(heldFor - 1000, 1000);
|
||||
|
||||
// Bildwahl: mischievous ab 4. Mal, sonst mouth_open
|
||||
let imgToShow = this.images.mouthOpen || this.images.default;
|
||||
if (this._consolationCount >= 3) {
|
||||
// Ab dem vierten Mal: mischievous immer, danach 20% Chance
|
||||
if (
|
||||
this._consolationCount === 3 ||
|
||||
Math.random() < 0.2
|
||||
) {
|
||||
imgToShow = this.images.mischievous || imgToShow;
|
||||
}
|
||||
}
|
||||
|
||||
this.img.src = imgToShow;
|
||||
this._consolationCount++;
|
||||
this._startBlinking();
|
||||
setTimeout(() => {
|
||||
if (!joyActive && !this._isSpeaking && !this._pettingActive) {
|
||||
this.img.src = this.images.default;
|
||||
}
|
||||
}, mouthOpenTime);
|
||||
} else {
|
||||
this._startBlinking();
|
||||
}
|
||||
}
|
||||
|
||||
_bindMouseHold() {
|
||||
let holdTimer = null;
|
||||
let joyTimeout = null;
|
||||
@@ -261,39 +296,14 @@ _bindMouseHold() {
|
||||
this._startBlinking();
|
||||
});
|
||||
}
|
||||
// Trostpreis: Augen auf, dann mouth_open oder mischievous
|
||||
cleanup();
|
||||
mouseDown = false;
|
||||
reopenEyes();
|
||||
const heldFor = Date.now() - mouseDownAt;
|
||||
|
||||
if (heldFor > 1000) {
|
||||
// mind. 1000ms oder (heldFor - 1000), je nachdem was größer ist
|
||||
const mouthOpenTime = Math.max(heldFor - 1000, 1000);
|
||||
|
||||
// Bildwahl: mischievous ab 4. Mal, sonst mouth_open
|
||||
let imgToShow = this.images.mouthOpen || this.images.default;
|
||||
if (this._consolationCount >= 3) {
|
||||
// Ab dem vierten Mal: mischievous immer, danach 20% Chance
|
||||
if (
|
||||
this._consolationCount === 3 ||
|
||||
Math.random() < 0.2
|
||||
) {
|
||||
imgToShow = this.images.mischievous || imgToShow;
|
||||
}
|
||||
}
|
||||
|
||||
this.img.src = imgToShow;
|
||||
this._consolationCount++;
|
||||
this._startBlinking();
|
||||
setTimeout(() => {
|
||||
if (!joyActive && !this._isSpeaking && !this._pettingActive) {
|
||||
this.img.src = this.images.default;
|
||||
}
|
||||
}, mouthOpenTime);
|
||||
} else {
|
||||
this._startBlinking();
|
||||
}
|
||||
// Trostpreis: Augen auf, dann mouth_open oder mischievous
|
||||
this.consolation({
|
||||
cleanup,
|
||||
mouseDown,
|
||||
mouseDownAt,
|
||||
reopenEyes,
|
||||
joyActive
|
||||
});
|
||||
mouseDown = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user