aduros / wasm4

Build retro games using WebAssembly for a fantasy console.
https://wasm4.org
ISC License
1.17k stars 172 forks source link

Suggestion: Import/export save data to a file #553

Open MrRafael-dev opened 2 years ago

MrRafael-dev commented 2 years ago

Currently, save data is limited to where you play the game:

My suggestion is to have an option to import/export save data to a file, allowing players to share and use them however they like. Not only this solves a large amount of limitations, it can also provide a lot more if used creatively:

aduros commented 2 years ago

We have state saving/loading mapped to the 2 and 4 keys. Maybe Shift-2 can open a dialog to save the state to a file, and Shift-4 to browse to open?

The state contains both RAM and disk, so it wouldn't be exactly what you're requesting, but might be the simplest and most intuitive for users to understand. Saving the disk alone could be interesting for sharing data between different tools though.

MrRafael-dev commented 2 years ago

Having the same option for save states would also be a good addition, but I don't think that should replace the ability of doing the same with disk.

Apart from file sizes, I have a few reasons for this:

That said, I think we should still be able to save/load the disk alone, even if an option for save states already existed.

Maybe disk import/export could have their own options on the menu?

Continue
Save state
Load state
Save disk
Load disk
Clear disk
Copy netplay URL
Reset cart

We could also have an option to clear disk data, in case we load the wrong save or just want a fresh start.

In regards to saving: I was thinking of just having a single, uncompressed binary file with 1KB of data. Not sure if the file extension could be just .bin or should have it's own extension, though.

zetanumbers commented 11 months ago

I've come up with a bit of a hack to export the gamestate. First you need to save gamestate of a cartridge <Enter> -> Save State. This is a way to get memory as ArrayBuffer object of this saved gamestate:

document.querySelector('wasm4-app').savedGameState.memory

So i grabbed function _arrayBufferToBase64 from stackoverflow, and the whole command becomes:

_arrayBufferToBase64(document.querySelector('wasm4-app').savedGameState.memory )

Output of witch you can copy and decode bytes within your terminal to pass it whereever you need.

JerwuQu commented 6 months ago

Is there more we want to do for this issue, like state import/export, or is it done?

zetanumbers commented 6 months ago

There are mutable globals we would ideally need to export/import.