caiiiycuk / js-dos

The best API for running dos programs in browser
https://js-dos.com
1.03k stars 129 forks source link

Can you share an example on how can I save states in v8? #337

Closed beingretrogamer closed 1 month ago

beingretrogamer commented 1 month ago

Hi @caiiiycuk hope you are doing good. Do you mind sharing a quick example on how can I save the games locally. And then upload the state to continue? Is this even possible in v8?

Thanks!

caiiiycuk commented 1 month ago

V8 do this automatically, it saves state in jsdos cloud if user is logged in, otherwise state is stored in indexed db of browser. Just do not forget to press save icon.

beingretrogamer commented 1 month ago

Thanks for the quick response. The thing is I am on the kiosk mode and am interested in implementing the auto saves. Is that supported that way? Can we expose the function being called when the user clicks in the normal mode?

On Sat, 24 Aug 2024 at 4:59 AM, Alexander Guryanov @.***> wrote:

V8 do this automatically, it saves state in jsdos cloud if user is logged in, otherwise state is stored in indexed db of browser. Just do not forget to press save icon.

— Reply to this email directly, view it on GitHub https://github.com/caiiiycuk/js-dos/issues/337#issuecomment-2307922599, or unsubscribe https://github.com/notifications/unsubscribe-auth/BIEQGPZPZWRLFB2CE5BTSNDZS7AVTAVCNFSM6AAAAABNBADPV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXHEZDENJZHE . You are receiving this because you authored the thread.Message ID: @.***>

caiiiycuk commented 1 month ago

Kiosk mode is harder, cause saves also use login information. If you can't activate normal mode (e.g. some ui that toggles it), then you need implement it by you own using CommandInterface instance.

beingretrogamer commented 1 month ago

Too bad! Do you mind sharing a quick snippet for reference?

Also, please point me to the file where saving happens. I would be happy to contribute this if you feel like it is feasible.

Thanks!

On Sat, 24 Aug 2024 at 5:07 AM, Alexander Guryanov @.***> wrote:

Kiosk mode is harder, cause saves also use login information. If you can't activate normal mode (e.g. some ui that toggles it), then you need implement it by you own using CommandInterface instance.

— Reply to this email directly, view it on GitHub https://github.com/caiiiycuk/js-dos/issues/337#issuecomment-2307927648, or unsubscribe https://github.com/notifications/unsubscribe-auth/BIEQGPY64BZVZQD4A4RLJLLZS7BVPAVCNFSM6AAAAABNBADPV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXHEZDONRUHA . You are receiving this because you authored the thread.Message ID: @.***>

caiiiycuk commented 1 month ago

If you doesn't care about login stuff, I can expose the api method to trigger save code path. It will store only in indexed db

beingretrogamer commented 1 month ago

Yep that would do the trick. Would it be a async method? Maybe return entire save state?

On Sat, 24 Aug 2024 at 5:33 AM, Alexander Guryanov @.***> wrote:

If you doesn't care about login stuff, I can expose the api method to trigger save code path. It will store only in indexed db

— Reply to this email directly, view it on GitHub https://github.com/caiiiycuk/js-dos/issues/337#issuecomment-2307940370, or unsubscribe https://github.com/notifications/unsubscribe-auth/BIEQGP3KQ5FO6J66GMI3NF3ZS7EVZAVCNFSM6AAAAABNBADPV6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMBXHE2DAMZXGA . You are receiving this because you authored the thread.Message ID: @.***>

beingretrogamer commented 1 month ago

Hey there! Just checking in if there is any update on this one?

caiiiycuk commented 1 month ago

Added in v8.1.19, example:

cost props = Dos(elem, options);
props.save(); // will trigger save function, it return Promise<boolean>

documentation: https://js-dos.com/player-api.html#dosprops

beingretrogamer commented 1 month ago

I am able to save the state and it adds an entry in indexedDB. Just after saving, I am retrieving the save data and converting it into a file to be stored locally. Now, how do I load the file before the game starts? I mean there is no load method and I tried initFs and it doesn't seem to work. The only thing that works is if I create an entry the indexedDB like below -

objectStore.add(_result, 'https://storage.yandexcloud.net/doszone-uploads/personal-v2/dzapi/guest/' + bundleName);

_result is my ArrayBuffer but this is not very intuitive from the api perspective due to

  1. Why this file name convention?
  2. I have to manually interact with the indexedDB which exposes very low level apis and is already a trouble

My 2 cents -

  1. Just like we have a save method, there should be a method which loads this data for merging.
  2. The save method should return the savedState instead of the boolean value so that there is no need to interact with indexedDB.

Let me know what are your thoughts! Again, I would be happy to contribute if you feel like this makes sense.

Thanks!

caiiiycuk commented 4 weeks ago

I think you missunderstood the idea of js-dos project. js-dos player is built to run jsdos bundles in web, it works like a blackbox you provide bundle and it manages everything including save/load functions. This new api is made in case when you use kiosk mode, you call the save method and player will save progress same as when you press save button in UI. The loading happen automatically by player itself, it works while you use same url.

There are two options:

  1. if you want to add new feature to save progress locally in a file on PC and then load it somehow, then you need to design also UI part of player, I mean clients of player should understand how to use this new option.
  2. If you want to build custom integration, like your own player with this feature, then you need to use emulators package instead, js-dos built on top of it. it has lowlevel api to implement save feature whatever you want.