Skip to content

Commit

Permalink
Adding helper function for getting Savefilepath (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
silverhadch authored and Amjad50 committed Oct 23, 2024
1 parent 292ae84 commit db5be91
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions plastic_tui/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,31 +161,28 @@ impl Ui {
}

fn save_state(&mut self, slot: u8) {
if self.nes.is_empty() {
return;
if let Some(path) = self.get_save_state_path(slot) {
let file = fs::File::create(&path).unwrap();
self.nes.save_state(&file).unwrap();
}

let base_saved_states_dir = base_save_state_folder().unwrap();
let filename = self.nes.save_state_file_name(slot).unwrap();
let path = base_saved_states_dir.join(&filename);

let file = fs::File::create(&path).unwrap();

self.nes.save_state(&file).unwrap();
}

fn load_state(&mut self, slot: u8) {
if self.nes.is_empty() {
return;
if let Some(path) = self.get_save_state_path(slot) {
let file = fs::File::open(&path).unwrap();
self.nes.load_state(&file).unwrap();
}
}

let base_saved_states_dir = base_save_state_folder().unwrap();
let filename = self.nes.save_state_file_name(slot).unwrap();
let path = base_saved_states_dir.join(&filename);
fn get_save_state_path(&self, slot: u8) -> Option<std::path::PathBuf> {
if self.nes.is_empty() {
return None;
}

let file = fs::File::open(&path).unwrap();
let base_saved_states_dir = base_save_state_folder()?;
let filename = self.nes.save_state_file_name(slot)?;

self.nes.load_state(&file).unwrap();
Some(base_saved_states_dir.join(filename))
}

fn reset_menu(&mut self) {
Expand Down Expand Up @@ -536,7 +533,6 @@ impl Ui {
thread::sleep(remaining);
}
}

disable_raw_mode().unwrap();
execute!(
io::stdout(),
Expand Down

0 comments on commit db5be91

Please sign in to comment.