Skip to content

Commit

Permalink
Efficiency improvement
Browse files Browse the repository at this point in the history
Edited code so that updates on 'next turn' and 'end combat' are pushed as a single update rather than a series of updates.
  • Loading branch information
Sk1mble committed Jan 8, 2021
1 parent 8c4c5b0 commit de2334b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
33 changes: 29 additions & 4 deletions Popcorn.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,14 @@ class PopcornViewer extends Application {
if (tokenId != undefined) {
foundToken = tokens.find(val => {return val.id == tokenId;})
}
if (foundToken == undefined){
return;
}
if ((combatants[i].hidden || foundToken.data.hidden) && !game.user.isGM){
continue;
}

let hasActed = true;
let hasActed = undefined;
if (foundToken != undefined) {
// There is no token for this actor in the conflict; it probably means the token has been deleted from the scene. We need to ignore this actor. Easiest way to do that is to leave hasActed as true.
hasActed = foundToken.getFlag("world", "popcornHasActed");
Expand Down Expand Up @@ -153,14 +156,37 @@ class PopcornViewer extends Application {

myContents += `<p><button type="button" onclick='
let actors = canvas.tokens.placeables;
actors.forEach(actor =>{actor.setFlag("world","popcornHasActed",false)});
let updates = actors.map(actor => {
let update = {};
console.log(actor)
update._id = actor.id;
update.flags = {
"world":
{
"popcornHasActed":false
}
}
return update;
})
game.scenes.viewed.updateEmbeddedEntity("Token", updates);
game.combat.nextRound();
ChatMessage.create({content: "${s_newexchange}", speaker: { alias: "${s_game}"}})
'>${s_nextexchange}</button></p>`

myContents += `<p><button type="button" onclick='
let actors = canvas.tokens.placeables;
actors.forEach(actor =>{actor.setFlag("world","popcornHasActed",false)});
let updates = actors.map(actor => {
let update = {};
update._id = actor.id;
update.flags = {
"world":
{
"popcornHasActed":false
}
}
return update;
})
game.scenes.viewed.updateEmbeddedEntity("Token", updates);
game.combat.endCombat();
ChatMessage.create({content: "${s_endingconflict}", speaker: { alias: "${s_game}"}})
'>${s_endconflict}</button></p>`
Expand All @@ -173,7 +199,6 @@ class PopcornViewer extends Application {
}
}


Hooks.on('getSceneControlButtons', (hudButtons) => {
PopcornViewer.prepareButtons(hudButtons);
})
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "A small module that creates a pop-out window for running games that use popcorn/elective action order initiative.",
"author": "Richard Bellingham (Skimble)",
"scripts": ["./Popcorn.js"],
"version": "1.2.0",
"version": "1.2.1",
"minimumCoreVersion": "0.6.0",
"compatibleCoreVersion": "0.7.7",
"socket": true,
Expand All @@ -18,6 +18,6 @@
"name": "Español",
"path": "languages/es.json"
}],
"download": "https://github.com/Sk1mble/Popcorn/archive/V1.2.0.zip",
"download": "https://github.com/Sk1mble/Popcorn/archive/V1.2.1.zip",
"manifest": "https://raw.githubusercontent.com/Sk1mble/Popcorn/master/module.json"
}

0 comments on commit de2334b

Please sign in to comment.