Skip to content

Commit

Permalink
create save file if not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed Jun 12, 2024
1 parent 5af2ab9 commit 42653b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion pets-lib/src/stats/savefiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ impl SaveFile {

pub fn load_from(save_slot: u8) -> io::Result<Self> {
let path = save_path(save_slot);
let mut file = GFile::open(path, ModeFlags::READ)?;
let Ok(mut file) = GFile::open(path, ModeFlags::READ) else {
let new_save = Self::fresh();
new_save.write_to(save_slot);
return Ok(new_save);
};

let mut content = vec![];
file.read_to_end(&mut content);
Expand Down
12 changes: 5 additions & 7 deletions pets-lib/src/title_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl TitleScreen {
}

#[func]
fn on_save_file_picked(&mut self, slot: u64) {
fn on_save_file_picked(&mut self, choice: Gd<Control>) {
let slot = choice.get_name().to_string().parse::<usize>().unwrap();
godot_print!("{}", slot);

let save = SaveFile::load_from(slot as u8).unwrap();
Expand Down Expand Up @@ -148,12 +149,9 @@ impl INode2D for TitleScreen {
let callable = self.base().callable("on_choice_picked");
connect_deferred(&mut self.choices, "selection_confirmed", callable);

let _callable = self.base().callable("on_save_file_picked");

// for (i, mut v) in self.save_buttons().into_iter().enumerate() {
// let callable = callable.bindv(varray![i as u64 + 1]);
// v.connect("".into(), callable);
// }
let callable = self.base().callable("on_save_file_picked");
self.save_choices
.connect("selection_confirmed".into(), callable);
}

fn input(&mut self, event: Gd<InputEvent>) {
Expand Down

0 comments on commit 42653b8

Please sign in to comment.