Repository navigation
Saves and settings last across releases on the web - #142
Merged
Merged
Conversation
Unity's WebGL PlayerPrefs live in IndexedDB under /idbfs/<md5 of the page's folder URL>. itch.io serves each upload from a new folder (html/<build>-<upload>/), so every release started with empty save slots and default settings: the old ones were still there, under another hash. LocalStore keeps saves and settings in the browser's localStorage (prefix "luckynumbers.", since itch serves every HTML game from one origin), which doesn't depend on the folder. PlayerPrefs stay as a second copy and the fallback when storage is blocked; a key only PlayerPrefs has moves across when first read. For saves made before this: the page, before Unity starts, copies the newest PlayerPrefs another build left into this build's folder if it has none yet, so those slots show up and move to localStorage.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug. On itch.io every release started with empty save slots and default settings.
Cause. Unity's WebGL PlayerPrefs live in IndexedDB under
/idbfs/<md5 of the page's folder URL>/PlayerPrefs. I checked this locally: the hash is the md5 oforigin + folder, and the query string and file name don't change it. itch serves each upload from a new folder (currentlyhtml-classic.itch.zone/html/20387758-2378538/), so each build looked under a new hash. Within one build, saves did work.Fix.
LocalStore(withLocalStore.jslib) keeps saves and settings inlocalStorageunderluckynumbers.*. Every itch HTML game is served from one origin, so the prefix matters. localStorage doesn't depend on the folder.SavePresenterandSettingsPresenternow go throughLocalStore.index.htmlchecks this build's folder. If it has no PlayerPrefs yet, the page copies in the newest PlayerPrefs another build left. Those slots then show up and move to localStorage. The rescue is capped at 1.5 s, so it never blocks the start for long.Testing
ln.py check: 0 errors.ln.py tests: 77/77 passed./old/) on the same origin, all in one browser profile:/old/, I made a new character in slot 1. It was written tolocalStorageasluckynumbers.ln.save.0.localStorage, so only the old folder's PlayerPrefs held the save, as with 0.4.1 and earlier./index.htmllogged[web] saves: carried over from an older build (/idbfs/155f…).localStorage.[Save] loaded slot 1: Salvager … Station.md5on the localhost URL and on the itch folder URL.