Fixed pointess generate_str function return
Also added a nice little helpful close window thingy
This commit is contained in:
14
src/infos.rs
14
src/infos.rs
@@ -35,26 +35,26 @@ impl CommandManager {
|
|||||||
}
|
}
|
||||||
pub fn remove_iwad(&mut self) {
|
pub fn remove_iwad(&mut self) {
|
||||||
self.iwad = None;
|
self.iwad = None;
|
||||||
let _ = self.generate_command_str();
|
self.update_command();
|
||||||
}
|
}
|
||||||
pub fn add_iwad(&mut self, iwad: &WadInfo) {
|
pub fn add_iwad(&mut self, iwad: &WadInfo) {
|
||||||
self.iwad = Some(iwad.path.clone());
|
self.iwad = Some(iwad.path.clone());
|
||||||
let _ = self.generate_command_str();
|
self.update_command();
|
||||||
}
|
}
|
||||||
pub fn add_pwads(&mut self, pwads: &Vec<&WadInfo>) {
|
pub fn add_pwads(&mut self, pwads: &Vec<&WadInfo>) {
|
||||||
self.pwads = Vec::new();
|
self.pwads = Vec::new();
|
||||||
for pwad in pwads {
|
for pwad in pwads {
|
||||||
self.pwads.push(pwad.path.clone());
|
self.pwads.push(pwad.path.clone());
|
||||||
}
|
}
|
||||||
let _ = self.generate_command_str();
|
self.update_command();
|
||||||
}
|
}
|
||||||
pub fn add_launcher(&mut self, launcher: &LauncherInfo) {
|
pub fn add_launcher(&mut self, launcher: &LauncherInfo) {
|
||||||
self.launcher = Some(launcher.path.clone());
|
self.launcher = Some(launcher.path.clone());
|
||||||
let _ = self.generate_command_str();
|
self.update_command();
|
||||||
}
|
}
|
||||||
pub fn remove_launcher(&mut self) {
|
pub fn remove_launcher(&mut self) {
|
||||||
self.launcher = None;
|
self.launcher = None;
|
||||||
let _ = self.generate_command_str();
|
self.update_command();
|
||||||
}
|
}
|
||||||
pub fn generate_command(&self) -> Result<(String, Vec<String>), CommandErrors> {
|
pub fn generate_command(&self) -> Result<(String, Vec<String>), CommandErrors> {
|
||||||
let launcher = if let Some(launcher) = &self.launcher {
|
let launcher = if let Some(launcher) = &self.launcher {
|
||||||
@@ -93,7 +93,8 @@ impl CommandManager {
|
|||||||
}
|
}
|
||||||
Ok((launcher.to_str().unwrap().to_string(), command))
|
Ok((launcher.to_str().unwrap().to_string(), command))
|
||||||
}
|
}
|
||||||
pub fn generate_command_str(&mut self) -> Result<(), CommandErrors> {
|
|
||||||
|
pub fn update_command(&mut self) {
|
||||||
match self.generate_command() {
|
match self.generate_command() {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.command_string = "plz add ".to_string();
|
self.command_string = "plz add ".to_string();
|
||||||
@@ -112,7 +113,6 @@ impl CommandManager {
|
|||||||
self.command_string = command;
|
self.command_string = command;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
64
src/main.rs
64
src/main.rs
@@ -42,6 +42,8 @@ struct RustDoomLauncher {
|
|||||||
add_stuff_window_displayed: bool,
|
add_stuff_window_displayed: bool,
|
||||||
selected_file_type: FileType,
|
selected_file_type: FileType,
|
||||||
selected_file_path: PathBuf,
|
selected_file_path: PathBuf,
|
||||||
|
save_config_window_displayed: bool,
|
||||||
|
close_application: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RustDoomLauncher {
|
impl Default for RustDoomLauncher {
|
||||||
@@ -58,6 +60,8 @@ impl Default for RustDoomLauncher {
|
|||||||
add_stuff_window_displayed: false,
|
add_stuff_window_displayed: false,
|
||||||
selected_file_type: FileType::Pwad,
|
selected_file_type: FileType::Pwad,
|
||||||
selected_file_path: PathBuf::new(),
|
selected_file_path: PathBuf::new(),
|
||||||
|
save_config_window_displayed: false,
|
||||||
|
close_application: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -128,13 +132,8 @@ impl RustDoomLauncher {
|
|||||||
|
|
||||||
impl eframe::App for RustDoomLauncher {
|
impl eframe::App for RustDoomLauncher {
|
||||||
fn on_close_event(&mut self) -> bool {
|
fn on_close_event(&mut self) -> bool {
|
||||||
let config = Config {
|
self.save_config_window_displayed = true;
|
||||||
iwads: Some(self.iwad_manager.selectable.clone()),
|
self.close_application
|
||||||
pwads: Some(self.pwad_manager.selectable.clone()),
|
|
||||||
launchers: Some(self.launcher_manager.selectable.clone()),
|
|
||||||
};
|
|
||||||
save_config(&self.config_filename, &config).unwrap();
|
|
||||||
true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||||
@@ -270,19 +269,20 @@ 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");
|
||||||
let r = ui.text_edit_singleline(&mut self.command_manager.warp)
|
let r = ui
|
||||||
|
.text_edit_singleline(&mut self.command_manager.warp)
|
||||||
.labelled_by(warp_label.id);
|
.labelled_by(warp_label.id);
|
||||||
if r.changed() {
|
if r.changed() {
|
||||||
let _ = self.command_manager.generate_command_str();
|
self.command_manager.update_command();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("difficulty");
|
ui.label("difficulty");
|
||||||
ui.set_max_width(180.0);
|
|
||||||
eframe::egui::ComboBox::new("difficulty", "")
|
eframe::egui::ComboBox::new("difficulty", "")
|
||||||
.selected_text(format!("{}", self.command_manager.difficulty))
|
.selected_text(format!("{}", self.command_manager.difficulty))
|
||||||
|
.width(140.0)
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
for diff in Difficulty::iterator() {
|
for diff in Difficulty::iterator() {
|
||||||
let r = ui.selectable_value(
|
let r = ui.selectable_value(
|
||||||
@@ -291,7 +291,7 @@ impl eframe::App for RustDoomLauncher {
|
|||||||
diff.to_string(),
|
diff.to_string(),
|
||||||
);
|
);
|
||||||
if r.clicked() {
|
if r.clicked() {
|
||||||
let _ = self.command_manager.generate_command_str();
|
self.command_manager.update_command();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -299,17 +299,21 @@ impl eframe::App for RustDoomLauncher {
|
|||||||
ui.separator();
|
ui.separator();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("fast");
|
ui.label("fast");
|
||||||
let r = ui.add(egui::Checkbox::without_text(&mut self.command_manager.fast_monsters));
|
let r = ui.add(egui::Checkbox::without_text(
|
||||||
|
&mut self.command_manager.fast_monsters,
|
||||||
|
));
|
||||||
if r.clicked() {
|
if r.clicked() {
|
||||||
let _ = self.command_manager.generate_command_str();
|
self.command_manager.update_command();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ui.separator();
|
ui.separator();
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("respawn");
|
ui.label("respawn");
|
||||||
let r = ui.add(egui::Checkbox::without_text(&mut self.command_manager.respawning_monsters));
|
let r = ui.add(egui::Checkbox::without_text(
|
||||||
|
&mut self.command_manager.respawning_monsters,
|
||||||
|
));
|
||||||
if r.clicked() {
|
if r.clicked() {
|
||||||
let _ = self.command_manager.generate_command_str();
|
self.command_manager.update_command();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -365,6 +369,36 @@ impl eframe::App for RustDoomLauncher {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if self.save_config_window_displayed {
|
||||||
|
egui::Window::new("Save WADs?")
|
||||||
|
.collapsible(false)
|
||||||
|
.resizable(false)
|
||||||
|
.show(ctx, |ui| {
|
||||||
|
ui.vertical(|ui| {
|
||||||
|
ui.label("Would you like to save the WADs you've added/deleted?");
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if ui.button("Yes").clicked() {
|
||||||
|
self.close_application = true;
|
||||||
|
let config = Config {
|
||||||
|
iwads: Some(self.iwad_manager.selectable.clone()),
|
||||||
|
pwads: Some(self.pwad_manager.selectable.clone()),
|
||||||
|
launchers: Some(self.launcher_manager.selectable.clone()),
|
||||||
|
};
|
||||||
|
save_config(&self.config_filename, &config).unwrap();
|
||||||
|
frame.close();
|
||||||
|
}
|
||||||
|
if ui.button("No").clicked() {
|
||||||
|
self.close_application = true;
|
||||||
|
frame.close();
|
||||||
|
};
|
||||||
|
if ui.button("Don't Quit").clicked() {
|
||||||
|
self.save_config_window_displayed = false;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
egui::Window::new("Add WAD or Launcher")
|
egui::Window::new("Add WAD or Launcher")
|
||||||
.open(&mut self.add_stuff_window_displayed)
|
.open(&mut self.add_stuff_window_displayed)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
|
|||||||
15
src/wad.rs
15
src/wad.rs
@@ -51,7 +51,7 @@ pub struct WadThingLump {
|
|||||||
|
|
||||||
pub struct OpenWad {
|
pub struct OpenWad {
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
header: WadHeader,
|
_header: WadHeader,
|
||||||
nice_lumps: Vec<NiceWadLumpEntry>,
|
nice_lumps: Vec<NiceWadLumpEntry>,
|
||||||
level_indicies: Vec<usize>,
|
level_indicies: Vec<usize>,
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,7 @@ pub struct OpenWad {
|
|||||||
pub fn open_wad(path: &PathBuf) -> OpenWad {
|
pub fn open_wad(path: &PathBuf) -> OpenWad {
|
||||||
let mut file = BufReader::new(File::open(path).unwrap());
|
let mut file = BufReader::new(File::open(path).unwrap());
|
||||||
let header: WadHeader = bincode::deserialize_from(&mut file).unwrap();
|
let header: WadHeader = bincode::deserialize_from(&mut file).unwrap();
|
||||||
|
assert!(header.identifier == *b"IWAD" || header.identifier == *b"PWAD");
|
||||||
file.seek(SeekFrom::Start(header.file_offset_to_start as u64))
|
file.seek(SeekFrom::Start(header.file_offset_to_start as u64))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let mut nice_lumps: Vec<NiceWadLumpEntry> = Vec::new();
|
let mut nice_lumps: Vec<NiceWadLumpEntry> = Vec::new();
|
||||||
@@ -84,7 +85,7 @@ pub fn open_wad(path: &PathBuf) -> OpenWad {
|
|||||||
}
|
}
|
||||||
OpenWad {
|
OpenWad {
|
||||||
path: path.clone(),
|
path: path.clone(),
|
||||||
header,
|
_header: header,
|
||||||
nice_lumps,
|
nice_lumps,
|
||||||
level_indicies,
|
level_indicies,
|
||||||
}
|
}
|
||||||
@@ -171,7 +172,7 @@ pub enum Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Enemy {
|
impl Enemy {
|
||||||
fn difficulty_value(enemy: &Self) -> u16 {
|
pub fn difficulty_value(enemy: &Self) -> u16 {
|
||||||
match enemy {
|
match enemy {
|
||||||
Self::FormerHuman => 2,
|
Self::FormerHuman => 2,
|
||||||
Self::WolfensteinSs => 2,
|
Self::WolfensteinSs => 2,
|
||||||
@@ -198,7 +199,7 @@ impl Enemy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HealthAndArmour {
|
impl HealthAndArmour {
|
||||||
fn health_value(hoa: &Self) -> u16 {
|
pub fn health_value(hoa: &Self) -> u16 {
|
||||||
match hoa {
|
match hoa {
|
||||||
Self::Beserk => 100,
|
Self::Beserk => 100,
|
||||||
Self::Stimpack => 10,
|
Self::Stimpack => 10,
|
||||||
@@ -272,8 +273,8 @@ mod tests {
|
|||||||
"WAD test need freedoom1.wad - get it from here https://freedoom.github.io"
|
"WAD test need freedoom1.wad - get it from here https://freedoom.github.io"
|
||||||
);
|
);
|
||||||
let ow = open_wad(&freedoom_iwad);
|
let ow = open_wad(&freedoom_iwad);
|
||||||
assert_eq!(&ow.header.identifier, b"IWAD");
|
assert_eq!(&ow._header.identifier, b"IWAD");
|
||||||
assert_eq!(std::str::from_utf8(&ow.header.identifier).unwrap(), "IWAD");
|
assert_eq!(std::str::from_utf8(&ow._header.identifier).unwrap(), "IWAD");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -327,7 +328,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_struct_size() {
|
fn test_struct_size() {
|
||||||
// This probably isn't really neccesary... but it might catch a mistake, maybe?
|
// This probably isn't really neccesary... but it might catch a mistake, maybe?
|
||||||
// These shouldn't compile if the size is incorrect (I think)
|
// These shouldn't compile if the size is incorrect
|
||||||
const _HS: [u8; 12] = [0; std::mem::size_of::<WadHeader>()];
|
const _HS: [u8; 12] = [0; std::mem::size_of::<WadHeader>()];
|
||||||
const _LDS: [u8; 16] = [0; std::mem::size_of::<WadLumpDirectoryEntry>()];
|
const _LDS: [u8; 16] = [0; std::mem::size_of::<WadLumpDirectoryEntry>()];
|
||||||
const _WTL: [u8; 10] = [0; std::mem::size_of::<WadThingLump>()];
|
const _WTL: [u8; 10] = [0; std::mem::size_of::<WadThingLump>()];
|
||||||
|
|||||||
Reference in New Issue
Block a user