TJSGameSettings getStore not saving properly?
I have a bizzare interaction right now with TJSGameSettings.getStore / getWritableStore.
It gets updated, I even see in the console through
game.settings.get
that the setting has been "updated"
Then I refresh and the changes made disappear. What gives?13 Replies
These changes are made through
bind:value={$setting}
on various inputs. It works on a regular writable
, so I am not sure what's happening here.
What is even stranger is that on live reload, TJSGameSettings
claims the setting is not a registered setting and returns undefined
Even when before the live reload it clearly existedlike
attaching a
subscribe(v => game.settings.set("...", v)
works but... this really shouldnt be the case right?
moving it from an import
to a global reference fixes the issue, so I am guessing the live reload bug was purely something on vite's / svelte's partYeah.. I was going to ask if you saw the same symptom without the dev server. Then there is potentially something going on with the live reload of the
TJSGameSettings
instance. Rather than making it a global reference perhaps you can import it into the top level app shell component then set TJSGameSettings
to a context item. This might prevent child component changes from reloading the instance.
Without seeing the code involved this is just my assumption.I tried fixing the issue by passing the settings as a prop, it also died when done this way
GitHub
pf2e-graphics/src/view/WorldAnimations/WorldAnimationsShell.svelte ...
@vauxs. Contribute to MrVauxs/pf2e-graphics development by creating an account on GitHub.
Here is the code, replace
window.pf2eGraphics.storeSettings
with an import from settings.ts
I removed the export because of the bug, but it was just export const storeSettings = new TJSGameSettings('pf2e-graphics')
I'm not sure offhand if the prop vs context aspect would make a difference. You can also import the game settings instance in the outer SvelteApplication instance and set that as a context in the mounting process such that there is no direct import of the settings instance in a Svelte component. That possibly could change the live reload situation too.
I think folks may overlook the ability to setup a context in the main Svelte config object from
SvelteApplication
versus just passing props.
This may not help this specific live reload issue. I always try and avoid any sort of global variable solution.
I also don't work as much with the dev server, so it's useful to hear about minor issues that come up.Worked hard to have everything HMR-able lol
For sure.. The likely problem in the live reload case is that the register method in the
TJSGameSettings
instance makes the connection with the underlying Foundry callback when the setting changes. If TJSGameSettings
is just hot reloaded then that connection is broken with a new instance of TJSGameSettings
. At least that is my introspective guess based on the symptoms.Thats what I guessed
Which is why I went with the globals, since I already had them for debugging purposes
Might as well have a de-facto One Source of Truth
After
0.2.0
starts rolling out it might be worth looking into various supporting code like TJSGameSettings
to see if things like that can be hardened for live reload out of the box.Feel free to gander around PF2e Graphics code in that aspect