Added a launcher button
Still doesn't use the extra flags like warp etc.
This commit is contained in:
41
src/main.rs
41
src/main.rs
@@ -1,7 +1,8 @@
|
|||||||
|
use config::{default_save_filename, load_config, save_config, Config};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
use infos::{Difficulty, LauncherInfo, WadInfo};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use config::{default_save_filename, save_config, load_config, Config};
|
use std::process::Command;
|
||||||
use infos::{WadInfo, LauncherInfo, Difficulty};
|
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod infos;
|
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 {
|
impl eframe::App for RustDoomLauncher {
|
||||||
@@ -83,17 +104,22 @@ impl eframe::App for RustDoomLauncher {
|
|||||||
pwads: Some(self.all_pwads.clone()),
|
pwads: Some(self.all_pwads.clone()),
|
||||||
launchers: Some(self.all_launchers.clone()),
|
launchers: Some(self.all_launchers.clone()),
|
||||||
};
|
};
|
||||||
save_config(&self.config_filename, &config);
|
save_config(&self.config_filename, &config).unwrap();
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
if self.config_file_loaded == false {
|
if self.config_file_loaded == false {
|
||||||
self.get_config_file_stuff();
|
self.get_config_file_stuff();
|
||||||
self.config_file_loaded = true;
|
self.config_file_loaded = true;
|
||||||
}
|
}
|
||||||
egui::containers::panel::CentralPanel::default().show(ctx, |ui| {
|
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.horizontal_wrapped(|ui| {
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
ui.label("Launchers");
|
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.
|
// to pass both of these vaules in, or what the story is here.
|
||||||
let get_name = |path: &PathBuf, name: &String| {
|
let get_name = |path: &PathBuf, name: &String| {
|
||||||
if self.name.is_empty() {
|
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
|
// return something that isn't a file
|
||||||
path.file_name().unwrap().to_str().unwrap().to_string()
|
path.file_name().unwrap().to_str().unwrap().to_string()
|
||||||
} else {
|
} else {
|
||||||
@@ -195,7 +221,8 @@ impl eframe::App for RustDoomLauncher {
|
|||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.set_max_width(180.0);
|
ui.set_max_width(180.0);
|
||||||
let warp_label = ui.label("warp");
|
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.separator();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
|||||||
Reference in New Issue
Block a user