Skip to content

Commit

Permalink
fix: Hopefully fix race condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
xdy committed Dec 28, 2021
1 parent 2a9b3f4 commit 3ffaedb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/module/app/mystify-token/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export async function doMystification(token: Token, active: boolean) {
})
);
}
(game as Game).scenes?.active?.updateEmbeddedDocuments("Token", updates);

return updates;
}

export function renderNameHud(data: TokenData, html: JQuery) {
Expand All @@ -141,7 +142,8 @@ export function renderNameHud(data: TokenData, html: JQuery) {
const hudElement = $(e.currentTarget);
const active = hudElement.hasClass("active");
if (token !== null && isTokenMystified(token) === active) {
await doMystification(token, active);
const updates = await doMystification(token, active);
await (game as Game).scenes?.active?.updateEmbeddedDocuments("Token", updates);
}
hudElement.toggleClass("active");
});
Expand Down
11 changes: 8 additions & 3 deletions src/module/keybinds.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Keyboard key controlling whether the actor should be mystified, if this feature is toggled on
import { MODULENAME } from "./xdy-pf2e-workbench";
import { doMystification, isTokenMystified } from "./app/mystify-token";
import { moveSelectedAheadOfCurrent } from "./app/moveCombatant";
import { doMystification, isTokenMystified } from "./app/mystify-token";

export let mystifyModifierKey: string;

Expand Down Expand Up @@ -35,8 +35,13 @@ export function registerKeybindings() {
key: "KeyM",
},
],
onDown: () => {
canvas?.tokens?.controlled.filter(async (token) => await doMystification(token, isTokenMystified(token)));
onDown: async () => {
const updates = [];
for (const token of canvas?.tokens?.controlled || []) {
updates.push(...(await doMystification(token, isTokenMystified(token))));
}

await (game as Game).scenes?.active?.updateEmbeddedDocuments("Token", updates);
},
restricted: false,
reservedModifiers: [],
Expand Down

0 comments on commit 3ffaedb

Please sign in to comment.