From f8fa25a2fbf366cc75a8d00c3d00bd730b47a8ed Mon Sep 17 00:00:00 2001 From: Arthur Roberts Date: Mon, 5 Jun 2023 20:53:13 +0100 Subject: [PATCH] Added a launcher button Still doesn't use the extra flags like warp etc. --- src/main.rs | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 34976d6..0bdab7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,8 @@ +use config::{default_save_filename, load_config, save_config, Config}; use eframe::egui; +use infos::{Difficulty, LauncherInfo, WadInfo}; use std::path::PathBuf; -use config::{default_save_filename, save_config, load_config, Config}; -use infos::{WadInfo, LauncherInfo, Difficulty}; +use std::process::Command; pub mod config; pub mod infos; @@ -74,6 +75,26 @@ impl RustDoomLauncher { } } } + + fn launch_doom(&self) -> () { + let launcher = match self.selected_launcher { + Some(l) => self.all_launchers.get(l).unwrap(), + None => panic!("Gotta pick a launcher!"), + }; + let iwad = match self.selected_iwad { + Some(i) => self.all_iwads.get(i).unwrap(), + None => panic!("Gotta pick and iwad"), + }; + let mut command = vec!["-iwad", iwad.path.to_str().unwrap()]; + for pwad_index in &self.selected_pwads { + command.push("-file"); + let pwad = self.all_pwads.get(*pwad_index).unwrap(); + command.push(pwad.path.to_str().unwrap()); + } + Command::new(launcher.path.to_str().unwrap()) + .args(command) + .spawn(); + } } impl eframe::App for RustDoomLauncher { @@ -83,17 +104,22 @@ impl eframe::App for RustDoomLauncher { pwads: Some(self.all_pwads.clone()), launchers: Some(self.all_launchers.clone()), }; - save_config(&self.config_filename, &config); + save_config(&self.config_filename, &config).unwrap(); true } - + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { if self.config_file_loaded == false { self.get_config_file_stuff(); self.config_file_loaded = true; } egui::containers::panel::CentralPanel::default().show(ctx, |ui| { - ui.heading("RustDoomLauncher"); + ui.horizontal(|ui| { + ui.heading("RustDoomLauncher"); + if ui.button("PLAY SOME DOOM!").clicked() { + self.launch_doom(); + } + }); ui.horizontal_wrapped(|ui| { ui.vertical(|ui| { ui.label("Launchers"); @@ -156,7 +182,7 @@ impl eframe::App for RustDoomLauncher { // to pass both of these vaules in, or what the story is here. let get_name = |path: &PathBuf, name: &String| { if self.name.is_empty() { - // Check this perhaps? Unsure whether the FileDialog can actually + // Check these unwraps perhaps? Unsure whether the FileDialog can actually // return something that isn't a file path.file_name().unwrap().to_str().unwrap().to_string() } else { @@ -195,7 +221,8 @@ impl eframe::App for RustDoomLauncher { ui.horizontal(|ui| { ui.set_max_width(180.0); let warp_label = ui.label("warp"); - ui.text_edit_singleline(&mut self.warp_string).labelled_by(warp_label.id); + ui.text_edit_singleline(&mut self.warp_string) + .labelled_by(warp_label.id); }); ui.separator(); ui.horizontal(|ui| {