This is going to be the last wad info window thingy

Going to remove it to focus on something more interesting

Or at least more achievable
This commit is contained in:
2023-07-27 22:33:08 +01:00
parent 07f7b67119
commit dbe4b550ac
3 changed files with 38 additions and 23 deletions

View File

@@ -123,6 +123,8 @@ impl CommandManager {
pub struct WadInfo {
pub path: PathBuf,
pub name: String,
#[serde(skip_deserializing)]
pub info_text: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]

View File

@@ -1,4 +1,5 @@
use config::{default_save_filename, load_config, save_config, Config};
use wad::get_summary;
use eframe::egui;
use eframe::egui::Color32;
use infos::{
@@ -38,6 +39,7 @@ struct RustDoomLauncher {
config_filename: PathBuf,
config: Option<Config>,
config_tried: bool,
wad_summary: String,
command_manager: CommandManager,
display_command: bool,
add_stuff_window_displayed: bool,
@@ -58,6 +60,7 @@ impl Default for RustDoomLauncher {
config_filename: default_save_filename(),
config: None, // TODO: put the config_filename in the config stuct - or something
config_tried: false,
wad_summary: "".to_string(),
display_command: false,
add_stuff_window_displayed: false,
selected_file_type: FileType::Pwad,
@@ -79,11 +82,16 @@ impl RustDoomLauncher {
if let Some(config) = &self.config {
if let Some(iwads) = &config.iwads {
for iwad in iwads {
let mut iwad = iwad.clone();
iwad.info_text = Some("I'm sure you know what's in that bloody IWAD".to_string());
self.iwad_manager.add(&iwad);
}
}
if let Some(pwads) = &config.pwads {
for pwad in pwads {
let mut pwad = pwad.clone();
pwad.info_text = get_summary(&pwad.path);
println!("{:?}", pwad);
self.pwad_manager.add(&pwad.clone());
}
}
@@ -205,15 +213,16 @@ impl eframe::App for RustDoomLauncher {
ui.label("IWADs");
let mut remove_pos: Option<usize> = None;
let mut add_pos: Option<usize> = None;
for (launcher, pos, selected) in
for (iwad, pos, selected) in
self.iwad_manager.iter_selectable_with_pos_and_selected()
{
ui.horizontal(|ui| {
if ui
.add(egui::SelectableLabel::new(selected, &launcher.name))
.add(egui::SelectableLabel::new(selected, &iwad.name))
.clicked()
{
add_pos = Some(pos);
self.wad_summary = iwad.info_text.as_ref().unwrap().clone();
}
if ui.button("").clicked() {
remove_pos = Some(pos);
@@ -247,6 +256,9 @@ impl eframe::App for RustDoomLauncher {
.clicked()
{
add_pos = Some(pos);
if let Some(txt) = pwad.info_text.clone() {
self.wad_summary = txt;
}
}
if ui.button("").clicked() {
remove_pos = Some(pos);
@@ -264,12 +276,12 @@ impl eframe::App for RustDoomLauncher {
.add_pwads(&self.pwad_manager.get_current())
}
});
let mut text = "Placeholder for WAD info stuffs";
let window_size = frame.info().window_info.size;
ui.set_max_height(300.0);
ui.add(
egui::TextEdit::multiline(&mut text)
egui::TextEdit::multiline(&mut self.wad_summary)
.desired_width(window_size[0] / 1.6)
.desired_rows(20),
.desired_rows(20)
);
});
ui.separator();
@@ -465,17 +477,20 @@ impl eframe::App for RustDoomLauncher {
if self.add_name.is_empty() || self.selected_file_path.as_os_str().is_empty() {
return;
}
let info_text = get_summary(&self.selected_file_path);
match self.selected_file_type {
FileType::Iwad => {
self.iwad_manager.add(&WadInfo {
name: self.add_name.clone(),
path: self.selected_file_path.clone(),
info_text: Some("I'm sure you know what's in that bloody IWAD!".to_string()),
});
}
FileType::Pwad => {
self.pwad_manager.add(&WadInfo {
name: self.add_name.clone(),
path: self.selected_file_path.clone(),
info_text: info_text,
});
}
FileType::Launcher => {

View File

@@ -5,7 +5,6 @@ use std::fs::File;
use std::fs;
use std::io::{BufReader, Seek, SeekFrom};
use std::path::PathBuf;
use strsim;
/*
A great document I've used as a reference is The Unofficial Doom Specs v1.666
@@ -58,26 +57,25 @@ pub struct OpenWad {
level_indicies: Vec<usize>,
}
pub fn find_txt_file(path: &PathBuf) -> Option<PathBuf> {
pub fn get_summary(path: &PathBuf) -> Option<String> {
if let Some(tf) = find_txt_file(&path) {
println!("{}", tf.display());
let text_file_contents = fs::read_to_string(tf).unwrap();
Some(text_file_contents)
} else {
None
}
}
fn find_txt_file(path: &PathBuf) -> Option<PathBuf> {
if !path.exists() || !path.is_file() {
return None
}
if let (Some(f), Some(p)) = (path.file_name(), path.parent()) {
let files_in_folder = fs::read_dir(&p).unwrap();
let mut txt_file = PathBuf::from(f);
txt_file.set_extension(".txt");
let txt_file = txt_file.into_os_string().into_string().unwrap().to_lowercase();
for f in files_in_folder {
// Jesus this can't be the right way to do things
let f1 = f.unwrap().path().file_name().unwrap().to_os_string().into_string().unwrap();
let f2 = f1.clone().to_lowercase();
let result = strsim::normalized_levenshtein(&txt_file, &f2);
if result > 0.5 {
let mut f3 = PathBuf::from(p);
f3.push(f1);
return Some(f3);
}
}
let mut txt_file = PathBuf::from(path);
txt_file.set_extension("txt");
println!("{}", txt_file.display());
if txt_file.exists() {
return Some(txt_file);
}
None
}