Last active
August 29, 2015 14:24
-
-
Save chrahunt/bd9121105668122f1aca to your computer and use it in GitHub Desktop.
Place ABCD 123 icons on smirk.
This file contains hidden or 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 Smirk Helper | |
// @include http://tagpro-*.koalabeast.com:* | |
// @include http://maptest*.newcompte.fr:* | |
// @include http://tangent.jukejuice.com:* | |
// @author snaps | |
// @license MIT | |
// @version 0.1.0 | |
// ==/UserScript== | |
var points = { | |
blue: { | |
A: [1180, 380], | |
B: [1560, 440], | |
C: [1800, 480], | |
D: [1860, 680], | |
"1": [1080, 820], | |
"2": [1460, 780], | |
"3": [1620, 880] | |
} | |
}; | |
var TILE_SIZE = 40; | |
// Reflect across mid. | |
function hreflect(p) { | |
var w = tagpro.map.length * TILE_SIZE, | |
mid = w / 2; | |
var x = p[0], | |
y = p[1]; | |
if (x > mid) { | |
x = x - 2 * (x - mid); | |
} else if (x < mid) { | |
x = x + 2 * (mid - x); | |
} | |
return [x, y]; | |
} | |
function waitForReqs(fn) { | |
if (typeof tagpro !== "undefined" && | |
tagpro.renderer && | |
tagpro.renderer.layers.foreground && | |
tagpro.playerId && | |
tagpro.players[tagpro.playerId] && | |
tagpro.map) { | |
fn(); | |
} else { | |
setTimeout(function () { | |
waitForReqs(fn); | |
}, 50); | |
} | |
} | |
function Indicators(locs) { | |
this.container = new PIXI.DisplayObjectContainer(); | |
tagpro.renderer.layers.foreground.addChild(this.container); | |
this.g = new PIXI.Graphics(); | |
this.container.addChild(this.g); | |
for (var loc in locs) { | |
this.drawIndicator(loc, locs[loc]); | |
} | |
} | |
Indicators.prototype.drawIndicator = function(text, loc) { | |
var x = loc[0] + TILE_SIZE / 2, | |
y = loc[1] + TILE_SIZE / 2; | |
var t = this.makeText(); | |
t.setText(text); | |
t.x = x; | |
t.y = y; | |
this.container.addChild(t); | |
this.g.beginFill(0xffffff, 0.4); | |
this.g.drawCircle(x, y, TILE_SIZE / 2); | |
this.g.endFill(); | |
}; | |
/** | |
* Get text for overlaying on center of tiles. | |
* @param {string} [color="#FFFFFF"] - The fill color to use for the text. | |
* @return {PIXI.Text} - The created text. | |
*/ | |
Indicators.prototype.makeText = function() { | |
var text = new PIXI.Text("", { | |
font: "bold 10pt Arial", | |
fill: "#FFFFFF", | |
stroke: "#000000", | |
strokeThickness: 3, | |
align: "center" | |
}); | |
text.anchor = new PIXI.Point(0.5, 0.5); | |
text.visible = true; | |
return text; | |
}; | |
Indicators.prototype.show = function() { | |
this.container.visible = true; | |
}; | |
Indicators.prototype.hide = function() { | |
this.container.visible = false; | |
}; | |
waitForReqs(function () { | |
// Reflect points. | |
var red = {}; | |
for (var i in points.blue) { | |
red[i] = hreflect(points.blue[i]); | |
} | |
points.red = red; | |
var indicators = { | |
red: new Indicators(points.red), | |
blue: new Indicators(points.blue) | |
}; | |
function updateShowing(team) { | |
if (team === 1) { | |
indicators.red.show(); | |
indicators.blue.hide(); | |
} else { | |
indicators.blue.show(); | |
indicators.red.hide(); | |
} | |
} | |
tagpro.socket.on('p', function (updates) { | |
updates = updates.u || updates; | |
updates.forEach(function (update) { | |
var id = update.id; | |
if (id === tagpro.playerId && update.team) { | |
updateShowing(update.team); | |
} | |
}); | |
}); | |
// Initial setting. | |
var player = tagpro.players[tagpro.playerId]; | |
updateShowing(player.team); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment