From c426e457ff463da645975515f6bc11492521aaac Mon Sep 17 00:00:00 2001 From: Vlyan Date: Fri, 13 Aug 2021 17:20:59 +0200 Subject: [PATCH] better sync for "Gm Monitor" between gm --- system/scripts/gm/gm-monitor.js | 16 ++++++++++++---- system/scripts/gm/gm-toolbox.js | 8 ++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/system/scripts/gm/gm-monitor.js b/system/scripts/gm/gm-monitor.js index 3b3a021..6f105dc 100644 --- a/system/scripts/gm/gm-monitor.js +++ b/system/scripts/gm/gm-monitor.js @@ -176,8 +176,7 @@ export class GmMonitor extends FormApplication { this.object.actors.push(actor[0]); - await this._saveActorsIds(); - return this.refresh(); + return this._saveAndRefresh(); } /** @@ -193,6 +192,16 @@ export class GmMonitor extends FormApplication { ); } + /** + * Save ids and refresh the windows (local and socket) + * @return {Promise} + */ + async _saveAndRefresh() { + await this._saveActorsIds(); + game.l5r5e.sockets.refreshAppId("l5r5e-gm-monitor"); + return this.refresh(); + } + /** * Open the Sheet for this actor * @param {Event} event @@ -228,8 +237,7 @@ export class GmMonitor extends FormApplication { this.object.actors = this.object.actors.filter((e) => e.id !== id); - await this._saveActorsIds(); - return this.refresh(); + return this._saveAndRefresh(); } /** diff --git a/system/scripts/gm/gm-toolbox.js b/system/scripts/gm/gm-toolbox.js index 96fcfad..ad0e321 100644 --- a/system/scripts/gm/gm-toolbox.js +++ b/system/scripts/gm/gm-toolbox.js @@ -189,12 +189,12 @@ export class GmToolbox extends FormApplication { * @param {string} type * @private */ - _updatesActors(type) { + async _updatesActors(type) { if (!game.user.isGM) { return; } - game.actors.contents.forEach((actor) => { + for await (const actor of game.actors.contents) { switch (type) { case "sleep": // Remove 'water x2' fatigue points @@ -225,7 +225,7 @@ export class GmToolbox extends FormApplication { break; } - actor.update({ + await actor.update({ data: { fatigue: { value: actor.data.data.fatigue.value, @@ -238,7 +238,7 @@ export class GmToolbox extends FormApplication { }, }, }); - }); + } ui.notifications.info(game.i18n.localize(`l5r5e.gm_toolbox.${type}_info`));