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:
@@ -123,6 +123,8 @@ impl CommandManager {
|
|||||||
pub struct WadInfo {
|
pub struct WadInfo {
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
#[serde(skip_deserializing)]
|
||||||
|
pub info_text: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
|||||||
25
src/main.rs
25
src/main.rs
@@ -1,4 +1,5 @@
|
|||||||
use config::{default_save_filename, load_config, save_config, Config};
|
use config::{default_save_filename, load_config, save_config, Config};
|
||||||
|
use wad::get_summary;
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use eframe::egui::Color32;
|
use eframe::egui::Color32;
|
||||||
use infos::{
|
use infos::{
|
||||||
@@ -38,6 +39,7 @@ struct RustDoomLauncher {
|
|||||||
config_filename: PathBuf,
|
config_filename: PathBuf,
|
||||||
config: Option<Config>,
|
config: Option<Config>,
|
||||||
config_tried: bool,
|
config_tried: bool,
|
||||||
|
wad_summary: String,
|
||||||
command_manager: CommandManager,
|
command_manager: CommandManager,
|
||||||
display_command: bool,
|
display_command: bool,
|
||||||
add_stuff_window_displayed: bool,
|
add_stuff_window_displayed: bool,
|
||||||
@@ -58,6 +60,7 @@ impl Default for RustDoomLauncher {
|
|||||||
config_filename: default_save_filename(),
|
config_filename: default_save_filename(),
|
||||||
config: None, // TODO: put the config_filename in the config stuct - or something
|
config: None, // TODO: put the config_filename in the config stuct - or something
|
||||||
config_tried: false,
|
config_tried: false,
|
||||||
|
wad_summary: "".to_string(),
|
||||||
display_command: false,
|
display_command: false,
|
||||||
add_stuff_window_displayed: false,
|
add_stuff_window_displayed: false,
|
||||||
selected_file_type: FileType::Pwad,
|
selected_file_type: FileType::Pwad,
|
||||||
@@ -79,11 +82,16 @@ impl RustDoomLauncher {
|
|||||||
if let Some(config) = &self.config {
|
if let Some(config) = &self.config {
|
||||||
if let Some(iwads) = &config.iwads {
|
if let Some(iwads) = &config.iwads {
|
||||||
for iwad in 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);
|
self.iwad_manager.add(&iwad);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Some(pwads) = &config.pwads {
|
if let Some(pwads) = &config.pwads {
|
||||||
for pwad in 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());
|
self.pwad_manager.add(&pwad.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,15 +213,16 @@ impl eframe::App for RustDoomLauncher {
|
|||||||
ui.label("IWADs");
|
ui.label("IWADs");
|
||||||
let mut remove_pos: Option<usize> = None;
|
let mut remove_pos: Option<usize> = None;
|
||||||
let mut add_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()
|
self.iwad_manager.iter_selectable_with_pos_and_selected()
|
||||||
{
|
{
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
if ui
|
if ui
|
||||||
.add(egui::SelectableLabel::new(selected, &launcher.name))
|
.add(egui::SelectableLabel::new(selected, &iwad.name))
|
||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
add_pos = Some(pos);
|
add_pos = Some(pos);
|
||||||
|
self.wad_summary = iwad.info_text.as_ref().unwrap().clone();
|
||||||
}
|
}
|
||||||
if ui.button("❌").clicked() {
|
if ui.button("❌").clicked() {
|
||||||
remove_pos = Some(pos);
|
remove_pos = Some(pos);
|
||||||
@@ -247,6 +256,9 @@ impl eframe::App for RustDoomLauncher {
|
|||||||
.clicked()
|
.clicked()
|
||||||
{
|
{
|
||||||
add_pos = Some(pos);
|
add_pos = Some(pos);
|
||||||
|
if let Some(txt) = pwad.info_text.clone() {
|
||||||
|
self.wad_summary = txt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ui.button("❌").clicked() {
|
if ui.button("❌").clicked() {
|
||||||
remove_pos = Some(pos);
|
remove_pos = Some(pos);
|
||||||
@@ -264,12 +276,12 @@ impl eframe::App for RustDoomLauncher {
|
|||||||
.add_pwads(&self.pwad_manager.get_current())
|
.add_pwads(&self.pwad_manager.get_current())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let mut text = "Placeholder for WAD info stuffs";
|
|
||||||
let window_size = frame.info().window_info.size;
|
let window_size = frame.info().window_info.size;
|
||||||
|
ui.set_max_height(300.0);
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::TextEdit::multiline(&mut text)
|
egui::TextEdit::multiline(&mut self.wad_summary)
|
||||||
.desired_width(window_size[0] / 1.6)
|
.desired_width(window_size[0] / 1.6)
|
||||||
.desired_rows(20),
|
.desired_rows(20)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
ui.separator();
|
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() {
|
if self.add_name.is_empty() || self.selected_file_path.as_os_str().is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let info_text = get_summary(&self.selected_file_path);
|
||||||
match self.selected_file_type {
|
match self.selected_file_type {
|
||||||
FileType::Iwad => {
|
FileType::Iwad => {
|
||||||
self.iwad_manager.add(&WadInfo {
|
self.iwad_manager.add(&WadInfo {
|
||||||
name: self.add_name.clone(),
|
name: self.add_name.clone(),
|
||||||
path: self.selected_file_path.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 => {
|
FileType::Pwad => {
|
||||||
self.pwad_manager.add(&WadInfo {
|
self.pwad_manager.add(&WadInfo {
|
||||||
name: self.add_name.clone(),
|
name: self.add_name.clone(),
|
||||||
path: self.selected_file_path.clone(),
|
path: self.selected_file_path.clone(),
|
||||||
|
info_text: info_text,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
FileType::Launcher => {
|
FileType::Launcher => {
|
||||||
|
|||||||
34
src/wad.rs
34
src/wad.rs
@@ -5,7 +5,6 @@ use std::fs::File;
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{BufReader, Seek, SeekFrom};
|
use std::io::{BufReader, Seek, SeekFrom};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use strsim;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
A great document I've used as a reference is The Unofficial Doom Specs v1.666
|
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>,
|
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() {
|
if !path.exists() || !path.is_file() {
|
||||||
return None
|
return None
|
||||||
}
|
}
|
||||||
if let (Some(f), Some(p)) = (path.file_name(), path.parent()) {
|
let mut txt_file = PathBuf::from(path);
|
||||||
let files_in_folder = fs::read_dir(&p).unwrap();
|
txt_file.set_extension("txt");
|
||||||
let mut txt_file = PathBuf::from(f);
|
println!("{}", txt_file.display());
|
||||||
txt_file.set_extension(".txt");
|
if txt_file.exists() {
|
||||||
let txt_file = txt_file.into_os_string().into_string().unwrap().to_lowercase();
|
return Some(txt_file);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user