Last active
September 22, 2019 02:17
-
-
Save nabbynz/f158da69f05e510b5922df30850a83d4 to your computer and use it in GitHub Desktop.
TagPro Time On Ball
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 Time On Ball | |
// @version 0.5.2 | |
// @include *://tagpro*.koalabeast.com/game | |
// @include http://tagpro-maptest.koalabeast.com:* | |
// @updateURL https://gist.github.com/nabbynz/f158da69f05e510b5922df30850a83d4/raw/Time_On_Ball.user.js | |
// @downloadURL https://gist.github.com/nabbynz/f158da69f05e510b5922df30850a83d4/raw/Time_On_Ball.user.js | |
// @grant none | |
// @author ballparts & Flail | |
// ==/UserScript== | |
console.log('START: ' + GM_info.script.name + ' (v' + GM_info.script.version + ' by ' + GM_info.script.author + ')'); | |
//////////////////////////// | |
// USER DEFINED VARIABLES // | |
//////////////////////////// | |
// Color of text - can be hex value or color name (e.g., "white") | |
const TEXT_COLOR = "white"; | |
// Opacity of text - 0 is transparent, 1 is opaque | |
const TEXT_OPACITY = 0.7; | |
// Size of the timer text font in pixels | |
const TEXT_SIZE = 15; | |
// Whether to rotate with the player. | |
const ROTATE = true; | |
//////////////////////////////// | |
// END USER DEFINED VARIABLES // | |
//////////////////////////////// | |
// Wait until the tagpro object exists, and add the function to tagpro.ready | |
function addToTagproReady(fn) { | |
// Make sure the tagpro object exists. | |
if (typeof tagpro !== "undefined") { | |
tagpro.ready(fn); | |
} else { | |
// If not ready, try again after a short delay. | |
setTimeout(function() { | |
addToTagproReady(fn); | |
}, 0); | |
} | |
} | |
function waitForId(fn) { | |
if (typeof tagpro !== "undefined" && tagpro.players && tagpro.playerId && tagpro.players[tagpro.playerId].sprites && tagpro.players[tagpro.playerId].sprites.actualBall) { | |
fn(); | |
} else { | |
setTimeout(function() { | |
waitForId(fn); | |
}); | |
} | |
} | |
function makeText() { | |
let text = new PIXI.Text("00", { | |
fontFamily: "Arial", | |
fontSize: TEXT_SIZE + "pt", | |
fontWight: "bold", | |
fill: TEXT_COLOR, | |
stroke: "#000000", | |
strokeThickness: 3, | |
}); | |
text.anchor.x = 0.5; | |
text.anchor.y = 0.5; | |
if (!ROTATE) { | |
text.x = 20; | |
text.y = 20; | |
} | |
text.alpha = TEXT_OPACITY; | |
return text; | |
} | |
addToTagproReady(function() { | |
waitForId(function() { | |
let stdUpdate = tagpro.ui.update; | |
let prevSeconds; | |
let text = makeText(); | |
setTimeout(function() { //let's wait for a bit before adding the sprite... | |
if (ROTATE) tagpro.players[tagpro.playerId].sprites.actualBall.addChild(text); | |
else tagpro.players[tagpro.playerId].sprites.ball.addChild(text); | |
tagpro.ui.update = function() { //why use ui update? | |
stdUpdate.apply(null, arguments); | |
let millis = Math.max(0, tagpro.gameEndsAt - Date.now()); | |
let seconds = Math.floor((millis / 1000)) % 60; | |
if (seconds !== prevSeconds) { //only update if the timer has changed... | |
text.text = (seconds > 9 ? seconds : '0' + seconds); | |
prevSeconds = seconds; | |
} | |
}; | |
}, 800); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment