Skip to content

Commit

Permalink
Shared vision bugfixes. Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
sfuqua committed Feb 21, 2021
1 parent 94c926e commit 9b6035f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.2.2 - 2020/02/20

### Fixed

- Addressed an issue where NPC tokens could be leaked to players when the GM clicks on an NPC.
- Addressed an issue where the GM moving NPC tokens did not update shared vision of those tokens.

## 0.2.1 - 2020/02/01

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shared-token-visibility",
"version": "0.2.1",
"version": "0.2.2",
"title": "Shared Token Visibility",
"description": "Shares visibility of individual tokens between all players, regardless of dynamic lightning",
"author": "Steven Fuqua",
Expand Down
19 changes: 19 additions & 0 deletions src/RevealedTokenLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,24 @@ export class RevealedTokenLayer extends CanvasLayer {
updateTokens(_userId: string, updates: Array<{ _id: string }>): void {
let dirty = false;
for (const { _id: tokenId } of updates) {
// This means we have shared vision of this token and aren't drawing it ourselves,
// so the token needs to move
if (this.revealedTokens.has(tokenId) && !this.myVisibleTokens.has(tokenId)) {
dirty = true;
break;
}

// Whether this token is currently being drawn on this client
const tokenVisible = canvas.tokens.get(tokenId)?.visible;

// This means something's out of sync and we need to rebuild our status
if (
!!tokenVisible !== this.myVisibleTokens.has(tokenId) ||
!tokenVisible !== this.myHiddenTokens.has(tokenId)
) {
dirty = true;
break;
}
}

if (dirty) {
Expand All @@ -206,6 +220,11 @@ export class RevealedTokenLayer extends CanvasLayer {
* Fires off the current visibility status to other clients.
*/
emitVisibilityUpdate(): void {
// If we're a GM, we want to avoid leaking tokens to the players
if (game.user.isGM) {
return;
}

const update: TokenVisibilityUpdate = {
type: "visibilityUpdate",
userId: game.userId,
Expand Down

0 comments on commit 9b6035f

Please sign in to comment.