Skip to content

Commit

Permalink
Render overlay icons for player controlled tokens only
Browse files Browse the repository at this point in the history
  • Loading branch information
coffiarts committed Dec 16, 2023
1 parent 0aa9f5f commit d2e6f3f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Binary file modified src/sheet-locker/artwork/lock-green-open.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/sheet-locker/artwork/lock-red-closed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 9 additions & 7 deletions src/sheet-locker/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ async function initSocketlib() {
socket.register("sheetEditGMAlertUIMessage", sheetEditGMAlertUIMessage);
socket.register("itemChangedGMAlertUIMessage", itemChangedGMAlertUIMessage);
socket.register("itemDeletedGMAlertUIMessage", itemDeletedGMAlertUIMessage);
socket.register("renderTokenOverlays", renderTokenOverlays);
Logger.debug(`Module ${Config.data.modID} registered in socketlib.`);
}

Expand Down Expand Up @@ -208,16 +209,17 @@ function onItemDeletedFromSheet(item, options, userid) {
* inspired by // https://github.com/LeafWulf/deathmark/blob/master/scripts/deathmark.js
*/
async function renderTokenOverlays() {
let img = (SheetLocker.isActive) ? Config.setting('overlayIconLocked') : Config.setting('overlayIconOpen');
for (const aToken of game.scenes.current.tokens) {
if (aToken.actorLink) {
const ownedActor = game.actors.find((actor)=>{return (actor.id === game.users.current.character?.id)});
if (game.user.isGM || aToken.actorId === ownedActor?.id) {
//Logger.debug("aToken.actorId", aToken.actorId, "ownedActor?.id", ownedActor?.id);
await aToken.update({overlayEffect: img});
// ensure that overlay is only rendered for the token's owner (the GM will implicitely see them for all owned tokens)
const actor = game.actors.find((actor)=>{return (actor.id === aToken.actorId)});
const overlayImg =(SheetLocker.isActive) ?
Config.setting('overlayIconLocked') : Config.setting('overlayIconOpen');
if(actor.isOwner && !game.user.isGM) { // GM session must NOT generate overlays, otherwise ANY token will receive an icon
await aToken.update({overlayEffect: overlayImg});
}
}
}
}
}
function getButton() {
return ui.controls.controls.find(control => control.name === "token").tools.find(tool => tool.name === "toggleSheetLocker");
Expand Down Expand Up @@ -254,7 +256,7 @@ async function onGameSettingChanged() {
}

// Refresh status overlays
await renderTokenOverlays();
socket.executeForEveryone("renderTokenOverlays")

}
}
Expand Down

0 comments on commit d2e6f3f

Please sign in to comment.