Starting to refactor config stuff

So that I can add in a "Added WADs" and "Removed WADs"
This commit is contained in:
2023-07-10 21:25:57 +01:00
parent 745c560409
commit 418daae284
3 changed files with 52 additions and 29 deletions

View File

@@ -36,7 +36,8 @@ struct RustDoomLauncher {
pwad_manager: MultiManager<WadInfo>,
add_name: String,
config_filename: PathBuf,
config_file_loaded: bool,
config: Option<Config>,
config_tried: bool,
command_manager: CommandManager,
display_command: bool,
add_stuff_window_displayed: bool,
@@ -55,7 +56,8 @@ impl Default for RustDoomLauncher {
command_manager: CommandManager::default(),
add_name: "".to_string(),
config_filename: default_save_filename(),
config_file_loaded: false,
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,
@@ -70,22 +72,27 @@ 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) {
let config = load_config(&self.config_filename).unwrap();
if let Some(iwads) = config.iwads {
self.config = match load_config(&self.config_filename) {
Ok(c) => Some(c),
Err(e) => None,
};
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 {
if let Some(pwads) = &config.pwads {
for pwad in pwads {
self.pwad_manager.add(&pwad.clone());
}
}
if let Some(launchers) = config.launchers {
if let Some(launchers) = &config.launchers {
for launcher in launchers {
self.launcher_manager.add(&launcher);
}
}
}
}
fn launch_doom(&self) {
@@ -138,10 +145,10 @@ impl eframe::App for RustDoomLauncher {
}
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
if !self.config_file_loaded {
if !self.config_tried {
self.get_config_file_stuff();
self.config_file_loaded = true;
}
self.config_tried = true;
};
egui::containers::panel::CentralPanel::default().show(ctx, |ui| {
ui.horizontal(|ui| {
ui.heading("RustDoomLauncher");
@@ -384,6 +391,8 @@ impl eframe::App for RustDoomLauncher {
iwads: Some(self.iwad_manager.selectable.clone()),
pwads: Some(self.pwad_manager.selectable.clone()),
launchers: Some(self.launcher_manager.selectable.clone()),
iwads_added_folder: None,
iwads_removed_folder: None,
};
save_config(&self.config_filename, &config).unwrap();
frame.close();