Skip to content

Commit

Permalink
Merge pull request #66 from kckaiwei/0.8+compatibility
Browse files Browse the repository at this point in the history
0.8+compatibility
  • Loading branch information
kckaiwei authored Jun 2, 2021
2 parents 725d360 + 8c02d1c commit fe60e3f
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 77 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 2.8.0
- Add compatibility with 0.8.6

# 2.7.5
- Fixed SWADE integration (via hook workaround)

Expand Down
10 changes: 5 additions & 5 deletions src/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"title": "Turn Marker",
"description": "Displays a (optionally animated) marker on the token who's active turn it is. Originally by Brunhine",
"author": "kckaiwei",
"version": "2.7.4",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.9",
"version": "2.8.0",
"minimumCoreVersion": "0.8.0",
"compatibleCoreVersion": "0.8.6",
"manifestPlusVersion": "1.0.0",
"esmodules": [
"scripts/turnmarker.js"
Expand Down Expand Up @@ -56,6 +56,6 @@
}
],
"url": "https://github.com/kckaiwei/TurnMarker-alt",
"manifest": "https://raw.githubusercontent.com/kckaiwei/TurnMarker-alt/v2.7.4/src/module.json",
"download": "https://github.com/kckaiwei/TurnMarker-alt/releases/download/v2.7.4/turnmarker.zip"
"manifest": "https://raw.githubusercontent.com/kckaiwei/TurnMarker-alt/v2.8.0/src/module.json",
"download": "https://github.com/kckaiwei/TurnMarker-alt/releases/download/v2.8.0/turnmarker.zip"
}
4 changes: 2 additions & 2 deletions src/scripts/chatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class Chatter {
static placeImage(combatant) {
if (Settings.getIncludeAnnounceImage()) {
let img = combatant.img;
if (combatant.flags.core && combatant.flags.core.thumb) {
img = combatant.flags.core.thumb;
if (combatant._actor.data.img) {
img = combatant._actor.data.img;
}
return `<div style="flex:3;padding-right:4px"><img src="${img}" style="border: none;" /></div>`;
// return `<div style="flex:3;"><video><source="${combatant.img}"></video></div>`;
Expand Down
52 changes: 26 additions & 26 deletions src/scripts/marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export class Marker {
*/
static async deleteTurnMarker() {
const to_delete = canvas.scene.getEmbeddedCollection('Tile')
.filter(tile => tile.flags.turnMarker)
.filter(tile => "flags" in tile.data)
.filter(tile => tile.data.flags.turnMarker)
.map(tile => tile._id);
if (!game.user.isGM) {
game.socket.emit(socketName, {
Expand All @@ -29,7 +30,8 @@ export class Marker {
*/
static async deleteOnDeckMarker() {
const to_delete = canvas.scene.getEmbeddedCollection('Tile')
.filter(tile => tile.flags.deckMarker)
.filter(tile => "flags" in tile.data)
.filter(tile => tile.data.flags.deckMarker)
.map(tile => tile._id);
if (!game.user.isGM) {
game.socket.emit(socketName, {
Expand All @@ -56,7 +58,7 @@ export class Marker {
let dims = this.getImageDimensions(token, false, "turnmarker");
let center = this.getImageLocation(token, false, "turnmarker");

let newTile = new Tile({
let newTile = await canvas.scene.createEmbeddedDocuments("Tile", [{
img: Settings.getImagePath(),
width: dims.w,
height: dims.h,
Expand All @@ -67,11 +69,9 @@ export class Marker {
hidden: token.data.hidden,
locked: false,
flags: {turnMarker: true}
});

let tile = await canvas.scene.createEmbeddedEntity('Tile', newTile.data);
}]);

return tile._id;
return newTile._id;
} else {
return null;
}
Expand All @@ -88,7 +88,7 @@ export class Marker {
let token = findTokenById(tokenId);
let dims = this.getImageDimensions(token, false, "deckmarker");
let center = this.getImageLocation(token, false, "deckmarker");
let newTile = new Tile({
let newTile = canvas.scene.createEmbeddedDocuments("Tile", [{
img: Settings.getOnDeckImagePath(),
width: dims.w,
height: dims.h,
Expand All @@ -99,10 +99,10 @@ export class Marker {
hidden: token.data.hidden,
locked: false,
flags: {deckMarker: true}
});
}]);

if (game.user.isGM) {
await canvas.scene.createEmbeddedEntity('Tile', newTile.data);
await canvas.scene.createEmbeddedDocuments('Tile', newTile.data);
}
}
}
Expand All @@ -113,7 +113,8 @@ export class Marker {
*/
static async deleteStartMarker() {
const to_delete = canvas.scene.getEmbeddedCollection('Tile')
.filter(tile => tile.flags.startMarker)
.filter(tile => "flags" in tile.data)
.filter(tile => tile.data.flags.startMarker)
.map(tile => tile._id);
if (!game.user.isGM) {
game.socket.emit(socketName, {
Expand All @@ -137,21 +138,20 @@ export class Marker {
let token = findTokenById(tokenId);
let dims = this.getImageDimensions(token);
let center = this.getImageLocation(token);
let newTile = new Tile({
img: Settings.getStartMarker(),
width: dims.w,
height: dims.h,
x: center.x,
y: center.y,
z: 900,
rotation: 0,
hidden: token.data.hidden,
locked: false,
flags: {startMarker: true}
});

if (game.user.isGM) {
await canvas.scene.createEmbeddedEntity('Tile', newTile.data);
let newTile = await canvas.scene.createEmbeddedDocuments("Tile", [{
img: Settings.getStartMarker(),
width: dims.w,
height: dims.h,
x: center.x,
y: center.y,
z: 900,
rotation: 0,
hidden: token.data.hidden,
locked: false,
flags: {startMarker: true}
}]);
await canvas.scene.setFlag(FlagScope, Flags.startMarkerPlaced, true);
}
}
Expand All @@ -167,14 +167,14 @@ export class Marker {
let dims = this.getImageDimensions(token, false, marker_type);
let center = this.getImageLocation(token, false, marker_type);

await canvas.scene.updateEmbeddedEntity('Tile', {
await canvas.scene.updateEmbeddedDocuments('Tile', [{
_id: markerId,
width: dims.w,
height: dims.h,
x: center.x,
y: center.y,
hidden: token.data.hidden
});
}]);
}

/**
Expand Down
9 changes: 4 additions & 5 deletions src/scripts/markeranimation.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,18 @@ export class MarkerAnimation {
let tile;
switch (marker_type) {
case "turnmarker":
tile = canvas.tiles.placeables.find(t => t.data.flags.turnMarker == true);
tile = canvas.background.tiles.find(t => t.data.flags.turnMarker == true);
break;
case "deckmarker":
tile = canvas.tiles.placeables.find(t => t.data.flags.deckMarker == true);
tile = canvas.background.tiles.find(t => t.data.flags.deckMarker == true);
break;
default:
tile = canvas.tiles.placeables.find(t => t.data.flags.turnMarker == true);
tile = canvas.background.tiles.find(t => t.data.flags.turnMarker == true);
}

if (tile && tile.data.img) {
let delta = Settings.getInterval() / 10000;
try {
tile.tile.img.rotation += (delta * dt);
tile.tile.rotation += (delta * dt);
} catch (err) {
// skip lost frames if the tile is being updated by the server
}
Expand Down
55 changes: 27 additions & 28 deletions src/scripts/turnmarker.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Hooks.once('ready', () => {
game.socket.on(socketName, async (data) => {
if (game.user.isGM) {
if (data) {
const to_delete = canvas.tiles.placeables.find(t => t.id === data[0]);
const to_delete = canvas.background.tiles.find(t => t.id === data[0]);
switch (data.mode) {
case socketAction.deleteStartMarker:
await canvas.scene.deleteEmbeddedEntity('Tile', to_delete);
Expand All @@ -43,38 +43,38 @@ Hooks.once('ready', () => {
});

Hooks.on('canvasReady', () => {
let deckTile = canvas.tiles.placeables.find(t => t.data.flags.deckMarker == true);
let deckTile = canvas.background.tiles.find(t => t.data.flags.deckMarker == true);
if (deckTile) {
deckTile.zIndex = Math.max(...canvas.tiles.placeables.map(o => o.zIndex)) + 1;
deckTile.zIndex = Math.max(...canvas.background.tiles.map(o => o.zIndex)) + 1;
deckTile.parent.sortChildren();
if (!game.paused && Settings.getShouldAnimate("deckmarker")) {
MarkerAnimation.startAnimation("deckmarker");
}
}

let tile = canvas.tiles.placeables.find(t => t.data.flags.turnMarker == true);
let tile = canvas.background.tiles.find(t => t.data.flags.turnMarker == true);
if (tile) {
tile.zIndex = Math.max(...canvas.tiles.placeables.map(o => o.zIndex)) + 1;
tile.zIndex = Math.max(...canvas.background.tiles.map(o => o.zIndex)) + 1;
tile.parent.sortChildren();
if (!game.paused && Settings.getShouldAnimate("turnmarker")) {
MarkerAnimation.startAnimation("turnmarker");
}
}
});

Hooks.on('createTile', (scene, data) => {
if (data.flags.turnMarker == true || data.flags.startMarker == true) {
const tile = canvas.tiles.placeables.find(t => t.id === data._id);
Hooks.on('createTile', (tileDoc) => {
if (tileDoc.data.flags.turnMarker == true || tileDoc.data.flags.startMarker == true) {
const tile = canvas.background.tiles.find(t => t.id === tileDoc.data._id);
if (tile) {
if (data.flags.deckMarker == true) {
tile.zIndex = Math.max(...canvas.tiles.placeables.map(o => o.zIndex)) + 1;
if (tileDoc.data.flags.deckMarker == true) {
tile.zIndex = Math.max(...canvas.background.tiles.map(o => o.zIndex)) + 1;
tile.parent.sortChildren();
if (!game.paused && Settings.getShouldAnimate("deckmarker")) {
MarkerAnimation.startAnimation("deckmarker");
}
}
else if (data.flags.turnMarker == true) {
tile.zIndex = Math.max(...canvas.tiles.placeables.map(o => o.zIndex)) + 1;
else if (tileDoc.data.flags.turnMarker == true) {
tile.zIndex = Math.max(...canvas.background.tiles.map(o => o.zIndex)) + 1;
tile.parent.sortChildren();
if (!game.paused && Settings.getShouldAnimate("turnmarker")) {
MarkerAnimation.startAnimation("turnmarker");
Expand All @@ -99,9 +99,8 @@ Hooks.on('updateCombat', async (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)
handleCombatUpdate(combatTracker.viewed, update)
}
});

Expand All @@ -112,13 +111,13 @@ Hooks.on('deleteCombat', async () => {
MarkerAnimation.stopAllAnimation();
});

Hooks.on('updateToken', async (scene, updateToken, updateData) => {
Hooks.on('updateToken', async (tokenDoc, updateData, diff, id) => {
/*
Moving preUpdateToken logic here, since pre hooks induce race conditions
*/

// Do onDeck first, so current token will have higher Z-index
let deckTile = canvas.tiles.placeables.find(t => t.data.flags.deckMarker == true);
let deckTile = canvas.background.tiles.find(t => t.data.flags.deckMarker == true);
if (deckTile) {
if ((updateData.x || updateData.y || updateData.width || updateData.height || updateData.hidden) &&
(game && game.combat) &&
Expand All @@ -130,19 +129,19 @@ Hooks.on('updateToken', async (scene, updateToken, updateData) => {
}
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.zIndex = Math.max(...canvas.background.tiles.map(o => o.zIndex)) + 1;
deckTile.parent.sortChildren();
}
}


let tile = canvas.tiles.placeables.find(t => t.data.flags.turnMarker == true);
let tile = canvas.background.tiles.find(t => t.data.flags.turnMarker == true);
if (tile) {
if ((updateData.x || updateData.y || updateData.width || updateData.height || updateData.hidden) &&
(game && game.combat && game.combat.combatant && game.combat.combatant.tokenId == updateToken._id) &&
(game && game.combat && game.combat.combatant && game.combat.combatant._token.data._id == updateData._id) &&
game.user.isGM && game.combat) {
await Marker.moveMarkerToToken(updateToken._id, tile.id, "turnmarker");
tile.zIndex = Math.max(...canvas.tiles.placeables.map(o => o.zIndex)) + 1;
await Marker.moveMarkerToToken(updateData._id, tile.data._id, "turnmarker");
tile.zIndex = Math.max(...canvas.background.tiles.map(o => o.zIndex)) + 1;
tile.parent.sortChildren();
}
}
Expand Down Expand Up @@ -214,7 +213,7 @@ async function handleCombatUpdate(combat, update) {
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);
let tile = canvas.background.tiles.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()) {
Expand All @@ -240,17 +239,17 @@ async function handleCombatUpdate(combat, update) {
}
}

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);
Hooks.on('updateTile', (tileDoc) => {
if (tileDoc.data.flags.turnMarker || tileDoc.data.flags.startMarker || tileDoc.data.flags.deckMarker) {
const tile = canvas.background.tiles.find(t => t.id === tileDoc.data._id);
if (tile) {
tile.renderable = isVisible(tile);
}
}
});

Hooks.on('sightRefresh', () => {
for (const tile of canvas.tiles.placeables) {
for (const tile of canvas.background.tiles) {
if (tile.data.flags.turnMarker || tile.data.flags.startMarker || tile.data.flags.deckMarker) {
tile.renderable = isVisible(tile);
}
Expand All @@ -259,10 +258,10 @@ Hooks.on('sightRefresh', () => {

Hooks.on('pauseGame', (isPaused) => {
if (!isPaused) {
if (Settings.getShouldAnimate("turnmarker") && canvas.tiles.placeables.find(t => t.data.flags.turnMarker == true)) {
if (Settings.getShouldAnimate("turnmarker") && canvas.background.tiles.find(t => t.data.flags.turnMarker == true)) {
MarkerAnimation.startAnimation("turnmarker");
}
if (Settings.getShouldAnimate("deckmarker") && canvas.tiles.placeables.find(t => t.data.flags.deckMarker == true)) {
if (Settings.getShouldAnimate("deckmarker") && canvas.background.tiles.find(t => t.data.flags.deckMarker == true)) {
MarkerAnimation.startAnimation("deckmarker");
}
} else {
Expand Down
19 changes: 8 additions & 11 deletions src/templates/updateWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ <h2>Want to support development?</h2>
<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
<a href="https://github.com/kckaiwei/TurnMarker-alt/blob/master/CHANGELOG.md">here</a>.</p>
<h2>v2.8.0</h2>
<ul>
<li>Add compatibility for Foundry version 0.8.6</li>
</ul>
<h2>v2.7.5</h2>
<ul>
<li>Add Savage Worlds Adventurer Edition support (SWADE)</li>
</ul>
<h2>v2.7.4</h2>
<ul>
<li>Fixed marker sizing issues for non-square tokens on grid/gridless maps</li>
Expand All @@ -32,17 +40,6 @@ <h2>v2.7.3</h2>
<ul>
<li>Fixed tile deletion issue in different scenes</li>
</ul>
<h2>v2.7.2</h2>
<ul>
<li>Fixed marker in wrong location after reloading</li>
<li>Fixed marker not pausing with game</li>
<li>Marker visibilities are now tied to vision</li>
</ul>
<h2>v2.7.1</h2>
<ul>
<li>Fixing ghosting issues with some start markers</li>
<li>Fixing turn marker showing when out of combat</li>
</ul>
<p style="display: flex; flex-flow: row nowrap; align-items: center; justify-content: flex-start;"><input
type="checkbox" class='show-again' id="welcome-screen-show-again" /> <label
for="welcome-screen-show-again">Don't show this screen again until next update.</label>
Expand Down

0 comments on commit fe60e3f

Please # to comment.