on("change:campaign:turnorder", function(obj, prev) {
if (!Campaign().get("turnorder")) return;
var turn_order = JSON.parse(Campaign().get("turnorder"));
if (!turn_order.length) return;
if (!turn_order[0].id == -1) return;
if (typeof turn_order[0].pr == "string") {
if (turn_order[0].pr.substring(0, 5) == "Round") {
var RoundTracker = turn_order[0].pr;
var CurrentRound = parseInt(RoundTracker.substring(5));
turn_order[0].pr = "Round " + (CurrentRound + 1);
Campaign().set({turnorder: JSON.stringify(turn_order)});
return;
}
}
var current_token = getObj("graphic", turn_order[0].id);
var initiative_highlighter = findObjs({name: "InitiativeHighlight", pageid: current_token.get("pageid")}, {caseInsensitive: true})[0];
if (initiative_highlighter == undefined) {
sendChat("ERROR", "/w gm Cannot find an initiative highlight token on this page.");
return;
}
if (initiative_highlighter.get("layer") == "gmlayer" && current_token.get("layer") != "gmlayer") {
initiative_highlighter.set({
"top": current_token.get("top"),
"left": current_token.get("left"),
"height": current_token.get("height"),
"width": current_token.get("width")
});
setTimeout(function() {
initiative_highlighter.set({
"layer": current_token.get("layer")
});
}, 500);
} else {
initiative_highlighter.set({
"layer": current_token.get("layer"),
"top": current_token.get("top"),
"left": current_token.get("left"),
"height": current_token.get("height"),
"width": current_token.get("width")
});
}
toFront(current_token);
});