Create libpixeltracking.js

This commit is contained in:
MollTheCoder 2023-01-16 18:10:17 -05:00 committed by GitHub
parent 485b5ca561
commit 1d67b7319a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 0 deletions

29
mods/libpixeltracking.js Normal file
View File

@ -0,0 +1,29 @@
enabledMods.includes("mods/libpacman-v1.js") || (enabledMods.push("mods/libpacman-v1.js"), localStorage.setItem("enabledMods", JSON.stringify(enabledMods)), location.reload());
let __trackedPixels = [];
let __oldCoords = [];
function subscribePixel(x, y, callback) {
__trackedPixels.push({ pixel: pixelMap[x][y], callback, update: false });
__oldCoords.push({ x, y });
}
requireMods(["mods/libhooktick.js"], () => {
everyTick(() => {
__trackedPixels.forEach((pixel, index) => {
let difference = [0, 0];
pixel.update = false;
if (pixel.pixel.x !== __oldCoords[index].x) {
difference[0] = Math.abs(__oldCoords[index].x-pixel.pixel.x);
__oldCoords[index].x = pixel.pixel.x;
pixel.update = true;
}
if(pixel.pixel.y !== __oldCoords[index].y){
difference[1] = Math.abs(__oldCoords[index].y-pixel.pixel.y);
__oldCoords[index].y = pixel.pixel.y;
pixel.update = true;
}
if(pixel.update){
pixel.callback(pixel.pixel, difference[0], difference[1]);
}
});
});
});