diff --git a/src/infos.rs b/src/infos.rs index f5cd10b..91ba69e 100644 --- a/src/infos.rs +++ b/src/infos.rs @@ -35,26 +35,26 @@ impl CommandManager { } pub fn remove_iwad(&mut self) { self.iwad = None; - let _ = self.generate_command_str(); + self.update_command(); } pub fn add_iwad(&mut self, iwad: &WadInfo) { self.iwad = Some(iwad.path.clone()); - let _ = self.generate_command_str(); + self.update_command(); } pub fn add_pwads(&mut self, pwads: &Vec<&WadInfo>) { self.pwads = Vec::new(); for pwad in pwads { self.pwads.push(pwad.path.clone()); } - let _ = self.generate_command_str(); + self.update_command(); } pub fn add_launcher(&mut self, launcher: &LauncherInfo) { self.launcher = Some(launcher.path.clone()); - let _ = self.generate_command_str(); + self.update_command(); } pub fn remove_launcher(&mut self) { self.launcher = None; - let _ = self.generate_command_str(); + self.update_command(); } pub fn generate_command(&self) -> Result<(String, Vec), CommandErrors> { let launcher = if let Some(launcher) = &self.launcher { @@ -93,7 +93,8 @@ impl CommandManager { } Ok((launcher.to_str().unwrap().to_string(), command)) } - pub fn generate_command_str(&mut self) -> Result<(), CommandErrors> { + + pub fn update_command(&mut self) { match self.generate_command() { Err(e) => { self.command_string = "plz add ".to_string(); @@ -112,7 +113,6 @@ impl CommandManager { self.command_string = command; } } - Ok(()) } } diff --git a/src/main.rs b/src/main.rs index 0f090f1..fb49d84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,6 +42,8 @@ struct RustDoomLauncher { add_stuff_window_displayed: bool, selected_file_type: FileType, selected_file_path: PathBuf, + save_config_window_displayed: bool, + close_application: bool, } impl Default for RustDoomLauncher { @@ -58,6 +60,8 @@ impl Default for RustDoomLauncher { add_stuff_window_displayed: false, selected_file_type: FileType::Pwad, selected_file_path: PathBuf::new(), + save_config_window_displayed: false, + close_application: false, } } } @@ -128,13 +132,8 @@ impl RustDoomLauncher { impl eframe::App for RustDoomLauncher { fn on_close_event(&mut self) -> bool { - let config = Config { - iwads: Some(self.iwad_manager.selectable.clone()), - pwads: Some(self.pwad_manager.selectable.clone()), - launchers: Some(self.launcher_manager.selectable.clone()), - }; - save_config(&self.config_filename, &config).unwrap(); - true + self.save_config_window_displayed = true; + self.close_application } fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) { @@ -270,19 +269,20 @@ impl eframe::App for RustDoomLauncher { ui.horizontal(|ui| { ui.set_max_width(180.0); let warp_label = ui.label("warp"); - let r = ui.text_edit_singleline(&mut self.command_manager.warp) + let r = ui + .text_edit_singleline(&mut self.command_manager.warp) .labelled_by(warp_label.id); if r.changed() { - let _ = self.command_manager.generate_command_str(); + self.command_manager.update_command(); } }); ui.separator(); ui.horizontal(|ui| { ui.horizontal(|ui| { ui.label("difficulty"); - ui.set_max_width(180.0); eframe::egui::ComboBox::new("difficulty", "") .selected_text(format!("{}", self.command_manager.difficulty)) + .width(140.0) .show_ui(ui, |ui| { for diff in Difficulty::iterator() { let r = ui.selectable_value( @@ -291,7 +291,7 @@ impl eframe::App for RustDoomLauncher { diff.to_string(), ); if r.clicked() { - let _ = self.command_manager.generate_command_str(); + self.command_manager.update_command(); } } }); @@ -299,17 +299,21 @@ impl eframe::App for RustDoomLauncher { ui.separator(); ui.horizontal(|ui| { ui.label("fast"); - let r = ui.add(egui::Checkbox::without_text(&mut self.command_manager.fast_monsters)); + let r = ui.add(egui::Checkbox::without_text( + &mut self.command_manager.fast_monsters, + )); if r.clicked() { - let _ = self.command_manager.generate_command_str(); + self.command_manager.update_command(); } }); ui.separator(); ui.horizontal(|ui| { ui.label("respawn"); - let r = ui.add(egui::Checkbox::without_text(&mut self.command_manager.respawning_monsters)); + let r = ui.add(egui::Checkbox::without_text( + &mut self.command_manager.respawning_monsters, + )); if r.clicked() { - let _ = self.command_manager.generate_command_str(); + self.command_manager.update_command(); } }); }); @@ -365,6 +369,36 @@ impl eframe::App for RustDoomLauncher { } }); + if self.save_config_window_displayed { + egui::Window::new("Save WADs?") + .collapsible(false) + .resizable(false) + .show(ctx, |ui| { + ui.vertical(|ui| { + ui.label("Would you like to save the WADs you've added/deleted?"); + ui.horizontal(|ui| { + if ui.button("Yes").clicked() { + self.close_application = true; + let config = Config { + iwads: Some(self.iwad_manager.selectable.clone()), + pwads: Some(self.pwad_manager.selectable.clone()), + launchers: Some(self.launcher_manager.selectable.clone()), + }; + save_config(&self.config_filename, &config).unwrap(); + frame.close(); + } + if ui.button("No").clicked() { + self.close_application = true; + frame.close(); + }; + if ui.button("Don't Quit").clicked() { + self.save_config_window_displayed = false; + }; + }); + }); + }); + } + egui::Window::new("Add WAD or Launcher") .open(&mut self.add_stuff_window_displayed) .show(ctx, |ui| { diff --git a/src/wad.rs b/src/wad.rs index cde09aa..5eae1e0 100644 --- a/src/wad.rs +++ b/src/wad.rs @@ -51,7 +51,7 @@ pub struct WadThingLump { pub struct OpenWad { path: PathBuf, - header: WadHeader, + _header: WadHeader, nice_lumps: Vec, level_indicies: Vec, } @@ -59,6 +59,7 @@ pub struct OpenWad { pub fn open_wad(path: &PathBuf) -> OpenWad { let mut file = BufReader::new(File::open(path).unwrap()); let header: WadHeader = bincode::deserialize_from(&mut file).unwrap(); + assert!(header.identifier == *b"IWAD" || header.identifier == *b"PWAD"); file.seek(SeekFrom::Start(header.file_offset_to_start as u64)) .unwrap(); let mut nice_lumps: Vec = Vec::new(); @@ -84,7 +85,7 @@ pub fn open_wad(path: &PathBuf) -> OpenWad { } OpenWad { path: path.clone(), - header, + _header: header, nice_lumps, level_indicies, } @@ -171,7 +172,7 @@ pub enum Enemy { } impl Enemy { - fn difficulty_value(enemy: &Self) -> u16 { + pub fn difficulty_value(enemy: &Self) -> u16 { match enemy { Self::FormerHuman => 2, Self::WolfensteinSs => 2, @@ -198,7 +199,7 @@ impl Enemy { } impl HealthAndArmour { - fn health_value(hoa: &Self) -> u16 { + pub fn health_value(hoa: &Self) -> u16 { match hoa { Self::Beserk => 100, Self::Stimpack => 10, @@ -272,8 +273,8 @@ mod tests { "WAD test need freedoom1.wad - get it from here https://freedoom.github.io" ); let ow = open_wad(&freedoom_iwad); - assert_eq!(&ow.header.identifier, b"IWAD"); - assert_eq!(std::str::from_utf8(&ow.header.identifier).unwrap(), "IWAD"); + assert_eq!(&ow._header.identifier, b"IWAD"); + assert_eq!(std::str::from_utf8(&ow._header.identifier).unwrap(), "IWAD"); } #[test] @@ -327,7 +328,7 @@ mod tests { #[test] fn test_struct_size() { // This probably isn't really neccesary... but it might catch a mistake, maybe? - // These shouldn't compile if the size is incorrect (I think) + // These shouldn't compile if the size is incorrect const _HS: [u8; 12] = [0; std::mem::size_of::()]; const _LDS: [u8; 16] = [0; std::mem::size_of::()]; const _WTL: [u8; 10] = [0; std::mem::size_of::()];