Use socket to manage loksyu

This commit is contained in:
2026-06-14 22:54:37 +02:00
parent 4cb8e26333
commit 50038a13f9
68 changed files with 464 additions and 233 deletions
+15 -1
View File
@@ -43,6 +43,9 @@ export class CDELoksyuApp extends foundry.applications.api.HandlebarsApplication
/** @type {Function|null} bound hook handler */
_updateHook = null
/** @type {Function|null} updateSetting hook handler (for socket-propagated writes) */
_settingHook = null
/** Singleton accessor — open or bring to front */
static open() {
const existing = Array.from(foundry.applications.instances.values()).find(
@@ -78,7 +81,14 @@ export class CDELoksyuApp extends foundry.applications.api.HandlebarsApplication
super._onRender(context, options)
this.#bindInputs()
this._updateHook = Hooks.on("cde:loksyuUpdated", () => this.render())
if (!this._updateHook) {
this._updateHook = Hooks.on("cde:loksyuUpdated", () => this.render())
}
if (!this._settingHook) {
this._settingHook = Hooks.on("updateSetting", (setting) => {
if (setting.key === `${SYSTEM_ID}.loksyuData`) this.render()
})
}
}
_onClose(options) {
@@ -86,6 +96,10 @@ export class CDELoksyuApp extends foundry.applications.api.HandlebarsApplication
Hooks.off("cde:loksyuUpdated", this._updateHook)
this._updateHook = null
}
if (this._settingHook !== null) {
Hooks.off("updateSetting", this._settingHook)
this._settingHook = null
}
super._onClose(options)
}