Last active
September 13, 2024 01:42
-
-
Save nabbynz/6d8d989aaa1d3c281aaf04b82063a4d8 to your computer and use it in GitHub Desktop.
Respawn_Pizzas_(Replays_Edition).user.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Respawn Pizzas (Replays Edition) | |
// @description Replace Respawn Warnings by a "growing pizza animation" to know exactly when the respawn happens! | |
// @author Ko (modified by nabby) | |
// @version 2.2.2 | |
// @match https://*.koalabeast.com/game | |
// @match https://*.koalabeast.com/game?* | |
// @updateURL https://gist.github.com/nabbynz/6d8d989aaa1d3c281aaf04b82063a4d8/raw/Respawn_Pizzas_(Replays_Edition).user.js | |
// @downloadURL https://gist.github.com/nabbynz/6d8d989aaa1d3c281aaf04b82063a4d8/raw/Respawn_Pizzas_(Replays_Edition).user.js | |
// @grant none | |
// ==/UserScript== | |
console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')'); | |
'use strict'; | |
/* eslint-env jquery */ | |
/* globals tagpro, tagproConfig, PIXI */ | |
/* eslint-disable no-multi-spaces */ | |
const slices = 30; // values like: 3, 6, 10, 20, 30 or 60 work well | |
tagpro.ready(function() { | |
const elements = tagpro.renderer.dynamicSprites; | |
const start = 1.5 * Math.PI; // The first slice should be at the top | |
const tau = Math.PI * 2; | |
const slice_size = tau / slices; | |
// Listen for respawn warnings... | |
tagpro.socket.on('mapupdate', function(mapupdates) { | |
if (!Array.isArray(mapupdates)) { | |
mapupdates = [mapupdates]; | |
} | |
if (document.visibilityState !== 'visible') { | |
return; | |
} | |
for (let mapupdate of mapupdates) { | |
let element = elements && elements[mapupdate.x] && elements[mapupdate.x][mapupdate.y]; | |
if (!element) { | |
continue; | |
} | |
if (/.\d1$/.test(String(mapupdate.v))) { // .test should be slightly faster (matches #.#1) | |
// Bake a new pizza if it's the first time | |
if (!element.pizza) { | |
element.pizza = new PIXI.Graphics(); | |
element.pizza_ix = element.x / 40; // index in tr.dynamicSprites | |
element.pizza_iy = element.y / 40; | |
element.pizza.center = element.width / 2; | |
element.addChild(element.pizza); | |
} | |
// Reset the pizza | |
element.mask = element.pizza; | |
element.slices = 0; | |
element.delta = 3000 / (slices + 1) / (tagpro.replaySpeed || 1); // takes into account replays speed | |
element.lastDraw = performance.now(); | |
// Let it grow! | |
requestAnimationFrame(() => { | |
updatePizza(element); | |
}); | |
} else if (element.pizza) { | |
element.pizza.destroy(); | |
element.pizza = null; | |
element.destroy(); | |
element = null; | |
} | |
} | |
}); | |
function updatePizza(element) { // Adds a slice | |
if (!element || !element.pizza || !element.pizza.visible) { | |
return; | |
} else if (tagpro.replayPaused) { // replays can cause fps stutter due to multiple updates when skipping | |
element.lastDraw = performance.now(); | |
requestAnimationFrame(() => { | |
updatePizza(element); | |
}); | |
return; | |
} else if (element.pizza && !elements[element.pizza_ix][element.pizza_iy].pizza) { | |
// remove pizza if the actual sprite (in dynamicSprites) has changed | |
element.pizza.destroy(); | |
element.pizza = null; | |
element.destroy(); | |
element = null; | |
return; | |
} | |
requestAnimationFrame(() => { | |
updatePizza(element); | |
}); | |
// Draw the pizza! | |
if (element.lastDraw < performance.now() - element.delta && tagpro.state !== 2) { | |
const portion = ++element.slices * slice_size; | |
if (portion < tau) { | |
element.pizza.clear().beginFill().moveTo(element.pizza.center, element.pizza.center).arc(element.pizza.center, element.pizza.center, 16, start, start + portion); | |
element.lastDraw = performance.now(); | |
} else { | |
element.pizza.destroy(); | |
element.pizza = null; | |
element.destroy(); | |
element = null; | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment