diff --git a/Changelog.txt b/Changelog.txt
new file mode 100644
index 0000000..81b190d
--- /dev/null
+++ b/Changelog.txt
@@ -0,0 +1,5 @@
+1.1.2
+0.8.6 functionality
+
+1.1.1
+Improved the behaviour of hook generation so only one set of hooks will ever be generated for Popcorn.
diff --git a/Popcorn.js b/Popcorn.js
index 48d8220..110d728 100644
--- a/Popcorn.js
+++ b/Popcorn.js
@@ -1,5 +1,5 @@
class PopcornViewer extends Application {
- super(options){
+ super(options) {
//console.log("Super called");
}
@@ -7,135 +7,135 @@ class PopcornViewer extends Application {
super.activateListeners(html);
const myButton = html.find("button[name='act']");
myButton.on("click", event => this._onClickButton(event, html));
- }
-
+ }
+
async _onClickButton(event, html) {
//console.log("Event target id "+event.target.id);
const tokenId = event.target.id;
const token = canvas.tokens.get(tokenId);
-
- await token.setFlag("world","popcornHasActed",true);
+
+
+ await token.setFlag("world", "popcornHasActed", true);
await ChatMessage.create({
content: `${token.name} is acting now.`,
speaker:
- {
- alias: "Game: "
- }
- });
- game.socket.emit("module.Popcorn",{"HasActed":true});
+ {
+ alias: "Game: "
+ }
+ });
+ game.socket.emit("module.Popcorn", { "HasActed": true });
this.render(false);
}
- static prepareButtons(hudButtons){
- let hud = hudButtons.find(val => {return val.name == "token";})
-
- if (hud){
- hud.tools.push({
- name:"PopcornInitiative",
- title:"Pop-out popcorn initiative tracker",
- icon:"fas fa-bolt",
- onClick: ()=> {
- const delay = 200;
-
- let opt=Dialog.defaultOptions;
- opt.resizable=true;
- opt.title="Popcorn Initiative Tracker";
- opt.width=400;
- opt.height=500;
- opt.minimizable=true;
-
- var viewer;
- viewer = new PopcornViewer(opt);
- viewer.render(true);
-
- game.system.popcorn = viewer;
- game.socket.on("module.Popcorn", data => viewer.render(false))
- },
- button:true
- });
+ static prepareButtons(hudButtons) {
+ let hud = hudButtons.find(val => { return val.name == "token"; })
+
+ if (hud) {
+ hud.tools.push({
+ name: "PopcornInitiative",
+ title: "Pop-out popcorn initiative tracker",
+ icon: "fas fa-bolt",
+ onClick: () => {
+ const delay = 200;
+
+ let opt = Dialog.defaultOptions;
+ opt.resizable = true;
+ opt.title = "Popcorn Initiative Tracker";
+ opt.width = 400;
+ opt.height = 500;
+ opt.minimizable = true;
+
+ var viewer;
+ viewer = new PopcornViewer(opt);
+ viewer.render(true);
+
+ game.system.popcorn = viewer;
+ game.socket.on("module.Popcorn", data => viewer.render(false))
+ },
+ button: true
+ });
}
}
- getData (){
- let content={content:`${this.preparePopcorn()}`}
+ getData() {
+ let content = { content: `${this.preparePopcorn()}` }
return content;
-}
+ }
- preparePopcorn(){
+ preparePopcorn() {
//console.log("PreparePopcorn called");
//Get a list of the active combatants
- if (game.combat!= null){
- var combatants = game.combat.combatants;
- var tokens = canvas.tokens.placeables;
- var tokenId;
- var viewer = viewer;
-
- let table=`
Exchange ${game.combat.round}
`;
-
- //Create a header row
- let rows;
- if (game.user.isGM){
- rows=[`
Character
Act Now?
`];
- } else {
- rows = [`
Character
`];
+ if (game.combat != null) {
+ var combatants = game.combat.combatants;
+ var tokens = canvas.tokens.placeables;
+ var tokenId;
+ var viewer = viewer;
+
+ let table = `
Exchange ${game.combat.round}
`;
+
+ //Create a header row
+ let rows;
+ if (game.user.isGM) {
+ rows = [`
Character
Act Now?
`];
+ } else {
+ rows = [`
Character
`];
+ }
+ //Create a row for each combatant with the correct flag
+ for (const [key, combatant] of combatants.entries()) {
+ if (combatant.token != undefined) {
+ tokenId = combatant.token.id;//This is the representative of a token in the combatants list.
}
- //Create a row for each combatant with the correct flag
- for(var i=0;i {return val.id == tokenId;})
- }
- if ((combatants[i].hidden || foundToken.data.hidden) && !game.user.isGM){
- continue;
- }
-
- let hasActed = true;
-
- 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");
- }
-
- if (game.user.isGM) {
- if (hasActed == undefined || hasActed == false){
- rows.push(`
+ let foundToken = undefined;
+
+ if (tokenId != undefined) {
+ foundToken = tokens.find(val => { return val.id == tokenId; })
+ }
+ if ((combatant.hidden || foundToken.data.hidden) && !game.user.isGM) {
+ continue;
+ }
+
+ let hasActed = true;
+
+ 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 = combatant.token.getFlag("world", "popcornHasActed");
+ }
+
+ if (game.user.isGM) {
+ if (hasActed == undefined || hasActed == false) {
+ rows.push(`
" }
+ }
// This function prepares the contents of the popcorn initiative viewer
// Display the current exchange number
@@ -146,16 +146,15 @@ class PopcornViewer extends Application {
}
-Hooks.on('getSceneControlButtons', function(hudButtons)
-{
- PopcornViewer.prepareButtons(hudButtons);
+Hooks.on('getSceneControlButtons', function (hudButtons) {
+ PopcornViewer.prepareButtons(hudButtons);
})
Hooks.on('renderCombatTracker', () => {
- if (game.system.popcorn != undefined) setTimeout(function(){game.system.popcorn.render(false);},50);
+ if (game.system.popcorn != undefined) setTimeout(function () { game.system.popcorn.render(false); }, 50);
})
Hooks.on('updateToken', (scene, token, data) => {
-if (data.hidden!=undefined){
- if (game.system.popcorn != undefined) setTimeout(function(){game.system.popcorn.render(false);},50);
-}
+ if (data.hidden != undefined) {
+ if (game.system.popcorn != undefined) setTimeout(function () { game.system.popcorn.render(false); }, 50);
+ }
})
\ No newline at end of file
diff --git a/Popcorn/1.1.0 Changelog.txt b/Popcorn/1.1.1 Changelog.txt
similarity index 97%
rename from Popcorn/1.1.0 Changelog.txt
rename to Popcorn/1.1.1 Changelog.txt
index 9ae1ae1..d4d17e9 100644
--- a/Popcorn/1.1.0 Changelog.txt
+++ b/Popcorn/1.1.1 Changelog.txt
@@ -1,3 +1,3 @@
-Will now not display a token in the Popcorn initiative tracker to players if:
-1) The token is hidden
-2) The combatant is hidden.
+Will now not display a token in the Popcorn initiative tracker to players if:
+1) The token is hidden
+2) The combatant is hidden.
diff --git a/Popcorn/Popcorn.js b/Popcorn/Popcorn.js
index 0bbfe7c..110d728 100644
--- a/Popcorn/Popcorn.js
+++ b/Popcorn/Popcorn.js
@@ -1,5 +1,5 @@
class PopcornViewer extends Application {
- super(options){
+ super(options) {
//console.log("Super called");
}
@@ -7,142 +7,135 @@ class PopcornViewer extends Application {
super.activateListeners(html);
const myButton = html.find("button[name='act']");
myButton.on("click", event => this._onClickButton(event, html));
- }
-
+ }
+
async _onClickButton(event, html) {
//console.log("Event target id "+event.target.id);
const tokenId = event.target.id;
const token = canvas.tokens.get(tokenId);
-
- await token.setFlag("world","popcornHasActed",true);
+
+
+ await token.setFlag("world", "popcornHasActed", true);
await ChatMessage.create({
- content: `${token.name} has taken their action for the exchange.`,
+ content: `${token.name} is acting now.`,
speaker:
- {
- alias: "Game: "
- }
- });
- game.socket.emit("module.Popcorn",{"HasActed":true});
+ {
+ alias: "Game: "
+ }
+ });
+ game.socket.emit("module.Popcorn", { "HasActed": true });
this.render(false);
}
- static prepareButtons(hudButtons){
- let hud = hudButtons.find(val => {return val.name == "token";})
-
- if (hud){
- hud.tools.push({
- name:"PopcornInitiative",
- title:"Pop-out popcorn initiative tracker",
- icon:"fas fa-bolt",
- onClick: ()=> {
- const delay = 200;
-
- let opt=Dialog.defaultOptions;
- opt.resizable=true;
- opt.title="Popcorn Initiative Tracker";
- opt.width=400;
- opt.height=500;
- opt.minimizable=true;
-
- var viewer;
- viewer = new PopcornViewer(opt);
- viewer.render(true);
-
- Hooks.on('renderCombatTracker', () => {
- setTimeout(function(){viewer.render(false);},delay);
- })
- Hooks.on('updateToken', (scene, token, data) => {
- if (data.hidden!=undefined){
- setTimeout(function(){viewer.render(false);},delay);
- }
- })
- game.socket.on("module.Popcorn", data => viewer.render(false))
- },
- button:true
- });
+ static prepareButtons(hudButtons) {
+ let hud = hudButtons.find(val => { return val.name == "token"; })
+
+ if (hud) {
+ hud.tools.push({
+ name: "PopcornInitiative",
+ title: "Pop-out popcorn initiative tracker",
+ icon: "fas fa-bolt",
+ onClick: () => {
+ const delay = 200;
+
+ let opt = Dialog.defaultOptions;
+ opt.resizable = true;
+ opt.title = "Popcorn Initiative Tracker";
+ opt.width = 400;
+ opt.height = 500;
+ opt.minimizable = true;
+
+ var viewer;
+ viewer = new PopcornViewer(opt);
+ viewer.render(true);
+
+ game.system.popcorn = viewer;
+ game.socket.on("module.Popcorn", data => viewer.render(false))
+ },
+ button: true
+ });
}
}
- getData (){
- let content={content:`${this.preparePopcorn()}`}
+ getData() {
+ let content = { content: `${this.preparePopcorn()}` }
return content;
-}
+ }
- preparePopcorn(){
+ preparePopcorn() {
//console.log("PreparePopcorn called");
//Get a list of the active combatants
- if (game.combat!= null){
- var combatants = game.combat.combatants;
- var tokens = canvas.tokens.placeables;
- var tokenId;
- var viewer = viewer;
-
- let table=`
Exchange ${game.combat.round}
`;
-
- //Create a header row
- let rows;
- if (game.user.isGM){
- rows=[`
Character
Act Now?
`];
- } else {
- rows = [`
Character
`];
+ if (game.combat != null) {
+ var combatants = game.combat.combatants;
+ var tokens = canvas.tokens.placeables;
+ var tokenId;
+ var viewer = viewer;
+
+ let table = `
Exchange ${game.combat.round}
`;
+
+ //Create a header row
+ let rows;
+ if (game.user.isGM) {
+ rows = [`
Character
Act Now?
`];
+ } else {
+ rows = [`
Character
`];
+ }
+ //Create a row for each combatant with the correct flag
+ for (const [key, combatant] of combatants.entries()) {
+ if (combatant.token != undefined) {
+ tokenId = combatant.token.id;//This is the representative of a token in the combatants list.
}
- //Create a row for each combatant with the correct flag
- for(var i=0;i {return val.id == tokenId;})
- }
- if ((combatants[i].hidden || foundToken.data.hidden) && !game.user.isGM){
- continue;
- }
-
- let hasActed = true;
-
- 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");
- }
-
- if (game.user.isGM) {
- if (hasActed == undefined || hasActed == false){
- rows.push(`
+ let foundToken = undefined;
+
+ if (tokenId != undefined) {
+ foundToken = tokens.find(val => { return val.id == tokenId; })
+ }
+ if ((combatant.hidden || foundToken.data.hidden) && !game.user.isGM) {
+ continue;
+ }
+
+ let hasActed = true;
+
+ 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 = combatant.token.getFlag("world", "popcornHasActed");
+ }
+
+ if (game.user.isGM) {
+ if (hasActed == undefined || hasActed == false) {
+ rows.push(`