Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to add a callback when the user saves in-game #163

Closed
KobeOne2 opened this issue Aug 25, 2024 · 8 comments · Fixed by #168
Closed

Is it possible to add a callback when the user saves in-game #163

KobeOne2 opened this issue Aug 25, 2024 · 8 comments · Fixed by #168
Assignees
Labels
enhancement New feature or request

Comments

@KobeOne2
Copy link

KobeOne2 commented Aug 25, 2024

Hello, and thank you for your fantastic project. I've been using it a lot recently due to my current circumstances.

Anyway, I was wondering if it was possible (to prevent forgetting to download the save😅) to trigger an automatic download prompt or even upload the save to a server whenever a player saved in-game. I tried to add this capability myself, but I couldn't find a way to detect when the save game changed. So, do you know if it is even doable with WASM mGBA? As far as I can tell, mGBA should have a callback "saveDataUpdated".

@thenick775
Copy link
Owner

thenick775 commented Aug 25, 2024

I didn't know that functionality existed, which is what has so far prevented me from implementing auto-persistence features.

I might just have to figure out how to bind it in my fork of mGBA, hopefully it doesn't require threading (which I haven't gotten to a full implementation with web workers).

I'll investigate this one as I free up!

For context:

  • nothing like that is exposed so far in the wasm contract
  • historically, I wasn't able to figure that out as I'm pretty new to the mGBA codebase as a whole (and as a user)
  • I can see this is used in _mCoreThreadAddCallbacks, which may preclude this type of functionality until I can work out threading in wasm for mGBA
  • This might be nice to add to Extended settings UI #151, adding specified actions that can occur on any of the mGBA callback states in mCoreCallbacks
    • prefer opt in most likely, as I definitely do intentionally rely on the current behavior sometimes, others might too

@thenick775 thenick775 added enhancement New feature or request help wanted Extra attention is needed labels Aug 25, 2024
@thenick775
Copy link
Owner

And just in case I've done a bad job at disseminating information, you should never have to download your safe files unless you want backups!

The File System has a SAVE FILE SYSTEM button, when clicked this will save all your roms/saves/save states to your browsers local indexeddb, ready for use when you close/reopen the emulator 😎

@thenick775
Copy link
Owner

thenick775 commented Aug 25, 2024

@KobeOne2 How'd you learn about the saveDataUpdated method in mGBA's core callbacks?

@thenick775 thenick775 self-assigned this Aug 26, 2024
@thenick775
Copy link
Owner

thenick775 commented Aug 27, 2024

Just wanted to say I've got a tentative POC up here:

Demo link (see file system modal and console output)

gbajs3 changes

mGBA wasm changes

I'll try to polish this up as I'm available!

@KobeOne2
Copy link
Author

Thank you for your hard work.

How'd you learn about the saveDataUpdated method in mGBA's core callbacks?

They seem to be listed here https://mgba.io/docs/scripting.html#class-CallbackManager.

@thenick775
Copy link
Owner

They seem to be listed here https://mgba.io/docs/scripting.html#class-CallbackManager.

Nice! I really need to dig deeper into mGBA docs 😂

@thenick775 thenick775 removed the help wanted Extra attention is needed label Aug 29, 2024
@thenick775
Copy link
Owner

thenick775 commented Sep 6, 2024

Just noting that this is still in progress!

Running into some issues adding a function to the wasm table immediately after emulator initialization/game startup, but should be able to work through that 😎

@thenick775
Copy link
Owner

thenick775 commented Sep 9, 2024

@KobeOne2 I've extended the mGBA core functionality to add user defined callbacks, at least all of the ones I could prove were accessible!

You can find the work done to add callbacks on the mGBA wasm core side here

And an example of how I use them on the js side here

I may add a few more callbacks as time goes on and I make the UI a little more conducive for actual emulator settings, but feel free to submit a PR here if you want to add some functionality!

This should give you a template for adding your own callbacks, but feel free to create another issue, discussion, or comment here if you need any assistance! 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants