unsoluble / smalltime

A small FoundryVTT module for displaying and controlling the current time of day.
MIT License
23 stars 15 forks source link

Darkness doesn't sync with players if not on GM's screen. [partial solution] #121

Closed Kreals closed 2 years ago

Kreals commented 2 years ago

Basically if a player moves away from the GM's currently viewed scene then the darkness level for the player's new scene will not change if the GM adjusts one of the time/moon/sun settings.

unsoluble commented 2 years ago

Yeah, that's expected behaviour; it's not practical to push database updates to the Darkness value for all scenes on every change, just the scene currently being viewed by the GM.

Kreals commented 2 years ago

Fair enough, it doesnt seem there is an easy way to get a reference to each player's/user's currently viewed scenes either, without looping through every scene and token. Oh well. Thanks for the reply.

Kreals commented 2 years ago

Oh, i actually did find a way to do this that only targets currently viewed scenes if anyone fancies a go.

Replace the the following code in the `\user_data\Data\modules\smalltime\scripts\smalltime.js' file at line 1819:

original

1819    if (game.user.isGM) {
1820           await currentScene.update({ darkness: darknessValue });
1821    } else {

replace with the following

1819     let usersViewingScenes = Array.from(game.users.values()).filter(function (emp) { return emp.viewedScene !== null });
1820     if (game.user.isGM) {
1821         for (let i = 0; i < usersViewingScenes.length; i++) {
1822          await game.scenes.get(usersViewingScenes[i].viewedScene).update({ darkness: darknessValue });
1823         }
1824         //await currentScene.update({ darkness: darknessValue });
1825     } else {

This will likely stress out your network connection a little more sooo, use at your own peril.