Partially done removing config parts

This commit is contained in:
2023-10-18 23:38:48 +01:00
parent 603b65ada6
commit 6122f99ff7
3 changed files with 55 additions and 156 deletions

View File

@@ -1,5 +1,4 @@
use config::{default_save_filename, load_config, save_config, Config};
use wad::get_summary;
use config::{default_config_filename, load_config, Config};
use eframe::egui;
use eframe::egui::Color32;
use infos::{
@@ -44,8 +43,6 @@ 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 {
@@ -56,44 +53,30 @@ impl Default for RustDoomLauncher {
pwad_manager: MultiManager::new(),
command_manager: CommandManager::default(),
add_name: "".to_string(),
config_filename: default_save_filename(),
config_filename: default_config_filename(),
config: None, // TODO: put the config_filename in the config stuct - or something
config_tried: false,
display_command: false,
add_stuff_window_displayed: false,
selected_file_type: FileType::Pwad,
selected_file_path: PathBuf::new(),
save_config_window_displayed: false,
close_application: false,
}
}
}
impl RustDoomLauncher {
// There must be a better way than this - maybe for the RustDoomLauncher to
// have a config thing
fn get_config_file_stuff(&mut self) {
self.config = match load_config(&self.config_filename) {
Ok(c) => Some(c),
Err(_e) => None,
// TODO - Throw some kind of error if a config file isn't found and/or missing iwad folder
match load_config(&self.config_filename) {
Ok(c) => {
if let Some(launchers) = &c.launchers {
for launcher in launchers {
self.launcher_manager.add(&launcher);
}
}
},
Err(_e) => {},
};
if let Some(config) = &self.config {
if let Some(iwads) = &config.iwads {
for iwad in iwads {
self.iwad_manager.add(&iwad);
}
}
if let Some(pwads) = &config.pwads {
for pwad in pwads {
self.pwad_manager.add(&pwad.clone());
}
}
if let Some(launchers) = &config.launchers {
for launcher in launchers {
self.launcher_manager.add(&launcher);
}
}
}
}
fn launch_doom(&self) {
@@ -140,11 +123,6 @@ impl RustDoomLauncher {
}
impl eframe::App for RustDoomLauncher {
fn on_close_event(&mut self) -> bool {
self.save_config_window_displayed = true;
self.close_application
}
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
if !self.config_tried {
self.get_config_file_stuff();
@@ -371,37 +349,6 @@ 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()),
..Default::default()
};
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| {