Skip to content

Super saver#223

Open
ewhac wants to merge 4 commits intoAda18980:5.5from
ewhac:super_saver
Open

Super saver#223
ewhac wants to merge 4 commits intoAda18980:5.5from
ewhac:super_saver

Conversation

@ewhac
Copy link
Contributor

@ewhac ewhac commented May 6, 2025

Re-design save codes. Re-write all sites where codes are compressed to use the new functions.

Because CompressionStreams require async code, save codes are now "trapped" inside the async/Promise space, and can only be accessed if the code accessing them is also inside that space. A lot of async keywords have been sprinkled haphazardly throughout the code to get it to compile and sort of work. However, there are almost certainly race conditions where "mainline" code needs to wait for async tasks to complete and fill out shared variables before proceeding. There is no way to do this without making the calling functions async as well.

The result is that bits of the program are now flaky, notably the wardrobe editor. Not sure how to address this without a major rewrite of everything.

Best reviewed using diff -b to ignore whitespace/indentation changes.

Backup all your save codes before messing with this!

@ewhac ewhac force-pushed the super_saver branch 2 times, most recently from 8398f66 to a943ad1 Compare June 25, 2025 11:11
@ewhac ewhac marked this pull request as ready for review August 4, 2025 01:50
@ewhac
Copy link
Contributor Author

ewhac commented Aug 4, 2025

Not sure how this got marked as a draft.

I've been using this branch as my daily driver for some weeks now, and haven't encountered any more odd behavior. The only real head-scratcher is when leaving the floor into the mezzanine/perk shrine -- it feels like the save code generator is being called twice, but I haven't yet worked out how.

Backup all your save codes before messing with this!

@ewhac ewhac force-pushed the super_saver branch 2 times, most recently from ed8f0c9 to 351ab3a Compare September 7, 2025 16:13
@ewhac ewhac force-pushed the super_saver branch 3 times, most recently from c2c4f95 to df89f00 Compare September 20, 2025 03:22
@ewhac ewhac force-pushed the super_saver branch 2 times, most recently from 9d2acef to 8cdf474 Compare October 8, 2025 11:17
@ewhac ewhac force-pushed the super_saver branch 2 times, most recently from 7762b2a to eb29208 Compare October 24, 2025 23:51
@ewhac ewhac force-pushed the super_saver branch 2 times, most recently from ba0d6df to 3519a71 Compare November 7, 2025 07:22
@ewhac ewhac force-pushed the super_saver branch 4 times, most recently from cc38b3d to d50559f Compare December 5, 2025 00:06
@ewhac ewhac force-pushed the super_saver branch 2 times, most recently from 646af88 to 6e041d6 Compare January 10, 2026 08:20
@ewhac ewhac force-pushed the super_saver branch 2 times, most recently from 72ac5c4 to 03306d1 Compare January 17, 2026 02:07
@YukiMonsai
Copy link

Im personally not a fan of making core functions async

@YukiMonsai
Copy link

Perhaps a better solution would be to use something similar to the "Generating Map" screen, but intercepting mouse clicks instead of overriding the screen

@ewhac
Copy link
Contributor Author

ewhac commented Feb 13, 2026

Im personally not a fan of making core functions async

I'm not, either. Unfortunately, the compression facility is advertised as async-only, rather like the IndexedDB facility (which created a series of .then() calls throughout the code). My JavaScript-fu was not strong enough to figure out how to get the compressed/decompressed data out of the async context. Indeed, all the JS material I can find suggests that async code cannot be made synchronous, i.e. you can't block on a Promise in the main thread until it resolves.

It may also be worth pointing out that I compressed not only game saves, but also outfits, so my PR touches more things.

I will be reading @Zarniwoops' PR #247 with interest.

@Zarniwoops
Copy link
Contributor

I tried to keep my changes as minimal as I could. Which meant just the bulk save, and not the rest of the smaller save codes.

Async is unavoidable, but the key here is that you can switch the main render screen to a "please wait / loading / saving", and let async come back in it's own time.

If there's any interest, I can update the PR to be a clean merge... otherwise, I'll leave it as-is just for reference.

ewhac added 4 commits March 17, 2026 02:00
Some brief experiments with CyberChef showed that changing from LZString
to gzip CompressionStreams would not only be faster, but also result in
smaller save codes.

New save codes are `data:` URLs, base64-encoded.  The MIME types are:

  - `application/vnd.straightlaced.kinkydungeon.save.game+gzip;version=2`
  - `application/vnd.straightlaced.kinkydungeon.save.outfit+gzip;version=2`
  - `application/vnd.straightlaced.kinkydungeon.save.wardrobe+gzip;version=2`

(The 'wardrobe` variant is not used yet.)

Save codes without a `data:` leader are assumed to be legacy LZString
codes, and may still be loaded from browser storage or pasted in to the
load dialog.  The intention, however, is for all new saves to be in the
new format.

This initial checkin gets the core code in place, but forces saves in
legacy format.  This will be removed when the new codes are proved
reliable, and I'm convinced we're not accidentally destroying data.

(async/Promises are a real pain...)
There are a bunch of places where wardrobe outfit codes are loaded and
stored, and I had to update all of them.  Tried to be judicious about
where to place `async` blocks, but there's a good chance there are
synchronization errors.  Initial tests promising, however; hence this
checkin.

Save codes still forced to legacy LZStrings.
Locate and update all remaining calls to `compressToBase64()`,
`decompressFromBase64()`, and `DecompressB64()`.  Also supply SaveType
arguments at all `KinkyDungeon{,De}CompressSave()` call sites.
Newly generated save codes will be in the new format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants