Zeenobit / moonshine_save

A save/load framework for Bevy game engine.
MIT License
81 stars 9 forks source link

Save / Load on Events #2

Closed data-niklas closed 1 year ago

data-niklas commented 1 year ago

Hi! Thanks for the awesome crate.

The plugins currently support loading and saving the game state dynamically using run_if and custom resources implementing *FileRequest.

I propose to use Bevy's event system, to send custom load / save events. The load / save plugins could then register event readers and load / save when they receive a new event.

https://bevy-cheatbook.github.io/programming/events.html

E.g.: repurpose *FileRequest to something similar to

pub struct SaveIntoFileRequest(PathBuf);
pub struct LoadFromFileRequest(PathBuf);

App::new()
        .add_event::<SaveIntoFileRequest>()
        .add_event::<LoadFromFileRequest>()
        .add_system(process_save_events)
        .add_system(process_load_events);
Zeenobit commented 1 year ago

That makes sense to me. I'll look into implementing save_into_file_on_event<E> and load_from_file_on_event<E>.

Zeenobit commented 1 year ago

Added in 0.2.2