Skip to content

Repository files navigation

AGB Save Controller

Uses two slot saving system, like GBA pokemon games, to reduce the risk of save corruption.

Usage

// Define your save struct and versionconstSAVE_VERSION:u8 = 1;structGameSave{money:u16,pos:(u8,u8)}// Impl SaveEncoding for your structimplGbaSaveforGameSave{//size of save data in bytesconstSIZE:usize = 4;//write the object into the slice however you wantfnencode_into(&self,out:&mut[u8]){
out[0] = pos.0;
out[1] = pos.1;//etc}//create the object from the slice however you wantfndecode_from(bytes:&[u8]) -> Self{let pos = (out[0], out[1]);//etc}}#[agb::entry]fnmain(mutgba: agb::Gba) -> ! {//call one of the init methods such as
gba.save.init_flash_64k();//then create the save controllerletmut save_controller = OwnedSaveController::new(&mut gba.save,SAVE_VERSION).unwrap();if save_controller.load().unwrap() == ManagedLoadResult::NoSave{//no save found so initialize data
save_controller.set_data(MyGameSave{money:100,pos:(10,10)});}
agb::println!("You have ${}", save_controller.data().unwrap().money);
save_controller.data_mut().map(|save| save.money += 100);
save_controller.save().unwrap();}

About

Two slot save controller for AGB

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages