Added this wad.rs thingy

It'll hopefully let me get into more rust AND doom stuff
This commit is contained in:
2023-06-18 22:39:28 +01:00
parent 849902ce84
commit 2e92202dbb
4 changed files with 39 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
bincode = "1.3.3"
directories = "5.0.1"
eframe = "0.21.3"
native-dialog = "0.6.3"

View File

@@ -34,26 +34,26 @@ impl CommandManager {
}
pub fn remove_iwad(&mut self) {
self.iwad = None;
self.generate_command_str();
let _ = self.generate_command_str();
}
pub fn add_iwad(&mut self, iwad: &WadInfo) {
self.iwad = Some(iwad.path.clone());
self.generate_command_str();
let _ = self.generate_command_str();
}
pub fn add_pwads(&mut self, pwads: &Vec<&WadInfo>) {
self.pwads = Vec::new();
for pwad in pwads {
self.pwads.push(pwad.path.clone());
self.generate_command_str();
}
let _ = self.generate_command_str();
}
pub fn add_launcher(&mut self, launcher: &LauncherInfo) {
self.launcher = Some(launcher.path.clone());
self.generate_command_str();
let _ = self.generate_command_str();
}
pub fn remove_launcher(&mut self) {
self.launcher = None;
self.generate_command_str();
let _ = self.generate_command_str();
}
pub fn generate_command(&self) -> Result<(String, Vec<String>), CommandErrors> {
let launcher = if let Some(launcher) = &self.launcher {

View File

@@ -8,6 +8,7 @@ use std::process::Command;
pub mod config;
pub mod infos;
pub mod wad;
fn main() -> Result<(), eframe::Error> {
let gui_options = eframe::NativeOptions {

32
src/wad.rs Normal file
View File

@@ -0,0 +1,32 @@
use std::path::PathBuf;
use std::fs::File;
use std::io::BufReader;
use bincode;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
pub struct WadHeader {
pub identifier: [u8; 4],
pub num_lumps: i32,
pub file_offset_to_start: i32,
}
pub fn open_wad(path: &PathBuf) -> WadHeader {
let mut file = BufReader::new(File::open(path).unwrap());
let header: WadHeader = bincode::deserialize_from(&mut file).unwrap();
header
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_open_wad() {
let freedoom_iwad = PathBuf::from("freedoom1.wad");
let ow = open_wad(&freedoom_iwad);
assert_eq!(std::str::from_utf8(&ow.identifier).unwrap(), "IWAD");
}
}