From e714af6319d67556ed84084546a4962e5d2f1f68 Mon Sep 17 00:00:00 2001 From: Mnem42 <177770058+Mnem42@users.noreply.github.com> Date: Sun, 26 Oct 2025 20:38:30 +0000 Subject: [PATCH] Potential fix and reorganising Fix the mod sometimes failing to load if it loads before the relevant parts of the UI --- mods/zoom.js | 112 +++++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/mods/zoom.js b/mods/zoom.js index bd08a89d..a83fea4d 100644 --- a/mods/zoom.js +++ b/mods/zoom.js @@ -1,58 +1,5 @@ // IIFE because paranoid (() => { - let canvas_div = document.getElementById("canvasDiv") - - // Be more granular at higher zoom levels - const speed_a = () => zoom_level > 3 ? 5 : 10 - const speed_b = () => zoom_level > 3 ? 10 : 20 - - keybinds["9"] = () => handle_zoom("in") - keybinds["0"] = () => handle_zoom("out") - - keybinds["w"] = () => handle_pan("up", speed_a()) - keybinds["a"] = () => handle_pan("left", speed_a()) - keybinds["s"] = () => handle_pan("down", speed_a()) - keybinds["d"] = () => handle_pan("right", speed_a()) - - keybinds["W"] = () => handle_pan("up", speed_b()) - keybinds["A"] = () => handle_pan("left", speed_b()) - keybinds["S"] = () => handle_pan("down", speed_b()) - keybinds["D"] = () => handle_pan("right", speed_b()) - - const controls_table = document.getElementById("controlsTable").lastElementChild - - controls_table.insertAdjacentHTML("beforeBegin",` - - Zoom in/out - - 9/ - 0 - - - - Pan - - W - A - S - D - - - - Pan (fast) - - Shift + - W - A - S - D - - - `) - - const zoom_data_div = document.createElement("div") - document.getElementById("logDiv").appendChild(zoom_data_div) - const zoom_levels = [ 0.5, 1, @@ -117,6 +64,60 @@ zoom_data_div.innerText += `Pan : ${x_pan}, ${y_pan}` } + function patch_keybinds(){ + // Be more granular at higher zoom levels + const speed_a = () => zoom_level > 3 ? 5 : 10 + const speed_b = () => zoom_level > 3 ? 10 : 20 + + keybinds["9"] = () => handle_zoom("in") + keybinds["0"] = () => handle_zoom("out") + + keybinds["w"] = () => handle_pan("up", speed_a()) + keybinds["a"] = () => handle_pan("left", speed_a()) + keybinds["s"] = () => handle_pan("down", speed_a()) + keybinds["d"] = () => handle_pan("right", speed_a()) + + keybinds["W"] = () => handle_pan("up", speed_b()) + keybinds["A"] = () => handle_pan("left", speed_b()) + keybinds["S"] = () => handle_pan("down", speed_b()) + keybinds["D"] = () => handle_pan("right", speed_b()) + } + + function patch_ui(){ + const zoom_data_div = document.createElement("div") + document.getElementById("logDiv").appendChild(zoom_data_div) + + const controls_table = document.getElementById("controlsTable").lastElementChild + controls_table.insertAdjacentHTML("beforeBegin",` + + Zoom in/out + + 9/ + 0 + + + + Pan + + W + A + S + D + + + + Pan (fast) + + Shift + + W + A + S + D + + + `) + } + // Redefine to give correct numbers when zoomed window.getMousePos = (canvas, evt) => { if (evt.touches) { @@ -139,4 +140,9 @@ window.zoom_level = 1 rescale() }) + + runAfterLoad(() => { + patch_keybinds() + patch_ui() + }) })()