Added a launcher button

Still doesn't use the extra flags like warp etc.
This commit is contained in:
2023-06-05 20:53:13 +01:00
parent 9eea5d9416
commit f8fa25a2fb

View File

@@ -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,7 +104,7 @@ 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
}
@@ -93,7 +114,12 @@ impl eframe::App for RustDoomLauncher {
self.config_file_loaded = true;
}
egui::containers::panel::CentralPanel::default().show(ctx, |ui| {
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| {