Added this wad.rs thingy
It'll hopefully let me get into more rust AND doom stuff
This commit is contained in:
@@ -6,6 +6,7 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bincode = "1.3.3"
|
||||||
directories = "5.0.1"
|
directories = "5.0.1"
|
||||||
eframe = "0.21.3"
|
eframe = "0.21.3"
|
||||||
native-dialog = "0.6.3"
|
native-dialog = "0.6.3"
|
||||||
|
|||||||
10
src/infos.rs
10
src/infos.rs
@@ -34,26 +34,26 @@ impl CommandManager {
|
|||||||
}
|
}
|
||||||
pub fn remove_iwad(&mut self) {
|
pub fn remove_iwad(&mut self) {
|
||||||
self.iwad = None;
|
self.iwad = None;
|
||||||
self.generate_command_str();
|
let _ = self.generate_command_str();
|
||||||
}
|
}
|
||||||
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());
|
||||||
self.generate_command_str();
|
let _ = self.generate_command_str();
|
||||||
}
|
}
|
||||||
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());
|
||||||
self.generate_command_str();
|
|
||||||
}
|
}
|
||||||
|
let _ = self.generate_command_str();
|
||||||
}
|
}
|
||||||
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());
|
||||||
self.generate_command_str();
|
let _ = self.generate_command_str();
|
||||||
}
|
}
|
||||||
pub fn remove_launcher(&mut self) {
|
pub fn remove_launcher(&mut self) {
|
||||||
self.launcher = None;
|
self.launcher = None;
|
||||||
self.generate_command_str();
|
let _ = self.generate_command_str();
|
||||||
}
|
}
|
||||||
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 {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use std::process::Command;
|
|||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod infos;
|
pub mod infos;
|
||||||
|
pub mod wad;
|
||||||
|
|
||||||
fn main() -> Result<(), eframe::Error> {
|
fn main() -> Result<(), eframe::Error> {
|
||||||
let gui_options = eframe::NativeOptions {
|
let gui_options = eframe::NativeOptions {
|
||||||
|
|||||||
32
src/wad.rs
Normal file
32
src/wad.rs
Normal 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");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user