From a48589bcf903ee9786299ae0f84e901258a4a509 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 26 May 2025 05:10:20 +0200 Subject: [PATCH] Refactor animeCat.js to consolidate mouse hold logic into a separate method --- animeCat.js | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/animeCat.js b/animeCat.js index 8e784ff..83ec632 100644 --- a/animeCat.js +++ b/animeCat.js @@ -247,38 +247,13 @@ _bindMouseHold() { mouseDown = false; } else { // 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(); - } + this.consolation({ + cleanup, + mouseDown, + mouseDownAt, + reopenEyes, + joyActive + }); } }, 4000);