Fixed the flag/command line stuff

Also added it all into the command_manager thing so the App struct
doesn't look quite so busy
This commit is contained in:
2023-07-04 23:34:34 +01:00
parent 061a987060
commit 6004df73f7
2 changed files with 54 additions and 35 deletions

View File

@@ -4,13 +4,12 @@ use std::path::PathBuf;
use std::slice::Iter; use std::slice::Iter;
use std::cmp::Ordering; use std::cmp::Ordering;
#[derive(Default)]
pub struct CommandManager { pub struct CommandManager {
pub launcher: Option<PathBuf>, pub launcher: Option<PathBuf>,
pub iwad: Option<PathBuf>, pub iwad: Option<PathBuf>,
pub pwads: Vec<PathBuf>, pub pwads: Vec<PathBuf>,
pub warp: String, pub warp: String,
pub difficulty: Option<Difficulty>, pub difficulty: Difficulty,
pub fast_monsters: bool, pub fast_monsters: bool,
pub respawning_monsters: bool, pub respawning_monsters: bool,
pub command_string: String, pub command_string: String,
@@ -28,7 +27,7 @@ impl CommandManager {
iwad: None, iwad: None,
pwads: Vec::new(), pwads: Vec::new(),
warp: "".to_string(), warp: "".to_string(),
difficulty: None, difficulty: Difficulty::None,
fast_monsters: false, fast_monsters: false,
respawning_monsters: false, respawning_monsters: false,
command_string: "".to_string(), command_string: "".to_string(),
@@ -73,13 +72,18 @@ impl CommandManager {
command.push("-file".to_string()); command.push("-file".to_string());
command.push(pwad.clone().into_os_string().into_string().unwrap()); command.push(pwad.clone().into_os_string().into_string().unwrap());
} }
if let Some(d) = self.difficulty { if self.difficulty != Difficulty::None {
command.push("-skill".to_string()); command.push("-skill".to_string());
command.push(d.flag_number().to_string()); command.push(self.difficulty.flag_number().to_string());
} }
if !self.warp.is_empty() { if !self.warp.is_empty() {
command.push("-warp".to_string()); command.push("-warp".to_string());
command.push(self.warp.to_string()); // Again, feel like there's must be a _much_ better way than this...
let warp_string = self.warp.to_string();
let strings: Vec<&str> = warp_string.split_whitespace().collect();
for string in strings {
command.push(string.to_string());
}
} }
if self.respawning_monsters { if self.respawning_monsters {
command.push("-respawn".to_string()); command.push("-respawn".to_string());

View File

@@ -38,10 +38,6 @@ struct RustDoomLauncher {
config_filename: PathBuf, config_filename: PathBuf,
config_file_loaded: bool, config_file_loaded: bool,
command_manager: CommandManager, command_manager: CommandManager,
warp_string: String,
difficulty: Difficulty,
fast_monsters: bool,
respawning_monsters: bool,
display_command: bool, display_command: bool,
add_stuff_window_displayed: bool, add_stuff_window_displayed: bool,
selected_file_type: FileType, selected_file_type: FileType,
@@ -58,10 +54,6 @@ impl Default for RustDoomLauncher {
add_name: "".to_string(), add_name: "".to_string(),
config_filename: default_save_filename(), config_filename: default_save_filename(),
config_file_loaded: false, config_file_loaded: false,
warp_string: String::new(),
difficulty: Difficulty::None,
fast_monsters: false,
respawning_monsters: false,
display_command: false, display_command: false,
add_stuff_window_displayed: false, add_stuff_window_displayed: false,
selected_file_type: FileType::Pwad, selected_file_type: FileType::Pwad,
@@ -267,42 +259,65 @@ impl eframe::App for RustDoomLauncher {
}); });
let mut text = "Placeholder for WAD info stuffs"; let mut text = "Placeholder for WAD info stuffs";
let window_size = frame.info().window_info.size; let window_size = frame.info().window_info.size;
ui.add(egui::TextEdit::multiline(&mut text).desired_width(window_size[0]/1.6).desired_rows(20)); ui.add(
egui::TextEdit::multiline(&mut text)
.desired_width(window_size[0] / 1.6)
.desired_rows(20),
);
}); });
ui.separator(); ui.separator();
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
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) let r = ui.text_edit_singleline(&mut self.command_manager.warp)
.labelled_by(warp_label.id); .labelled_by(warp_label.id);
if r.changed() {
let _ = self.command_manager.generate_command_str();
}
}); });
ui.separator(); ui.separator();
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("difficulty"); ui.horizontal(|ui| {
eframe::egui::ComboBox::new("difficulty", "") ui.label("difficulty");
.selected_text(format!("{}", self.difficulty)) ui.set_max_width(180.0);
.show_ui(ui, |ui| { eframe::egui::ComboBox::new("difficulty", "")
for diff in Difficulty::iterator() { .selected_text(format!("{}", self.command_manager.difficulty))
ui.selectable_value(&mut self.difficulty, *diff, diff.to_string()); .show_ui(ui, |ui| {
} for diff in Difficulty::iterator() {
}); let r = ui.selectable_value(
}); &mut self.command_manager.difficulty,
ui.separator(); *diff,
ui.horizontal(|ui| { diff.to_string(),
ui.label("fast"); );
ui.checkbox(&mut self.fast_monsters, ""); if r.clicked() {
}); let _ = self.command_manager.generate_command_str();
ui.separator(); }
ui.horizontal(|ui| { }
ui.label("respawn"); });
ui.checkbox(&mut self.respawning_monsters, ""); });
ui.separator();
ui.horizontal(|ui| {
ui.label("fast");
let r = ui.add(egui::Checkbox::without_text(&mut self.command_manager.fast_monsters));
if r.clicked() {
let _ = self.command_manager.generate_command_str();
}
});
ui.separator();
ui.horizontal(|ui| {
ui.label("respawn");
let r = ui.add(egui::Checkbox::without_text(&mut self.command_manager.respawning_monsters));
if r.clicked() {
let _ = self.command_manager.generate_command_str();
}
});
}); });
}); });
ui.separator(); ui.separator();
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label("Command"); ui.label("Command");
ui.checkbox(&mut self.display_command, ""); ui.add(egui::Checkbox::without_text(&mut self.display_command));
}); });
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
if let Some(l) = self.launcher_manager.get_current() { if let Some(l) = self.launcher_manager.get_current() {