Fix Editor scroll zoom sensitivity - Bonk.io

Fixes scrolling in the editor causing zoom to go ZOOOM (ie when using a trackpad)

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Fix Editor scroll zoom sensitivity - Bonk.io
// @description  Fixes scrolling in the editor causing zoom to go ZOOOM (ie when using a trackpad)
// @author       Excigma
// @namespace    https://github.com/Excigma
// @license      GPL-3.0
// @version      0.0.2
// @match        https://bonk.io/gameframe-release.html
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(() => {
	const REVERSE_SCROLL = false;
	const SENSITIVITY = 0.02;

	const mapeditor_midbox_previewcontainer = document.querySelector("#mapeditor_midbox_previewcontainer");
	const classic_mid_customgame = document.getElementById("classic_mid_customgame");

	// This requires the newest version of kklee
	classic_mid_customgame.addEventListener("click", () => {
		if (!window.kklee) {
			alert("Editor scroll zoom tweaks requires kklee to be installed.\nMake sure you have kklee installed.\nIf you have it installed:\n- either kklee failed to load\n- or kklee changed its code and is no longer compatible");
		} else {
			let scroll_amount = 0;
			mapeditor_midbox_previewcontainer.addEventListener("wheel", evt => {
				scroll_amount += evt.deltaY * SENSITIVITY * (REVERSE_SCROLL ? 1 : -1);

				// Once a threshold is reached...
				if (scroll_amount > 1) {
					// Zoom in
					window.kklee.stageRenderer.scaleStage(1.25);
					window.kklee.updateRenderer();
					scroll_amount = 0;
				} else if (scroll_amount < -1) {
					// Zoom out
					window.kklee.stageRenderer.scaleStage(0.8);
					window.kklee.updateRenderer();
					scroll_amount = 0;
				}
		
				// Don't let bonk.io handle the scroll event
				evt.stopImmediatePropagation();
				evt.preventDefault();
			});
		}
	});
})();