Adding flags
This commit is contained in:
@@ -8,7 +8,9 @@ edition = "2021"
|
||||
[dependencies]
|
||||
directories = "5.0.1"
|
||||
eframe = "0.21.3"
|
||||
native-dialog = "0.6.3"
|
||||
rfd = "0.11.4"
|
||||
serde = "1.0.163"
|
||||
serde_derive = "1.0.163"
|
||||
shell-escape = "0.1.5"
|
||||
toml = "0.7.4"
|
||||
|
||||
10
src/infos.rs
10
src/infos.rs
@@ -55,4 +55,14 @@ impl Difficulty {
|
||||
];
|
||||
DIFFICULTIES.iter()
|
||||
}
|
||||
pub fn flag_number(&self) -> &str {
|
||||
match self {
|
||||
Difficulty::None => "0",
|
||||
Difficulty::Baby => "1",
|
||||
Difficulty::Easy => "2",
|
||||
Difficulty::Medium => "3",
|
||||
Difficulty::Hard => "4",
|
||||
Difficulty::Nightmare => "5",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
83
src/main.rs
83
src/main.rs
@@ -1,6 +1,7 @@
|
||||
use config::{default_save_filename, load_config, save_config, Config};
|
||||
use eframe::egui;
|
||||
use infos::{Difficulty, LauncherInfo, WadInfo};
|
||||
use native_dialog::{MessageDialog, MessageType};
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
@@ -32,6 +33,13 @@ struct RustDoomLauncher {
|
||||
difficulty: Difficulty,
|
||||
fast_monsters: bool,
|
||||
respawning_monsters: bool,
|
||||
display_command: bool,
|
||||
}
|
||||
|
||||
// Great name, I know
|
||||
enum MyErrors {
|
||||
NoLauncher,
|
||||
NoIwad,
|
||||
}
|
||||
|
||||
impl Default for RustDoomLauncher {
|
||||
@@ -50,6 +58,7 @@ impl Default for RustDoomLauncher {
|
||||
difficulty: Difficulty::None,
|
||||
fast_monsters: false,
|
||||
respawning_monsters: false,
|
||||
display_command: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,14 +85,34 @@ impl RustDoomLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
fn launch_doom(&self) -> () {
|
||||
fn get_launcher_and_command(&self, show_dialogs: bool) -> Result<(&str, Vec<&str>), MyErrors> {
|
||||
let launcher = match self.selected_launcher {
|
||||
Some(l) => self.all_launchers.get(l).unwrap(),
|
||||
None => panic!("Gotta pick a launcher!"),
|
||||
None => {
|
||||
if show_dialogs {
|
||||
MessageDialog::new()
|
||||
.set_type(MessageType::Error)
|
||||
.set_title("I can't let you do that")
|
||||
.set_text("You didn't pick a launcher!\nPlease do that")
|
||||
.show_alert()
|
||||
.unwrap();
|
||||
}
|
||||
return Err(MyErrors::NoLauncher);
|
||||
}
|
||||
};
|
||||
let iwad = match self.selected_iwad {
|
||||
Some(i) => self.all_iwads.get(i).unwrap(),
|
||||
None => panic!("Gotta pick and iwad"),
|
||||
None => {
|
||||
if show_dialogs {
|
||||
MessageDialog::new()
|
||||
.set_type(MessageType::Error)
|
||||
.set_title("I can't let you do that")
|
||||
.set_text("You didn't pick an IWAD!\nPlease do that")
|
||||
.show_alert()
|
||||
.unwrap();
|
||||
}
|
||||
return Err(MyErrors::NoIwad);
|
||||
}
|
||||
};
|
||||
let mut command = vec!["-iwad", iwad.path.to_str().unwrap()];
|
||||
for pwad_index in &self.selected_pwads {
|
||||
@@ -91,9 +120,37 @@ impl RustDoomLauncher {
|
||||
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();
|
||||
if self.difficulty != Difficulty::None {
|
||||
command.push("-skill");
|
||||
command.push(self.difficulty.flag_number());
|
||||
}
|
||||
if !self.warp_string.is_empty() {
|
||||
command.push("-warp");
|
||||
command.push(&self.warp_string);
|
||||
}
|
||||
if self.respawning_monsters {
|
||||
command.push("-respawn");
|
||||
}
|
||||
Ok((launcher.path.to_str().unwrap(), command))
|
||||
}
|
||||
|
||||
fn form_command_string(&self) -> String {
|
||||
match self.get_launcher_and_command(false) {
|
||||
Ok((launch, comms)) => {
|
||||
//TODO - escape all the strings
|
||||
let c = comms.join(" ");
|
||||
format!("{} {}", launch, c)
|
||||
}
|
||||
Err(MyErrors::NoLauncher) => "Error: No launcher".to_string(),
|
||||
Err(MyErrors::NoIwad) => "Error: No IWAD".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
fn launch_doom(&self) -> () {
|
||||
if let Ok((launcher, command)) = self.get_launcher_and_command(true) {
|
||||
// Note to self, don't hit launch button when running from emacs
|
||||
Command::new(launcher).args(command).spawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +165,7 @@ impl eframe::App for RustDoomLauncher {
|
||||
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 {
|
||||
self.get_config_file_stuff();
|
||||
self.config_file_loaded = true;
|
||||
@@ -247,7 +304,10 @@ impl eframe::App for RustDoomLauncher {
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
ui.label("Command");
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Command");
|
||||
ui.checkbox(&mut self.display_command, "");
|
||||
});
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
// I don't actually think using SelectableLabel is correct here -
|
||||
// but it'll at least do the highlighting when hovered nicely
|
||||
@@ -300,6 +360,13 @@ impl eframe::App for RustDoomLauncher {
|
||||
pos += 1;
|
||||
}
|
||||
});
|
||||
if self.display_command {
|
||||
ui.horizontal(|ui| {
|
||||
let mut text = self.form_command_string();
|
||||
let window_size = frame.info().window_info.size;
|
||||
ui.add(egui::TextEdit::multiline(&mut text).desired_width(window_size[0] * 0.9));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user