Starting to refactor config stuff

So that I can add in a "Added WADs" and "Removed WADs"
This commit is contained in:
2023-07-10 21:25:57 +01:00
parent 745c560409
commit 418daae284
3 changed files with 52 additions and 29 deletions

View File

@@ -6,6 +6,8 @@ use directories;
#[derive(Serialize, Deserialize, Debug, Default)]
pub struct Config {
pub iwads_added_folder: Option<PathBuf>,
pub iwads_removed_folder: Option<PathBuf>,
pub iwads: Option<Vec<WadInfo>>,
pub pwads: Option<Vec<WadInfo>>,
pub launchers: Option<Vec<LauncherInfo>>,

View File

@@ -36,7 +36,8 @@ struct RustDoomLauncher {
pwad_manager: MultiManager<WadInfo>,
add_name: String,
config_filename: PathBuf,
config_file_loaded: bool,
config: Option<Config>,
config_tried: bool,
command_manager: CommandManager,
display_command: bool,
add_stuff_window_displayed: bool,
@@ -55,7 +56,8 @@ impl Default for RustDoomLauncher {
command_manager: CommandManager::default(),
add_name: "".to_string(),
config_filename: default_save_filename(),
config_file_loaded: false,
config: None, // TODO: put the config_filename in the config stuct - or something
config_tried: false,
display_command: false,
add_stuff_window_displayed: false,
selected_file_type: FileType::Pwad,
@@ -70,23 +72,28 @@ 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) {
let config = load_config(&self.config_filename).unwrap();
if let Some(iwads) = config.iwads {
self.config = match load_config(&self.config_filename) {
Ok(c) => Some(c),
Err(e) => None,
};
if let Some(config) = &self.config {
if let Some(iwads) = &config.iwads {
for iwad in iwads {
self.iwad_manager.add(&iwad);
}
}
if let Some(pwads) = config.pwads {
if let Some(pwads) = &config.pwads {
for pwad in pwads {
self.pwad_manager.add(&pwad.clone());
}
}
if let Some(launchers) = config.launchers {
if let Some(launchers) = &config.launchers {
for launcher in launchers {
self.launcher_manager.add(&launcher);
}
}
}
}
fn launch_doom(&self) {
match self.command_manager.generate_command() {
@@ -138,10 +145,10 @@ impl eframe::App for RustDoomLauncher {
}
fn update(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
if !self.config_file_loaded {
if !self.config_tried {
self.get_config_file_stuff();
self.config_file_loaded = true;
}
self.config_tried = true;
};
egui::containers::panel::CentralPanel::default().show(ctx, |ui| {
ui.horizontal(|ui| {
ui.heading("RustDoomLauncher");
@@ -384,6 +391,8 @@ impl eframe::App for RustDoomLauncher {
iwads: Some(self.iwad_manager.selectable.clone()),
pwads: Some(self.pwad_manager.selectable.clone()),
launchers: Some(self.launcher_manager.selectable.clone()),
iwads_added_folder: None,
iwads_removed_folder: None,
};
save_config(&self.config_filename, &config).unwrap();
frame.close();

View File

@@ -56,6 +56,15 @@ pub struct OpenWad {
level_indicies: Vec<usize>,
}
pub fn find_txt_file(path: &PathBuf) -> Option<PathBuf> {
// get folder WAD is in
// get name of WAD
// iterate through all txt/TXT files
// if name is like 50% the same/similar, return match
// return if found anything, otherwise None
None
}
pub fn open_wad(path: &PathBuf) -> OpenWad {
let mut file = BufReader::new(File::open(path).unwrap());
let header: WadHeader = bincode::deserialize_from(&mut file).unwrap();
@@ -174,25 +183,25 @@ pub enum Enemy {
impl Enemy {
pub fn difficulty_value(enemy: &Self) -> u16 {
match enemy {
Self::FormerHuman => 2,
Self::WolfensteinSs => 2,
Self::FormerHumanSergeant => 6,
Self::HeavyWeaponDude => 10,
Self::Imp => 4,
Self::Arachnotron => 14,
Self::ArchVile => 30,
Self::BaronOfHell => 16,
Self::BossBrain => 100,
Self::Cacodemon => 14,
Self::CyberDemon => 40,
Self::HellKnight => 10,
Self::LostSoul => 3,
Self::Mancubus => 18,
Self::PainElemental => 27,
Self::Revenant => 23,
Self::Spectre => 8,
Self::SpiderMastermind => 35,
Self::Demon => 7,
Self::FormerHuman => 20,
Self::WolfensteinSs => 20,
Self::FormerHumanSergeant => 60,
Self::HeavyWeaponDude => 100,
Self::Imp => 40,
Self::Arachnotron => 240,
Self::ArchVile => 500,
Self::BaronOfHell => 250,
Self::BossBrain => 1000,
Self::Cacodemon => 200,
Self::CyberDemon => 500,
Self::HellKnight => 150,
Self::LostSoul => 30,
Self::Mancubus => 280,
Self::PainElemental => 470,
Self::Revenant => 430,
Self::Spectre => 80,
Self::SpiderMastermind => 500,
Self::Demon => 70,
Self::Unknown => 0,
}
}
@@ -311,6 +320,7 @@ mod tests {
let freedoom_iwad = PathBuf::from("freedoom1.wad");
let ow = open_wad(&freedoom_iwad);
let summary = get_enemies_and_health_per_level(ow);
let mut levels = Vec::new();
for (level_name, (enemy_sum, health_sum)) in summary {
let mut enemy_total = 0;
for (enemy, num) in enemy_sum {
@@ -320,8 +330,10 @@ mod tests {
for (hoa, num) in health_sum {
health_total += HealthAndArmour::health_value(&hoa) * num;
}
println!("Level: {}, et: {}, ht: {}, ratio: {}", level_name, enemy_total * 10, health_total, (enemy_total * 10) / health_total);
levels.push((enemy_total / health_total, level_name, enemy_total, health_total));
}
levels.sort();
println!("{:#?}", levels);
panic!();
}