Did some clippy things and wad.rs is being developed
This commit is contained in:
@@ -4,28 +4,18 @@ use std::path::PathBuf;
|
||||
use toml;
|
||||
use directories;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||
pub struct Config {
|
||||
pub iwads: Option<Vec<WadInfo>>,
|
||||
pub pwads: Option<Vec<WadInfo>>,
|
||||
pub launchers: Option<Vec<LauncherInfo>>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Config {
|
||||
iwads: None,
|
||||
pwads: None,
|
||||
launchers: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load_config(path: &PathBuf) -> Result<Config, Box<dyn std::error::Error>> {
|
||||
if !path.exists() {
|
||||
return Ok(Config::default());
|
||||
}
|
||||
let content = std::fs::read_to_string(&path)?;
|
||||
let content = std::fs::read_to_string(path)?;
|
||||
Ok(toml::from_str(&content)?)
|
||||
}
|
||||
|
||||
|
||||
15
src/infos.rs
15
src/infos.rs
@@ -2,7 +2,9 @@ use serde_derive::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use std::path::PathBuf;
|
||||
use std::slice::Iter;
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CommandManager {
|
||||
pub launcher: Option<PathBuf>,
|
||||
pub iwad: Option<PathBuf>,
|
||||
@@ -122,6 +124,7 @@ pub struct LauncherInfo {
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct MultiManager<T> {
|
||||
pub selectable: Vec<T>,
|
||||
pub current_selected: Vec<usize>,
|
||||
@@ -168,13 +171,10 @@ impl<T: Clone> MultiManager<T> {
|
||||
self.selectable.remove(index);
|
||||
let mut new_selected: Vec<usize> = Vec::new();
|
||||
for s in &self.current_selected {
|
||||
println!("{}", s);
|
||||
if *s == index {
|
||||
continue
|
||||
} else if *s > index {
|
||||
new_selected.push(s - 1);
|
||||
} else {
|
||||
new_selected.push(*s);
|
||||
match s.cmp(&index) {
|
||||
Ordering::Equal => continue,
|
||||
Ordering::Less => new_selected.push(*s),
|
||||
Ordering::Greater => new_selected.push(s - 1),
|
||||
}
|
||||
}
|
||||
self.current_selected = new_selected;
|
||||
@@ -192,6 +192,7 @@ impl<T: Clone> MultiManager<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SingleManager<T> {
|
||||
pub selectable: Vec<T>,
|
||||
pub current_selected: Option<usize>,
|
||||
|
||||
13
src/main.rs
13
src/main.rs
@@ -71,7 +71,7 @@ impl Default for RustDoomLauncher {
|
||||
impl RustDoomLauncher {
|
||||
// There must be a better way than this - maybe for the RustDoomLauncher to
|
||||
// have a config thing
|
||||
fn get_config_file_stuff(&mut self) -> () {
|
||||
fn get_config_file_stuff(&mut self) {
|
||||
let config = load_config(&self.config_filename).unwrap();
|
||||
if let Some(iwads) = config.iwads {
|
||||
for iwad in iwads {
|
||||
@@ -90,7 +90,7 @@ impl RustDoomLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
fn launch_doom(&self) -> () {
|
||||
fn launch_doom(&self) {
|
||||
match self.command_manager.generate_command() {
|
||||
Err(e) => {
|
||||
let text = match e {
|
||||
@@ -106,7 +106,12 @@ impl RustDoomLauncher {
|
||||
},
|
||||
Ok((launcher, command)) => {
|
||||
// Note to self, don't hit launch button when running from emacs
|
||||
Command::new(launcher).args(command).spawn();
|
||||
let result = Command::new(launcher).args(command).spawn();
|
||||
match result {
|
||||
Err(e) => panic!("{}", e),
|
||||
Ok(_o) => ()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +145,7 @@ impl eframe::App for RustDoomLauncher {
|
||||
}
|
||||
|
||||
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
if self.config_file_loaded == false {
|
||||
if !self.config_file_loaded {
|
||||
self.get_config_file_stuff();
|
||||
self.config_file_loaded = true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::path::PathBuf;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::io::{BufReader, Seek, SeekFrom};
|
||||
use bincode;
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct WadHeader {
|
||||
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();
|
||||
|
||||
file.seek(SeekFrom::Start(header.file_offset_to_start as u64)).unwrap();
|
||||
|
||||
header
|
||||
}
|
||||
@@ -26,7 +26,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_open_wad() {
|
||||
let freedoom_iwad = PathBuf::from("freedoom1.wad");
|
||||
assert!(freedoom_iwad.exists(), "Needs freedoom1.wad - get it from here https://freedoom.github.io");
|
||||
let ow = open_wad(&freedoom_iwad);
|
||||
assert_eq!(&ow.identifier, b"IWAD");
|
||||
assert_eq!(std::str::from_utf8(&ow.identifier).unwrap(), "IWAD");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user