Description
What problem does this solve or what need does it fill?
Saving and loading game state is a core functionality that will be reused across almost every game made in Bevy, but implementing this functionality requires advanced Bevy knowledge and there isn't consensus on how you might effectively accomplish it.
What solution would you like?
A pair of Commands
to save and load a game state, probably in combination with some Resources to set global config of this functionality.
@TheRawMeatball whipped up the following prototype:
struct SaveCommand;
struct LastSaveData(Option<SomeSerializedDataType>)
trait SaveCommandExt {
fn save(&mut self);
}
impl Command for SaveCommand {
fn write(self: Box<Self>, world: &mut World, resources: &mut Resources){
let data = /*serialize stuff*/;
resources.get_mut::<LastSaveData>().unwrap().0 = Some(data);
}
}
impl SaveCommandExt for Commands {
fn save(&mut self) {
self.add_command(SaveCommand)
}
}
Usage:
fn regular_system(commands: &mut Commands) {
commands.save();
}
What alternative(s) have you considered?
Clearly document an idiomatic way to do this.
Additional context
Here's an example of a new user trying to implement this on their own and stumbling.
This issue relates directly to #255.