Skip to content

Commit

Permalink
Merge pull request #57 from kckaiwei/swade-bug-fix
Browse files Browse the repository at this point in the history
[BUG] SWADE new round bug fix
  • Loading branch information
kckaiwei authored May 24, 2021
2 parents b64a7fe + 31b39b4 commit 98e089a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.7.5
- Fixed SWADE integration (via hook workaround)

# 2.7.4
- Fixed marker sizing for non-square tokens on grid/gridless maps
- Added on deck marker option (off by default)
Expand Down
2 changes: 1 addition & 1 deletion dist/scripts/turnmarker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/scripts/turnmarker.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion dist/templates/updateWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ <h2>Issues or Ideas?</h2>

<h2>Want to support development?</h2>
<p>There are lots of ways to support development, <a
href="https://github.com/kckaiwei/TurnMarker-alt#support-development">check here</a> for more info.</h2>
href="https://github.com/kckaiwei/TurnMarker-alt#support-development">check here</a> for more info.
</p>

<h1>Important Changes</h1>
<p>Below are just some of the changes to the module that should be called out. The full changelog is also available
Expand Down
80 changes: 48 additions & 32 deletions src/scripts/turnmarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Hooks.once('ready', () => {
}
}
});

});

Hooks.on('canvasReady', () => {
Expand Down Expand Up @@ -90,36 +91,17 @@ Hooks.on('updateCombat', async (combat, update) => {
if (!combat.started) {
await Marker.deleteStartMarker();
}
if (combat.combatant) {
let nextTurn = getNextTurn(combat);
if (update && lastTurn != combat.combatant._id && game.user.isGM && game.userId == firstGM()) {
lastTurn = combat.combatant._id;
if (combat && combat.combatant && combat.started) {
await Marker.placeStartMarker(combat.combatant.token._id);
createCombatDeckMarker(combat, nextTurn);
let tile = canvas.tiles.placeables.find(t => t.data.flags.turnMarker == true);
await Marker.placeTurnMarker(combat.combatant.token._id, (tile && tile.id) || undefined);
if (Settings.shouldAnnounceTurns() && !combat.combatant.hidden) {
switch (Settings.getAnnounceActors()) {
case 0:
Chatter.sendTurnMessage(combat.combatant);
break;
case 1:
if (combat.combatant.actor.hasPlayerOwner) {
Chatter.sendTurnMessage(combat.combatant);
}
break;
case 2:
if (!combat.combatant.actor.hasPlayerOwner) {
Chatter.sendTurnMessage(combat.combatant);
}
break;
case 3:
Chatter.sendTurnMessage(combat.combatant, true);
}
}
}
}
// SWADE has a special initiative
if (game.system.id != "swade") {
handleCombatUpdate(combat, update);
}
});

// For SWADE, need to reget active player after each round, but no better hook is fired after initiative shuffle
Hooks.on("renderCombatTracker", async (combatTracker, update) => {
console.log(combatTracker);
if (game.system.id == "swade") {
handleCombatUpdate(combatTracker.combat, update)
}
});

Expand All @@ -141,12 +123,12 @@ Hooks.on('updateToken', async (scene, updateToken, updateData) => {
if ((updateData.x || updateData.y || updateData.width || updateData.height || updateData.hidden) &&
(game && game.combat) &&
game.user.isGM && game.combat) {
let currentTurn = game.combat.turn
let currentTurn = game.combat.turn;
let nextTurn = currentTurn + 1;
if (nextTurn >= game.combat.turns.length) {
nextTurn = 0;
}
let nextToken = game.combat.turns[nextTurn].token
let nextToken = game.combat.turns[nextTurn].token;
await Marker.moveMarkerToToken(nextToken._id, deckTile.id, "deckmarker");
deckTile.zIndex = Math.max(...canvas.tiles.placeables.map(o => o.zIndex)) + 1;
deckTile.parent.sortChildren();
Expand Down Expand Up @@ -224,6 +206,40 @@ async function createCombatDeckMarker(combat, nextTurn) {
}
}

async function handleCombatUpdate(combat, update) {
if (combat.combatant) {
let nextTurn = getNextTurn(combat);
if (update && lastTurn != combat.combatant._id && game.user.isGM && game.userId == firstGM()) {
lastTurn = combat.combatant._id;
if (combat && combat.combatant && combat.started) {
await Marker.placeStartMarker(combat.combatant.token._id);
createCombatDeckMarker(combat, nextTurn);
let tile = canvas.tiles.placeables.find(t => t.data.flags.turnMarker == true);
await Marker.placeTurnMarker(combat.combatant.token._id, (tile && tile.id) || undefined);
if (Settings.shouldAnnounceTurns() && !combat.combatant.hidden) {
switch (Settings.getAnnounceActors()) {
case 0:
Chatter.sendTurnMessage(combat.combatant);
break;
case 1:
if (combat.combatant.actor.hasPlayerOwner) {
Chatter.sendTurnMessage(combat.combatant);
}
break;
case 2:
if (!combat.combatant.actor.hasPlayerOwner) {
Chatter.sendTurnMessage(combat.combatant);
}
break;
case 3:
Chatter.sendTurnMessage(combat.combatant, true);
}
}
}
}
}
}

Hooks.on('updateTile', (entity, data, options, userId) => {
if (data.flags.turnMarker || data.flags.startMarker || data.flags.deckMarker) {
const tile = canvas.tiles.placeables.find(t => t.id === data._id);
Expand Down

0 comments on commit 98e089a

Please # to comment.