[PR] [Feature] Refresh actors when a homebrew setting is changed (#1382)

* Refresh actors when a homebrew setting is changed

* Newline at end of file

* Close open prosemirror documents during reset
This commit is contained in:
Carlos Fernandez 2025-12-22 07:48:03 -05:00 committed by GitHub
parent 99d0eab5bd
commit e8dd38fbfa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -46,6 +46,9 @@ const registerMenuSettings = () => {
if (value.maxFear) {
if (ui.resources) ui.resources.render({ force: true });
}
// Some homebrew settings may change sheets in various ways, so trigger a re-render
resetActors();
}
});
@ -140,3 +143,25 @@ const registerNonConfigSettings = () => {
type: DhTagTeamRoll
});
};
/**
* Triggers a reset and non-forced re-render on all given actors (if given)
* or all world actors and actors in all scenes to show immediate results for a changed setting.
*/
function resetActors(actors) {
actors ??= [
game.actors.contents,
game.scenes.contents.flatMap(s => s.tokens.contents).flatMap(t => t.actor ?? [])
].flat();
actors = new Set(actors);
for (const actor of actors) {
for (const app of Object.values(actor.apps)) {
for (const element of app.element?.querySelectorAll('prose-mirror.active')) {
element.open = false; // This triggers a save
}
}
actor.reset();
actor.render();
}
}