From 77fea785f1c157cfb451e2feb1973e3500041a9b Mon Sep 17 00:00:00 2001 From: peshomir <80340328+peshomir@users.noreply.github.com> Date: Tue, 22 Jul 2025 13:17:12 +0300 Subject: [PATCH] Prevent hovering tooltiip from causing perspective switching during replays --- patches/hoveringTooltip.js | 38 ++++++++++++++++++++++++++++++++++++++ patches/patches.js | 28 ---------------------------- src/hoveringTooltip.js | 3 +++ 3 files changed, 41 insertions(+), 28 deletions(-) create mode 100644 patches/hoveringTooltip.js diff --git a/patches/hoveringTooltip.js b/patches/hoveringTooltip.js new file mode 100644 index 0000000..c2fae4d --- /dev/null +++ b/patches/hoveringTooltip.js @@ -0,0 +1,38 @@ +import ModUtils from "../modUtils.js" + +export default (/** @type {ModUtils} */ { insertCode, replaceRawCode, waitForMinification }) => { + + insertCode(`/* here */ + this.click = function(lK, lL, a1m) { + var gy = bL.gz(lK); + var h0 = bL.h1(lL); + var eV = bL.f7(gy, h0); + var eN = bL.eZ(eV); + if (!bL.isInMapBounds(gy, h0)) { return false; } + var a5C = (Device.a1.largeUIEnabled() ? 0.025 : 0.0144) * h___.hu; + var dp = performance.now(); + if (Math.abs(lK - a4t) > a5C || Math.abs(lL - a4u) > a5C || dp > time + 500) { return false; } + time = dp; + if (a1m) { a5D(lK, lL, eN); return false; } + /*...*/}`, + `__fx.hoveringTooltip.display = function(mouseX, mouseY) { + var coordX = bL.gz(mouseX), coordY = bL.h1(mouseY), + coord = bL.f7(coordX, coordY), point = bL.eZ(coord); + // if (coordX < 0 || coordY < 0) return; + if (bL.isInMapBounds(coordX, coordY)) (function(lK, lL, eN) { + a5D(lK, lL, eN) + }(mouseX, mouseY, point)) + }`) + insertCode(`player = aQ.eF(eR); + if (game.gIsReplay /* here */) { game.playerId = player; } + str = L(58, /* Player: {0} */ [b0.context.truncateAndFillText(playerData.rawPlayerNames[player], b0.qZ.sN(0, 10), 150)]) + " "; + str += L(59, /* Strength: {10} */ [b0.rY.formatNumber(playerData.playerBalances[player])]) + " "; + str += L(60, /* Territory: {10} */ [b0.rY.formatNumber(playerData.playerTerritories[player])]) + " ";`, + `&& __fx.hoveringTooltip.active === false`) + + waitForMinification(() => { + replaceRawCode("aK.nH=(window.devicePixelRatio||1)*aEr,", + `aK.nH = (window.devicePixelRatio || 1) * aEr, __fx.hoveringTooltip.canvasPixelScale = aK.nH,`) + }) + +} \ No newline at end of file diff --git a/patches/patches.js b/patches/patches.js index 1499f0a..a67e13a 100644 --- a/patches/patches.js +++ b/patches/patches.js @@ -11,29 +11,6 @@ export default (/** @type {ModUtils} */ modUtils) => { return alert("Error:\\n" + e.filename + " " + e.lineno + " " + e.colno + " " + e.message);` ) - // Hovering tooltip - modUtils.insertCode(`/* here */ - this.click = function(lK, lL, a1m) { - var gy = bL.gz(lK); - var h0 = bL.h1(lL); - var eV = bL.f7(gy, h0); - var eN = bL.eZ(eV); - if (!bL.isInMapBounds(gy, h0)) { return false; } - var a5C = (Device.a1.largeUIEnabled() ? 0.025 : 0.0144) * h___.hu; - var dp = performance.now(); - if (Math.abs(lK - a4t) > a5C || Math.abs(lL - a4u) > a5C || dp > time + 500) { return false; } - time = dp; - if (a1m) { a5D(lK, lL, eN); return false; } - /*...*/}`, - `__fx.hoveringTooltip.display = function(mouseX, mouseY) { - var coordX = bL.gz(mouseX), coordY = bL.h1(mouseY), - coord = bL.f7(coordX, coordY), point = bL.eZ(coord); - // if (coordX < 0 || coordY < 0) return; - if (bL.isInMapBounds(coordX, coordY)) (function(lK, lL, eN) { - a5D(lK, lL, eN) - }(mouseX, mouseY, point)) - }`) - modUtils.waitForMinification(() => applyPatches(modUtils)) } //export const requiredVariables = ["game", "playerId", "playerData", "rawPlayerNames", "gIsSingleplayer", "playerTerritories"]; @@ -309,11 +286,6 @@ canvas.font=aY.g0.g1(1,fontSize),canvas.fillStyle="rgba("+gR+","+tD+","+hj+",0.6 `this.uI=function(username){var uK,uJ=username.indexOf("[");return!(uJ<0)&&1<(uK=username.indexOf("]"))-uJ&&uK-uJ<=8?username.substring(uJ+1,uK).toUpperCase().trim():null}, __fx.leaderboardFilter.parseClanFromPlayerName = this.uI;`); } - { // Hovering tooltip - replaceRawCode("aK.nH=(window.devicePixelRatio||1)*aEr,", - `aK.nH = (window.devicePixelRatio || 1) * aEr, __fx.hoveringTooltip.canvasPixelScale = aK.nH,`) - } - // Detailed team pie chart percentage replaceRawCode(`qr=Math.floor(100*f0+.5)+"%"`, `qr = (__fx.settings.detailedTeamPercentage ? (100*f0).toFixed(2) : Math.floor(100*f0+.5)) + "%"`) diff --git a/src/hoveringTooltip.js b/src/hoveringTooltip.js index 5a4e8a9..abb5cb2 100644 --- a/src/hoveringTooltip.js +++ b/src/hoveringTooltip.js @@ -4,6 +4,7 @@ import { getVar } from "./gameInterface.js"; const hoveringTooltip = new (function() { let recentlyShown = false; this.display = () => {}; // this gets populated by the modified game script + this.active = false; this.canvasPixelScale = 1; function handler(e) { if (!getSettings().hoveringTooltip || !getVar("gameState") || recentlyShown) return; @@ -21,7 +22,9 @@ const hoveringTooltip = new (function() { recentlyShown = true; try { + this.active = true; this.display(this.canvasPixelScale * x, this.canvasPixelScale * y); + this.active = false; } catch (e) { console.error(e) } // for better performance, reduce the tooltip display frequency to no more than once every 100 ms setTimeout(() => recentlyShown = false, 100);