Skip to content

Instantly share code, notes, and snippets.

@xeqi
Created December 7, 2023 14:31
Show Gist options
  • Save xeqi/335f9971d8cf5abc9c4e8fa07ef76103 to your computer and use it in GitHub Desktop.
Save xeqi/335f9971d8cf5abc9c4e8fa07ef76103 to your computer and use it in GitHub Desktop.
Battle stats update macro
const enemyTokens = game.canvas.scene.tokens.filter(entry => entry.disposition == -1);
const enemyDrawings = [
// Name, Amount
["0HRRJvAy0DL9fZYj", "xOkLUlaf66MIWaEg"],
["fvEtY6HXxuWZwTaM", "3ZpYPphDlKP0qocJ"],
["BxYhCFss1Hxeubg1", "1cyj6HHCq1Dy5y9C"],
["0zVx7PfduwZbNqnj", "kkoOJOPxo6K8hIhV"],
].map(uis => uis.map(id => canvas.scene.drawings.get(id)));
var roster = {};
for(const token of enemyTokens){
const name = token.name
if(roster.hasOwnProperty(name)){
roster[name] += 1;
}
else{
roster[name] = 1;
}
}
let shown = 0;
for(const name of Object.keys(roster).sort()){
const ui = enemyDrawings[shown]
await ui[0].update({text: name, hidden: false});
await ui[1].update({text: roster[name], hidden: false});
shown++;
}
//Hide extra rows
for (; shown < enemyDrawings.length; shown++) {
for (let j = 0; j < enemyDrawings[shown].length; j++) {
await enemyDrawings[shown][j].update({hidden: true});
}
}
// Id's of Text name and number for enemies
const allys = game.canvas.scene.tokens.filter(entry => entry.disposition == 1).sort(e => -e.y).map(e => game.actors.get(e.actorId));
const allyDrawings = [
//name, hp, mp, ip, fp
["mXsd2I0LjMpyK9VP","XwELJvS8HLYpYdJQ","kmaZxgstoL1FJu0y","ASlTQvd7YXNjbbBZ","KBaSiPVrbOGIJRpP"],
["LTpN7Yx6zIszVCgx","DL29CQCvjMfewZ6c","X9RGOgBUXLODwdGZ","bkOPzkC9vMsGnv7h","Af5ZDPTe3R9Krp0Y"],
["WuCb3cC0taGHhE1o","GyyZWQPCJiVAKQoe","rLXwmewwJRdOPZMQ","Y8WAsJaDc8NLo87U","MM08yklUK5P9HnoY"],
["SK7R7OsicJxNSHCq","3AOd6Fyydr7GdKoY","iBAr7qQywOfjRPMP","0GcUU2lue2i3x73O","H6Ef5H8Nsu2VhzEh"],
].map(uis => uis.map(id => canvas.scene.drawings.get(id)));
shown = 0;
for(const ally of allys){
const ui = allyDrawings[shown]
await ui[0].update({text: ally.name, hidden: false});
await ui[1].update({text: `${ally.system.resources.hp.value} / ${ally.system.resources.hp.max}`, hidden: false});
await ui[2].update({text: `${ally.system.resources.mp.value} / ${ally.system.resources.mp.max}`, hidden: false});
await ui[3].update({text: `${ally.system.resources.ip.value} / ${ally.system.resources.ip.max}`, hidden: false});
await ui[4].update({text: ally.system.resources.fp.value, hidden: false});
shown++;
}
//Hide extra rows
for (; shown < allyDrawings.length; shown++) {
for (let j = 0; j < allyDrawings[shown].length; j++) {
await allyDrawings[shown][j].update({hidden: true});
}
}
await new Promise(r => setTimeout(r, 3000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment