From a2b6d5022eeefbac55e4ce6cb703ece6e4d6ca27 Mon Sep 17 00:00:00 2001 From: cohaereo Date: Mon, 18 Dec 2023 20:53:47 +0100 Subject: [PATCH] chore: Fix "some" clippy lints --- eurochef-edb/src/array.rs | 4 +- eurochef-edb/src/edb.rs | 14 ++--- eurochef-edb/src/entity.rs | 2 +- eurochef-edb/src/map.rs | 2 +- eurochef-edb/src/versions.rs | 11 ++-- eurochef-filelist/src/path.rs | 16 +++--- eurochef-filelist/src/v4.rs | 15 +++--- eurochef-filelist/src/v5.rs | 16 +++--- eurochef-filelist/src/v9.rs | 16 +++--- eurochef/cli/src/edb/animations.rs | 16 +++--- eurochef/cli/src/edb/entities.rs | 18 +++---- eurochef/cli/src/edb/gltf_export.rs | 8 +-- eurochef/cli/src/edb/maps.rs | 6 +-- eurochef/cli/src/edb/mod.rs | 2 +- eurochef/cli/src/edb/spreadsheets.rs | 17 +++--- eurochef/cli/src/edb/textures.rs | 19 +++---- eurochef/cli/src/filelist/create.rs | 12 ++--- eurochef/cli/src/filelist/extract.rs | 8 +-- eurochef/cli/src/filelist/mod.rs | 2 +- eurochef/cli/src/main.rs | 6 +-- eurochef/gui/build.rs | 4 +- eurochef/gui/src/app.rs | 31 +++++------ eurochef/gui/src/entities.rs | 40 +++++++------- eurochef/gui/src/map_frame.rs | 18 +++---- eurochef/gui/src/maps.rs | 9 +--- eurochef/gui/src/render/billboard.rs | 2 +- eurochef/gui/src/render/camera.rs | 17 +++--- eurochef/gui/src/render/entity.rs | 2 +- eurochef/gui/src/render/mod.rs | 8 +-- eurochef/gui/src/render/trigger.rs | 10 ++-- eurochef/gui/src/scripts.rs | 4 +- eurochef/gui/src/textures.rs | 54 ++++++++----------- eurochef/shared/src/hashcodes.rs | 2 +- eurochef/shared/src/maps.rs | 18 +++---- eurochef/shared/src/platform/texture/gx.rs | 22 ++++---- eurochef/shared/src/platform/texture/pc.rs | 2 +- eurochef/shared/src/platform/texture/xbox.rs | 19 ++++--- eurochef/shared/src/platform/texture/xenon.rs | 10 ++-- eurochef/shared/src/textures.rs | 10 ++-- 39 files changed, 219 insertions(+), 273 deletions(-) diff --git a/eurochef-edb/src/array.rs b/eurochef-edb/src/array.rs index b68f8a2..1a82c2d 100644 --- a/eurochef-edb/src/array.rs +++ b/eurochef-edb/src/array.rs @@ -35,7 +35,7 @@ impl EXGeoHashArray { } pub fn data(&self) -> &Vec { - return &self.data; + &self.data } } @@ -161,7 +161,7 @@ impl EXRelArray { } pub fn data(&self) -> &Vec { - return &self.data; + &self.data } } diff --git a/eurochef-edb/src/edb.rs b/eurochef-edb/src/edb.rs index 13d0e57..412385c 100644 --- a/eurochef-edb/src/edb.rs +++ b/eurochef-edb/src/edb.rs @@ -24,10 +24,8 @@ impl DatabaseReader for R { let ptr: *mut EdbFile = transmute(self as *mut _); // Check alignment and safety marker - if (transmute::<_, usize>(ptr) & 0x7) == 0 - && (*ptr).safety_marker == EdbFile::SAFETY_MARKER - { - Some(transmute(ptr)) + if (ptr as usize & 0x7) == 0 && (*ptr).safety_marker == EdbFile::SAFETY_MARKER { + Some(&mut *ptr) } else { if cfg!(debug_assertions) { warn!("Couldn't verify EdbFile marker and alignment!"); @@ -76,7 +74,7 @@ impl EdbFile { )); } - if version < 182 || version > 263 { + if !(182..=263).contains(&version) { return Err(crate::error::EurochefError::Unsupported( crate::error::UnsupportedError::Version(version), )); @@ -109,10 +107,8 @@ impl EdbFile { pub fn add_reference(&mut self, file: Hashcode, reference: Hashcode) { if file == u32::MAX || reference.is_local() { self.add_reference_internal(reference); - } else { - if !self.external_references.contains(&(file, reference)) { - self.external_references.push((file, reference)) - } + } else if !self.external_references.contains(&(file, reference)) { + self.external_references.push((file, reference)) } } diff --git a/eurochef-edb/src/entity.rs b/eurochef-edb/src/entity.rs index 124081e..325ebe1 100644 --- a/eurochef-edb/src/entity.rs +++ b/eurochef-edb/src/entity.rs @@ -139,7 +139,7 @@ impl EXGeoEntity { EXGeoEntity::Mesh(e) => Some(&e.data.base), EXGeoEntity::Split(e) => Some(&e.base), EXGeoEntity::MapZone(e) => Some(&e.base), - EXGeoEntity::Instance(e) => Some(&e), + EXGeoEntity::Instance(e) => Some(e), EXGeoEntity::UnknownType(_e) => None, } } diff --git a/eurochef-edb/src/map.rs b/eurochef-edb/src/map.rs index 200e789..e1aff55 100644 --- a/eurochef-edb/src/map.rs +++ b/eurochef-edb/src/map.rs @@ -228,7 +228,7 @@ impl BinRead for EXGeoTriggerEngineOptions { let mut res: EXGeoTriggerEngineOptions = Default::default(); const FLAG_BASE: usize = 24; - if trig_flags.is_set(FLAG_BASE + 0) { + if trig_flags.is_set(FLAG_BASE) { res.visual_object = Some(reader.read_type(endian)?); } if trig_flags.is_set(FLAG_BASE + 1) { diff --git a/eurochef-edb/src/versions.rs b/eurochef-edb/src/versions.rs index 436819a..4281122 100644 --- a/eurochef-edb/src/versions.rs +++ b/eurochef-edb/src/versions.rs @@ -30,7 +30,7 @@ pub enum Platform { } pub fn transform_windows_path>(path: P) -> String { - path.as_ref().replace("\\", "/") + path.as_ref().replace('\\', "/") } impl Platform { @@ -47,12 +47,15 @@ impl Platform { // swy: the magic value is the four-byte GEOM tag, for big endian the G '0x47' shows first, // otherwise it's the M (0x4D) of MOEG; looks reversed to humans, little-endian - let endian = if reader.read_ne::().ok()? == b'G' /* 0x47 */ { + let endian = if reader.read_ne::().ok()? == b'G' + /* 0x47 */ + { Endian::Big - } else { // 'M' /* 0x4D */ + } else { + // 'M' /* 0x4D */ Endian::Little }; - + reader.rewind().ok(); let header = reader.read_type::(endian).unwrap(); diff --git a/eurochef-filelist/src/path.rs b/eurochef-filelist/src/path.rs index d5c568e..8c46351 100644 --- a/eurochef-filelist/src/path.rs +++ b/eurochef-filelist/src/path.rs @@ -1,11 +1,11 @@ pub fn unscramble_filename_v7(file_index: u32, bytes: &mut [u8]) { - for i in 0..bytes.len() { - bytes[i] = (bytes[i] as u32) + for (i, b) in bytes.iter_mut().enumerate() { + *b = (*b as u32) .wrapping_add(0x16) .wrapping_sub(file_index) .wrapping_sub(i as u32) as u8; - if bytes[i] == 0 { + if *b == 0 { break; } } @@ -13,8 +13,8 @@ pub fn unscramble_filename_v7(file_index: u32, bytes: &mut [u8]) { // TODO: This should take a string and output a Cow<[u8]> to ensure null-termination pub fn scramble_filename_v7(file_index: u32, bytes: &mut [u8]) { - for i in 0..bytes.len() { - bytes[i] = (bytes[i] as u32) + for (i, b) in bytes.iter_mut().enumerate() { + *b = (*b as u32) .wrapping_sub(0x16) .wrapping_add(file_index) .wrapping_add(i as u32) as u8; @@ -22,13 +22,13 @@ pub fn scramble_filename_v7(file_index: u32, bytes: &mut [u8]) { } pub fn unscramble_filename_v10(file_index: u32, bytes: &mut [u8]) { - for i in 0..bytes.len() { - bytes[i] = (bytes[i] as u32) + for (i, b) in bytes.iter_mut().enumerate() { + *b = (*b as u32) .wrapping_sub(0x6a) .wrapping_sub(file_index * 4) .wrapping_sub(i as u32 * 4) as u8; - if bytes[i] == 0 { + if *b == 0 { break; } } diff --git a/eurochef-filelist/src/v4.rs b/eurochef-filelist/src/v4.rs index 27b47e9..b86e262 100644 --- a/eurochef-filelist/src/v4.rs +++ b/eurochef-filelist/src/v4.rs @@ -44,16 +44,15 @@ impl EXFileList4 { } // FIXME: If the strings arent encoded linearly this will be a bit inefficient - for (_, (start, end)) in filename_offsets + for (start, end) in filename_offsets .iter() .chain([res.header.filesize as u64].iter()) .tuple_windows() - .enumerate() { let size = end - start; let mut data = vec![0u8; size as usize]; reader.seek(std::io::SeekFrom::Start(*start))?; - reader.read(&mut data)?; + reader.read_exact(&mut data)?; let null_pos = data.iter().position(|&p| p == 0).unwrap_or(data.len()); res.filenames @@ -64,16 +63,16 @@ impl EXFileList4 { } } -impl Into for EXFileList4 { - fn into(self) -> UXFileList { +impl From for UXFileList { + fn from(val: EXFileList4) -> Self { UXFileList { num_filelists: None, build_type: None, - endian: self.endian, - files: self + endian: val.endian, + files: val .filenames .into_iter() - .zip(self.header.fileinfo) + .zip(val.header.fileinfo) .map(|(filename, info)| { ( filename, diff --git a/eurochef-filelist/src/v5.rs b/eurochef-filelist/src/v5.rs index b4a9935..5d5a43e 100644 --- a/eurochef-filelist/src/v5.rs +++ b/eurochef-filelist/src/v5.rs @@ -55,7 +55,7 @@ impl EXFileList5 { let size = end - start; let mut data = vec![0u8; size as usize]; reader.seek(std::io::SeekFrom::Start(*start))?; - reader.read(&mut data)?; + reader.read_exact(&mut data)?; if res.header.version >= 7 { unscramble_filename_v7(i as u32, &mut data); @@ -71,16 +71,16 @@ impl EXFileList5 { } // TODO: Make a trait for filelists bundling both the read and from/into functions so that they can be used genericly -impl Into for EXFileList5 { - fn into(self) -> UXFileList { +impl From for UXFileList { + fn from(val: EXFileList5) -> Self { UXFileList { - num_filelists: Some(self.header.num_filelists), - build_type: Some(self.header.build_type), - endian: self.endian, - files: self + num_filelists: Some(val.header.num_filelists), + build_type: Some(val.header.build_type), + endian: val.endian, + files: val .filenames .into_iter() - .zip(self.header.fileinfo) + .zip(val.header.fileinfo) .map(|(filename, info)| { ( filename, diff --git a/eurochef-filelist/src/v9.rs b/eurochef-filelist/src/v9.rs index 933d8d4..42e2a99 100644 --- a/eurochef-filelist/src/v9.rs +++ b/eurochef-filelist/src/v9.rs @@ -55,7 +55,7 @@ impl EXFileList9 { let size = end - start; let mut data = vec![0u8; size as usize]; reader.seek(std::io::SeekFrom::Start(*start))?; - reader.read(&mut data)?; + reader.read_exact(&mut data)?; if res.header.version >= 10 { unscramble_filename_v10(i as u32, &mut data); @@ -73,16 +73,16 @@ impl EXFileList9 { } // TODO: Make a trait for filelists bundling both the read and from/into functions so that they can be used genericly -impl Into for EXFileList9 { - fn into(self) -> UXFileList { +impl From for UXFileList { + fn from(val: EXFileList9) -> Self { UXFileList { - num_filelists: Some(self.header.num_filelists), - build_type: Some(self.header.build_type), - endian: self.endian, - files: self + num_filelists: Some(val.header.num_filelists), + build_type: Some(val.header.build_type), + endian: val.endian, + files: val .filenames .into_iter() - .zip(self.header.fileinfo) + .zip(val.header.fileinfo) .map(|(filename, info)| { ( filename, diff --git a/eurochef/cli/src/edb/animations.rs b/eurochef/cli/src/edb/animations.rs index 4b4e121..26f0d83 100644 --- a/eurochef/cli/src/edb/animations.rs +++ b/eurochef/cli/src/edb/animations.rs @@ -28,11 +28,7 @@ pub fn execute_command( let output_folder = output_folder.unwrap_or(format!( "./entities/{}/", - Path::new(&filename) - .file_name() - .unwrap() - .to_string_lossy() - .to_string(), + Path::new(&filename).file_name().unwrap().to_string_lossy() )); let output_folder = Path::new(&output_folder); @@ -66,7 +62,7 @@ pub fn execute_command( ) .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Extracting textures"); @@ -77,7 +73,7 @@ pub fn execute_command( let _span_enter = _span.enter(); if let Ok(t) = it.data { - if t.frames.len() == 0 { + if t.frames.is_empty() { error!("Skipping texture with no frames"); continue; } @@ -118,7 +114,7 @@ pub fn execute_command( ) .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Extracting animskins"); @@ -190,7 +186,7 @@ pub fn execute_command( } } - if vertex_data.len() == 0 { + if vertex_data.is_empty() { warn!( "Processed entity doesnt have vertex data! (v={}/i={}/t={})", vertex_data.len(), @@ -199,7 +195,7 @@ pub fn execute_command( ); } - if strips.len() <= 0 { + if strips.is_empty() { continue; } diff --git a/eurochef/cli/src/edb/entities.rs b/eurochef/cli/src/edb/entities.rs index eb2c8a4..cc40399 100644 --- a/eurochef/cli/src/edb/entities.rs +++ b/eurochef/cli/src/edb/entities.rs @@ -34,11 +34,7 @@ pub fn execute_command( ) -> anyhow::Result<()> { let output_folder = output_folder.unwrap_or(format!( "./entities/{}/", - Path::new(&filename) - .file_name() - .unwrap() - .to_string_lossy() - .to_string(), + Path::new(&filename).file_name().unwrap().to_string_lossy() )); let output_folder = Path::new(&output_folder); @@ -92,7 +88,7 @@ pub fn execute_command( ) .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Extracting textures"); @@ -103,7 +99,7 @@ pub fn execute_command( let _span_enter = _span.enter(); if let Ok(t) = it.data { - if t.frames.len() == 0 { + if t.frames.is_empty() { error!("Skipping texture with no frames"); continue; } @@ -164,7 +160,7 @@ pub fn execute_command( ) .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Extracting entities"); @@ -210,7 +206,7 @@ pub fn execute_command( continue; } - if strips.len() <= 0 { + if strips.is_empty() { warn!( "Processed entity doesnt have tristrips! (v={}/i={}/t={})", vertex_data.len(), @@ -234,7 +230,7 @@ pub fn execute_command( } } - if vertex_data.len() == 0 { + if vertex_data.is_empty() { warn!( "Processed entity doesnt have vertex data! (v={}/i={}/t={})", vertex_data.len(), @@ -243,7 +239,7 @@ pub fn execute_command( ); } - let mut gltf = gltf_export::create_mesh_scene(&ent_id); + let mut gltf = gltf_export::create_mesh_scene(ent_id); gltf_export::add_mesh_to_scene( &mut gltf, &vertex_data, diff --git a/eurochef/cli/src/edb/gltf_export.rs b/eurochef/cli/src/edb/gltf_export.rs index d1ca77a..1ebca0e 100644 --- a/eurochef/cli/src/edb/gltf_export.rs +++ b/eurochef/cli/src/edb/gltf_export.rs @@ -204,16 +204,16 @@ pub fn add_mesh_to_scene( let mut material_map: HashMap = HashMap::new(); // Restore material map for (i, m) in root.materials.iter().enumerate() { - let msplit = m.name.as_ref().unwrap().split('_').nth(0).unwrap(); + let msplit = m.name.as_ref().unwrap().split('_').next().unwrap(); let mhashcode = u32::from_str_radix(msplit, 16).unwrap(); material_map.insert(mhashcode, i as u32); } for t in strips { - if !material_map.contains_key(&t.texture_index) { + if let std::collections::hash_map::Entry::Vacant(e) = material_map.entry(t.texture_index) { let (img_uri, transparency) = texture_map .get(&t.texture_index) - .map(|v| v.clone()) + .cloned() .unwrap_or((format!("{:08x}.png", t.texture_index), Transparency::Opaque)); root.images.push(gjson::Image { @@ -283,7 +283,7 @@ pub fn add_mesh_to_scene( }); let material_index = root.materials.len() as u32 - 1; - material_map.insert(t.texture_index, material_index); + e.insert(material_index); } let material_id = material_map.get(&t.texture_index).unwrap(); diff --git a/eurochef/cli/src/edb/maps.rs b/eurochef/cli/src/edb/maps.rs index d326d7a..07abf99 100644 --- a/eurochef/cli/src/edb/maps.rs +++ b/eurochef/cli/src/edb/maps.rs @@ -26,11 +26,7 @@ pub fn execute_command( ) -> anyhow::Result<()> { let output_folder = output_folder.unwrap_or(format!( "./maps/{}/", - Path::new(&filename) - .file_name() - .unwrap() - .to_string_lossy() - .to_string(), + Path::new(&filename).file_name().unwrap().to_string_lossy() )); let trigger_typemap = if let Some(path) = trigger_defs_file { diff --git a/eurochef/cli/src/edb/mod.rs b/eurochef/cli/src/edb/mod.rs index da3ef35..3f79f32 100644 --- a/eurochef/cli/src/edb/mod.rs +++ b/eurochef/cli/src/edb/mod.rs @@ -1,4 +1,4 @@ -const TICK_STRINGS: &'static str = "⠁⠂⠄⡀⢀⠠⠐⠈"; +const TICK_STRINGS: &str = "⠁⠂⠄⡀⢀⠠⠐⠈"; pub mod animations; pub mod entities; diff --git a/eurochef/cli/src/edb/spreadsheets.rs b/eurochef/cli/src/edb/spreadsheets.rs index 0f47533..75f40fb 100644 --- a/eurochef/cli/src/edb/spreadsheets.rs +++ b/eurochef/cli/src/edb/spreadsheets.rs @@ -12,11 +12,7 @@ use eurochef_shared::spreadsheets::{SpreadsheetDefinitions, UXGeoSpreadsheet}; pub fn execute_command(filename: String, output_folder: Option) -> anyhow::Result<()> { let output_folder = output_folder.unwrap_or(format!( "./spreadsheets/{}/", - Path::new(&filename) - .file_name() - .unwrap() - .to_string_lossy() - .to_string(), + Path::new(&filename).file_name().unwrap().to_string_lossy() )); let output_folder = Path::new(&output_folder); std::fs::create_dir_all(output_folder)?; @@ -29,10 +25,9 @@ pub fn execute_command(filename: String, output_folder: Option) -> anyho if let Some(dissected_path) = DissectedFilelistPath::dissect(&filename) { let exe_path = std::env::current_exe().unwrap(); let exe_dir = exe_path.parent().unwrap(); - let v = std::fs::read_to_string(exe_dir.join(&format!( - "./assets/spreadsheets_{}.yml", - dissected_path.game - ))) + let v = std::fs::read_to_string( + exe_dir.join(format!("./assets/spreadsheets_{}.yml", dissected_path.game)), + ) .unwrap_or_default(); let spreadsheet_definitions: SpreadsheetDefinitions = match serde_yaml::from_str(&v) { @@ -59,7 +54,7 @@ pub fn execute_command(filename: String, output_folder: Option) -> anyho for (file_hashcode, sfile) in &spreadsheet_definitions { for (hashcode, spreadsheet) in &sfile.0 { - for (_sheet_num, sheet) in &spreadsheet.0 { + for sheet in spreadsheet.0.values() { if sheet.columns.is_empty() { continue; } @@ -92,7 +87,7 @@ pub fn execute_command(filename: String, output_folder: Option) -> anyho UXGeoSpreadsheet::Data(data) => { for (sheet_num, sheet) in data.iter().enumerate() { edb.seek(SeekFrom::Start(sheet.address as u64))?; - let sheet_definition = match spreadsheet_definition.0.get(&hashcode) { + let sheet_definition = match spreadsheet_definition.0.get(hashcode) { None => { error!("Missing spreadsheet definition for file {:08x} spreadsheet {hashcode:08x} sheet #{sheet_num} (address 0x{:x})", edb.header.hashcode, sheet.address); continue; diff --git a/eurochef/cli/src/edb/textures.rs b/eurochef/cli/src/edb/textures.rs index b92a8de..3ae686a 100644 --- a/eurochef/cli/src/edb/textures.rs +++ b/eurochef/cli/src/edb/textures.rs @@ -20,11 +20,7 @@ pub fn execute_command( ) -> anyhow::Result<()> { let output_folder = output_folder.unwrap_or(format!( "./textures/{}/", - Path::new(&filename) - .file_name() - .unwrap() - .to_string_lossy() - .to_string(), + Path::new(&filename).file_name().unwrap().to_string_lossy(), )); let output_folder = Path::new(&output_folder); std::fs::create_dir_all(output_folder)?; @@ -47,7 +43,7 @@ pub fn execute_command( ) .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Extracting textures"); @@ -98,13 +94,10 @@ pub fn execute_command( }), )?; encoder.finish_encode()?; - } else { - if let Some(f) = t.frames.into_iter().nth(0) { - let image = - image::RgbaImage::from_vec(t.width as u32, t.height as u32, f) - .unwrap(); - image.save(filename)?; - } + } else if let Some(f) = t.frames.into_iter().next() { + let image = + image::RgbaImage::from_vec(t.width as u32, t.height as u32, f).unwrap(); + image.save(filename)?; } } else { for (i, f) in t.frames.into_iter().enumerate() { diff --git a/eurochef/cli/src/filelist/create.rs b/eurochef/cli/src/filelist/create.rs index 2e04e06..639e669 100644 --- a/eurochef/cli/src/filelist/create.rs +++ b/eurochef/cli/src/filelist/create.rs @@ -69,14 +69,14 @@ pub fn execute_command( ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] {msg}") .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Locating files"); for p in &file_paths_temp { // Join path to root folder and change globbing pattern to be `glob`-compatible let path_on_disk = - Path::new(&input_folder).join(transform_windows_path(&p[3..].replace("#", "?"))); + Path::new(&input_folder).join(transform_windows_path(&p[3..].replace('#', "?"))); let mut found_files = false; #[allow(for_loops_over_fallibles)] @@ -110,7 +110,7 @@ pub fn execute_command( ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] {msg}") .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Locating files"); @@ -144,7 +144,7 @@ pub fn execute_command( ) .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Packing files"); @@ -235,7 +235,7 @@ pub fn execute_command( // this should make the diff engines' life easier. and we should // get a byte-by-byte perfect reconstruction for pristine files, // (as long as they get stored in the same order with the help of a handy .scr spec file) - f_data.write(&common_garbage_buf[filedata.len()..filedata_len_plus_padding])?; + f_data.write_all(&common_garbage_buf[filedata.len()..filedata_len_plus_padding])?; } } @@ -317,7 +317,7 @@ fn parse_scr_filelist>(path: P) -> anyhow::Result> { if line == "[FileList]" { in_filesection = true; - } else if line.starts_with("[") { + } else if line.starts_with('[') { in_filesection = false; } } diff --git a/eurochef/cli/src/filelist/extract.rs b/eurochef/cli/src/filelist/extract.rs index 03ca72e..ecb5070 100644 --- a/eurochef/cli/src/filelist/extract.rs +++ b/eurochef/cli/src/filelist/extract.rs @@ -75,7 +75,7 @@ pub fn execute_command( None // swy: the user explicitly asked not to write the .scr file at all }; - scr_file.as_mut().map(|f| { + if let Some(f) = scr_file.as_mut() { writeln!( f, "[FileInfomation] @@ -83,7 +83,7 @@ pub fn execute_command( [FileList]\n" ) .expect("Failed to write scr file header"); - }); + } let file_base = &filename[..filename.len() - 3]; let mut data_files = vec![]; @@ -105,7 +105,7 @@ pub fn execute_command( ) .unwrap() .progress_chars("##-") - .tick_chars(&TICK_STRINGS), + .tick_chars(TICK_STRINGS), ); pb.set_message("Extracting files"); @@ -151,7 +151,7 @@ pub fn execute_command( std::fs::create_dir_all(fpath_noprefix.parent().unwrap())?; File::create(&fpath_noprefix) .context(format!("Failed to create output file {fpath_noprefix:?}"))? - .write(&data)?; + .write_all(&data)?; } println!("Successfully extracted {} files", filelist.files.len()); diff --git a/eurochef/cli/src/filelist/mod.rs b/eurochef/cli/src/filelist/mod.rs index 4b23f52..2d70507 100644 --- a/eurochef/cli/src/filelist/mod.rs +++ b/eurochef/cli/src/filelist/mod.rs @@ -1,4 +1,4 @@ -const TICK_STRINGS: &'static str = "⠁⠂⠄⡀⢀⠠⠐⠈"; +const TICK_STRINGS: &str = "⠁⠂⠄⡀⢀⠠⠐⠈"; pub mod create; pub mod extract; diff --git a/eurochef/cli/src/main.rs b/eurochef/cli/src/main.rs index 2fbef51..6dade94 100644 --- a/eurochef/cli/src/main.rs +++ b/eurochef/cli/src/main.rs @@ -27,9 +27,9 @@ pub enum PlatformArg { WiiU, } -impl Into for PlatformArg { - fn into(self) -> Platform { - match self { +impl From for Platform { + fn from(val: PlatformArg) -> Self { + match val { PlatformArg::Pc => Platform::Pc, PlatformArg::Xbox | PlatformArg::Xb => Platform::Xbox, PlatformArg::Xbox360 => Platform::Xbox360, diff --git a/eurochef/gui/build.rs b/eurochef/gui/build.rs index a7d4e54..40e3542 100644 --- a/eurochef/gui/build.rs +++ b/eurochef/gui/build.rs @@ -1,7 +1,7 @@ use std::process::Command; fn main() { - let git_hash = if let Ok(output) = Command::new("git").args(&["rev-parse", "HEAD"]).output() { + let git_hash = if let Ok(output) = Command::new("git").args(["rev-parse", "HEAD"]).output() { String::from_utf8(output.stdout).unwrap() } else { "unknown".to_string() @@ -15,7 +15,7 @@ fn main() { date_time.format("%Y-%m-%d %H:%M:%S") ); - let output = Command::new("rustc").args(&["--version"]).output().unwrap(); + let output = Command::new("rustc").args(["--version"]).output().unwrap(); let rustc_version = String::from_utf8(output.stdout).unwrap(); println!("cargo:rustc-env=RUSTC_VERSION={}", rustc_version); } diff --git a/eurochef/gui/src/app.rs b/eurochef/gui/src/app.rs index 4cebc18..62eae31 100644 --- a/eurochef/gui/src/app.rs +++ b/eurochef/gui/src/app.rs @@ -142,7 +142,7 @@ impl EurochefApp { match s.load_file_with_path(path) { Ok(_) => {} Err(e) => { - s.state = AppState::Error(e.into()); + s.state = AppState::Error(e); } } } @@ -212,11 +212,11 @@ impl EurochefApp { file_ref: Hashcode, platform: Platform, ) -> anyhow::Result<()> { - let ref mut edb = if let Some(path) = self.path_cache.get(&file_ref) { + let edb = &mut (if let Some(path) = self.path_cache.get(&file_ref) { match file_map.entry(file_ref) { hash_map::Entry::Occupied(e) => e.into_mut(), hash_map::Entry::Vacant(a) => { - let file = File::open(&path)?; + let file = File::open(path)?; let reader = BufReader::new(file); a.insert(EdbFile::new(Box::new(reader), platform)?) @@ -224,12 +224,12 @@ impl EurochefApp { } } else { return Ok(()); - }; + }); let header = edb.header.clone(); let mut rs_lock = self.render_store.write(); - let scripts = UXGeoScript::read_hashcodes(edb, &references)?; + let scripts = UXGeoScript::read_hashcodes(edb, references)?; for s in &scripts { rs_lock.insert_script(header.hashcode, s.clone()); } @@ -240,7 +240,7 @@ impl EurochefApp { .internal_references .iter() .filter(|v| !rs_lock.is_object_loaded(header.hashcode, **v)) - .map(|v| *v) + .copied() .collect(); let internal_refs = [references, &interal_references_filtered].concat(); let (entities, _, _) = entities::read_from_file(edb, Some(&internal_refs))?; @@ -321,7 +321,7 @@ impl EurochefApp { self.fileinfo = Some(fileinfo::FileInfoPanel::new(edb.header.clone())); let spreadsheets = UXGeoSpreadsheet::read_all(&mut edb)?; - if spreadsheets.len() > 0 { + if !spreadsheets.is_empty() { self.spreadsheetlist = Some(spreadsheet::TextItemList::new(spreadsheets.clone())); } @@ -349,7 +349,7 @@ impl EurochefApp { rs_lock.insert_script(header.hashcode, s.clone()); } - if scripts.len() > 0 { + if !scripts.is_empty() { self.scripts = Some(scripts::ScriptListPanel::new( header.hashcode, &self.gl, @@ -452,7 +452,7 @@ impl eframe::App for EurochefApp { }); if let Some((data, load_path)) = self.load_input.take() { - let platform = Platform::from_path(&load_path); + let platform = Platform::from_path(load_path); self.pending_file = Some((data, platform)); } @@ -462,7 +462,7 @@ impl eframe::App for EurochefApp { match self.load_file(*platform, Box::new(cur), ctx) { Ok(_) => {} Err(e) => { - self.state = AppState::Error(e.into()); + self.state = AppState::Error(e); } } self.pending_file = None; @@ -491,7 +491,7 @@ impl eframe::App for EurochefApp { ctx.input(|i| { if !i.raw.dropped_files.is_empty() { for file in &i.raw.dropped_files { - let mut info = if let Some(path) = &file.path { + let info = if let Some(path) = &file.path { path.display().to_string() } else if !file.name.is_empty() { file.name.clone() @@ -808,11 +808,12 @@ impl eframe::App for EurochefApp { Panel::Textures => textures.as_mut().map(|s| s.show(ui)), Panel::Entities => entities.as_mut().map(|s| s.show(ctx, ui)), Panel::Spreadsheets => spreadsheetlist.as_mut().map(|s| s.show(ui)), - Panel::Maps => Some({ + Panel::Maps => { if let Some(Err(e)) = maps.as_mut().map(|s| s.show(ctx, ui)) { self.state = AppState::Error(e); - } - }), + }; + Some(()) + } Panel::Scripts => scripts.as_mut().map(|s| s.show(ui)), }; }); @@ -827,7 +828,7 @@ impl eframe::App for EurochefApp { fn remove_stacktrace(s: &str) -> &str { if let Some(v) = s.to_lowercase().find("stack backtrace:") { - &s[..v].trim() + s[..v].trim() } else { s } diff --git a/eurochef/gui/src/entities.rs b/eurochef/gui/src/entities.rs index fc14230..9fc9594 100644 --- a/eurochef/gui/src/entities.rs +++ b/eurochef/gui/src/entities.rs @@ -134,7 +134,7 @@ impl EntityListPanel { gl, t.width as i32, t.height as i32, - &d, + d, glow::RGBA, t.flags, ); @@ -298,14 +298,14 @@ impl EntityListPanel { ui.label(format!("Entity {i:x} failed:")); ui.colored_label( Color32::LIGHT_RED, - cutoff_string(strip_ansi_codes(&err), 1024), + cutoff_string(strip_ansi_codes(err), 1024), ); }); return; } - let response = if let Some(Some(tex)) = self.entity_previews.get(&i) { + let response = if let Some(Some(tex)) = self.entity_previews.get(i) { egui::Image::new(tex.id(), [256., 256.]) .uv(egui::Rect::from_min_size( egui::Pos2::ZERO, @@ -468,27 +468,25 @@ impl EntityListPanel { .map(|v| v.data.as_ref()) { meshes.push(mesh) - } else { - if let Some(Ok(skin)) = self - .skins + } else if let Some(Ok(skin)) = self + .skins + .iter() + .find(|ir| ir.hashcode == *hc) + .map(|v| &v.data) + { + let entity_indices: Vec = skin + .entities .iter() - .find(|ir| ir.hashcode == *hc) - .map(|v| &v.data) - { - let entity_indices: Vec = skin - .entities - .iter() - .chain(skin.more_entities.iter()) - .map(|d| d.entity_index & 0x00ffffff) - .collect(); - for i in entity_indices { - if let Ok((_, mesh)) = &self.entities[i as usize].data.as_ref() { - meshes.push(mesh); - } + .chain(skin.more_entities.iter()) + .map(|d| d.entity_index & 0x00ffffff) + .collect(); + for i in entity_indices { + if let Ok((_, mesh)) = &self.entities[i as usize].data.as_ref() { + meshes.push(mesh); } - } else { - unreachable!("Thumbnail requested for nonexistent entity {hc:x}"); } + } else { + unreachable!("Thumbnail requested for nonexistent entity {hc:x}"); } let mut bb = (Vec3::splat(f32::MAX), Vec3::splat(f32::MIN)); diff --git a/eurochef/gui/src/map_frame.rs b/eurochef/gui/src/map_frame.rs index 1fa6643..a5cbc70 100644 --- a/eurochef/gui/src/map_frame.rs +++ b/eurochef/gui/src/map_frame.rs @@ -219,7 +219,7 @@ impl MapFrame { let exe_path = std::env::current_exe().unwrap(); let exe_dir = exe_path.parent().unwrap(); let v = std::fs::read_to_string( - exe_dir.join(&format!("./assets/{}", self.selected_triginfo_path)), + exe_dir.join(format!("./assets/{}", self.selected_triginfo_path)), )?; self.trigger_info = serde_yaml::from_str(&v).context("Failed to load trigger definition file")?; @@ -269,11 +269,11 @@ impl MapFrame { self.textfield_focused = response.has_focus(); if let Ok(hashcode) = u32::from_str_radix(&self.sky_ent, 16) { - if !self + if self .render_store .read() .get_entity(self.file, hashcode) - .is_some() + .is_none() { ui.strong(font_awesome::EXCLAMATION_TRIANGLE.to_string()) .on_hover_ui(|ui| { @@ -410,7 +410,7 @@ impl MapFrame { } } - self.draw_trigger_inspector(context, &map); + self.draw_trigger_inspector(context, map); let time: f64 = ui.input(|t| t.time); @@ -439,7 +439,7 @@ impl MapFrame { // TODO(cohae): How do we get out of this situation let map = map.clone(); // FIXME(cohae): ugh. let sky_ent = u32::from_str_radix(&self.sky_ent, 16).unwrap_or(u32::MAX); - let default_trigger_icon = self.default_trigger_icon.clone(); + let default_trigger_icon = self.default_trigger_icon; let billboard_renderer = self.billboard_renderer.clone(); let link_renderer = self.link_renderer.clone(); let selected_trigger = self.selected_trigger; @@ -742,8 +742,7 @@ impl MapFrame { if let Some(coll) = t .engine_options .collision_index - .map(|c| map.trigger_collisions.get(c as usize)) - .flatten() + .and_then(|c| map.trigger_collisions.get(c as usize)) { if coll.dtype == 0 || coll.dtype == 3 { collision_renderer.render( @@ -886,8 +885,7 @@ impl MapFrame { if let Some(coll) = trig .engine_options .collision_index - .map(|c| map.trigger_collisions.get(c as usize)) - .flatten() + .and_then(|c| map.trigger_collisions.get(c as usize)) { ui.label("Collision"); match coll.dtype { @@ -1016,7 +1014,7 @@ impl MapFrame { }); } - if trig.links.iter().find(|v| **v != -1).is_some() { + if trig.links.iter().any(|v| *v != -1) { ui.separator(); ui.strong("Outgoing Links"); diff --git a/eurochef/gui/src/maps.rs b/eurochef/gui/src/maps.rs index 511de52..c406d7a 100644 --- a/eurochef/gui/src/maps.rs +++ b/eurochef/gui/src/maps.rs @@ -99,7 +99,7 @@ impl MapViewerPanel { file: Hashcode, gl: &glow::Context, maps: &[ProcessedMap], - ref_entities: &Vec>, + ref_entities: &[IdentifiableResult<(EXGeoEntity, ProcessedEntityMesh)>], platform: Platform, ) -> Vec<(u32, Arc>)> { let mut ref_renderers = vec![]; @@ -217,12 +217,7 @@ pub fn read_from_file(edb: &mut EdbFile) -> Vec { continue; } - if map.triggers[ei] - .links - .iter() - .find(|v| **v == i as i32) - .is_some() - { + if map.triggers[ei].links.iter().any(|v| *v == i as i32) { map.triggers[i].incoming_links.push(ei as i32); } } diff --git a/eurochef/gui/src/render/billboard.rs b/eurochef/gui/src/render/billboard.rs index 549f93a..46598da 100644 --- a/eurochef/gui/src/render/billboard.rs +++ b/eurochef/gui/src/render/billboard.rs @@ -19,7 +19,7 @@ impl BillboardRenderer { }) } - const VERTEX_DATA: &[[f32; 5]] = &[ + const VERTEX_DATA: &'static [[f32; 5]] = &[ [-0.5, -0.5, 0.0, 0.0, 1.0], [-0.5, 0.5, 0.0, 0.0, 0.0], [0.5, -0.5, 0.0, 1.0, 1.0], diff --git a/eurochef/gui/src/render/camera.rs b/eurochef/gui/src/render/camera.rs index f4ba645..4520ad8 100644 --- a/eurochef/gui/src/render/camera.rs +++ b/eurochef/gui/src/render/camera.rs @@ -79,15 +79,12 @@ impl Camera3D for ArcBallCamera { fn update(&mut self, ui: &egui::Ui, response: Option<&egui::Response>, _delta: f32) { if let Some(multi_touch) = ui.ctx().multi_touch() { self.zoom += -(multi_touch.zoom_delta - 1.0); - } else { - if let Some(response) = &response { - if response.dragged_by(egui::PointerButton::Primary) - || response.dragged_by(egui::PointerButton::Middle) - { - let mouse_delta = response.drag_delta(); - self.orientation += - Vec2::new(mouse_delta.y as f32 * 0.8, mouse_delta.x as f32) * 0.15; - } + } else if let Some(response) = &response { + if response.dragged_by(egui::PointerButton::Primary) + || response.dragged_by(egui::PointerButton::Middle) + { + let mouse_delta = response.drag_delta(); + self.orientation += Vec2::new(mouse_delta.y * 0.8, mouse_delta.x) * 0.15; } } @@ -227,7 +224,7 @@ impl Camera3D for FpsCamera { } let mouse_delta = response.drag_delta(); - self.orientation += Vec2::new(mouse_delta.y as f32 * 0.8, mouse_delta.x as f32) * 0.15; + self.orientation += Vec2::new(mouse_delta.y * 0.8, mouse_delta.x) * 0.15; } let mut speed = delta * zoom_factor(self.speed_mul) * 10.0; diff --git a/eurochef/gui/src/render/entity.rs b/eurochef/gui/src/render/entity.rs index 4c06545..70cff51 100644 --- a/eurochef/gui/src/render/entity.rs +++ b/eurochef/gui/src/render/entity.rs @@ -330,7 +330,7 @@ impl EntityRenderer { scroll = tex.scroll * time as f32; - if tex.frames.len() > 0 { + if !tex.frames.is_empty() { gl.bind_texture( glow::TEXTURE_2D, Some(tex.frames[(time as f32 / frame_time) as usize % tex.frames.len()]), diff --git a/eurochef/gui/src/render/mod.rs b/eurochef/gui/src/render/mod.rs index 56e0cf6..9916f94 100644 --- a/eurochef/gui/src/render/mod.rs +++ b/eurochef/gui/src/render/mod.rs @@ -36,7 +36,7 @@ impl RenderUniforms { aspect_ratio: f32, time: f32, ) { - let mut aspect_ratio_vert = (1.0 / aspect_ratio).max(1.0); + let aspect_ratio_vert = (1.0 / aspect_ratio).max(1.0); let mut projection = if orthographic { glam::Mat4::orthographic_rh_gl( @@ -154,9 +154,9 @@ impl RenderStore { } } - pub fn is_file_loaded(&self, file: Hashcode) -> bool { - self.files.contains_key(&file) - } + // pub fn is_file_loaded(&self, file: Hashcode) -> bool { + // self.files.contains_key(&file) + // } pub fn is_object_loaded(&self, file: Hashcode, hashcode: Hashcode) -> bool { match hashcode.base() { diff --git a/eurochef/gui/src/render/trigger.rs b/eurochef/gui/src/render/trigger.rs index e68ee2d..fc9ff9e 100644 --- a/eurochef/gui/src/render/trigger.rs +++ b/eurochef/gui/src/render/trigger.rs @@ -71,7 +71,7 @@ pub struct SelectCubeRenderer { } impl SelectCubeRenderer { - const VERTEX_DATA: &[[f32; 3]] = &[ + const VERTEX_DATA: &'static [[f32; 3]] = &[ [0.5, -0.5, 0.5], // Bottom, NE (0) [0.5, -0.5, -0.5], // Bottom, SE (1) [-0.5, -0.5, -0.5], // Bottom, SW (2) @@ -82,7 +82,7 @@ impl SelectCubeRenderer { [-0.5, 0.5, 0.5], // Top, NW (7) ]; - const INDEX_DATA: &[u8] = &[ + const INDEX_DATA: &'static [u8] = &[ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7, ]; @@ -267,21 +267,21 @@ impl CollisionDatumRenderer { gl.bind_buffer(glow::ARRAY_BUFFER, Some(vertex_buffer)); gl.buffer_data_u8_slice( glow::ARRAY_BUFFER, - bytemuck::cast_slice(&vertices), + bytemuck::cast_slice(vertices), glow::STATIC_DRAW, ); let index_buffer_tris = gl.create_buffer().unwrap(); gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, Some(index_buffer_tris)); gl.buffer_data_u8_slice( glow::ELEMENT_ARRAY_BUFFER, - bytemuck::cast_slice(&indices), + bytemuck::cast_slice(indices), glow::STATIC_DRAW, ); let index_buffer_lines = gl.create_buffer().unwrap(); gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, Some(index_buffer_lines)); gl.buffer_data_u8_slice( glow::ELEMENT_ARRAY_BUFFER, - bytemuck::cast_slice(&indices_outline), + bytemuck::cast_slice(indices_outline), glow::STATIC_DRAW, ); diff --git a/eurochef/gui/src/scripts.rs b/eurochef/gui/src/scripts.rs index f5d7760..6192866 100644 --- a/eurochef/gui/src/scripts.rs +++ b/eurochef/gui/src/scripts.rs @@ -369,7 +369,7 @@ impl ScriptListPanel { *file, ), UXGeoScriptCommandData::Event { event_type, data } => { - extra_info = hex::encode(&data); + extra_info = hex::encode(data); ( Self::COMMAND_COLOR_EVENT, format!("Event {}", format_hashcode(&self.hashcodes, *event_type)), @@ -381,7 +381,7 @@ impl ScriptListPanel { continue; } - extra_info = hex::encode(&data); + extra_info = hex::encode(data); ( Self::COMMAND_COLOR_UNKNOWN, format!("Unknown 0x{cmd:x}"), diff --git a/eurochef/gui/src/textures.rs b/eurochef/gui/src/textures.rs index a282fda..e4b07ea 100644 --- a/eurochef/gui/src/textures.rs +++ b/eurochef/gui/src/textures.rs @@ -61,7 +61,7 @@ impl TextureList { format!("{:08x}", it.hashcode), egui::ColorImage::from_rgba_unmultiplied( [t.width as usize, t.height as usize], - &f, + f, ), egui::TextureOptions::default(), ) @@ -108,14 +108,12 @@ impl TextureList { let frame_time = (1. / t.framerate as f32) * frametime_scale; let frames = &self.egui_textures[&it.hashcode]; - let current = if frames.len() == 0 { + let current = if frames.is_empty() { &self.fallback_texture + } else if frames.len() > 1 { + &frames[(time / frame_time) as usize % frames.len()] } else { - if frames.len() > 1 { - &frames[(time / frame_time) as usize % frames.len()] - } else { - &frames[0] - } + &frames[0] }; let diagnostics = t.diagnostics.to_strings(); @@ -164,20 +162,19 @@ impl TextureList { let (rect, response) = ui.allocate_exact_size(egui::vec2(128., 128.) * self.zoom, egui::Sense::click()); - - ui.painter().rect_filled( + ui.painter().rect_filled( rect, egui::Rounding::none(), Color32::BLACK, ); - - ui.painter().text( - rect.left_top() + egui::vec2(24., 24.), + + ui.painter().text(rect.left_top() + egui::vec2(24., 24.), egui::Align2::CENTER_CENTER, font_awesome::LINK, egui::FontId::proportional(24.), Color32::RED, ); + response.on_hover_ui(|ui| { ui.colored_label(Color32::LIGHT_RED, format!( "Texture {:08x} is a reference to texture {:08x} in file {:08x}", @@ -191,15 +188,12 @@ impl TextureList { continue; } - let (rect, response) = - ui.allocate_exact_size(egui::vec2(128., 128.) * self.zoom, egui::Sense::click()); - - ui.painter().rect_filled( - rect, + let (rect, response) = ui.allocate_exact_size(egui::vec2(128., 128.) * self.zoom, egui::Sense::click()); + ui.painter().rect_filled(rect, egui::Rounding::none(), Color32::BLACK, ); - + ui.painter().text( rect.left_top() + egui::vec2(24., 24.), egui::Align2::CENTER_CENTER, @@ -207,14 +201,14 @@ impl TextureList { egui::FontId::proportional(24.), Color32::RED, ); - - response.on_hover_ui(|ui| { - ui.label(format!( - "Texture {:08x} failed:", - it.hashcode - )); - ui.colored_label(Color32::LIGHT_RED, cutoff_string(strip_ansi_codes(&format!("{e:?}")), 1024)); - }); + + response.on_hover_ui(|ui| { + ui.label(format!( + "Texture {:08x} failed:", + it.hashcode + )); + ui.colored_label(Color32::LIGHT_RED, cutoff_string(strip_ansi_codes(&format!("{e:?}")), 1024)); + }); }, } } @@ -233,22 +227,20 @@ impl TextureList { egui::Window::new("Texture Viewer") .open(&mut window_open) .collapsible(false) - .default_height(ctx.available_rect().height() * 0.70 as f32) + .default_height(ctx.available_rect().height() * 0.70_f32) .show(ctx, |ui| { let time = self.start_time.elapsed().as_secs_f32(); let frametime_scale = t.frame_count as f32 / t.frames.len() as f32; let frame_time = (1. / t.framerate as f32) * frametime_scale; let frames = &self.egui_textures[&it.hashcode]; - let current = if frames.len() > 0 { + let current = if !frames.is_empty() { &frames[(time / frame_time) as usize % frames.len()] } else { &frames[0] }; - if let pos = ctx.input(|i| i.zoom_delta()) { - self.enlarged_zoom *= pos; - } + self.enlarged_zoom *= ctx.input(|i| i.zoom_delta()); egui::Image::new(current, current.size_vec2() * self.enlarged_zoom).ui(ui); diff --git a/eurochef/shared/src/hashcodes.rs b/eurochef/shared/src/hashcodes.rs index 9a10fe7..7a7a449 100644 --- a/eurochef/shared/src/hashcodes.rs +++ b/eurochef/shared/src/hashcodes.rs @@ -3,7 +3,7 @@ use nohash_hasher::IntMap; use tracing::info; pub fn parse_hashcodes(string: &str) -> IntMap { - let res: IntMap = string.lines().filter_map(|l| parse_hashcode(l)).collect(); + let res: IntMap = string.lines().filter_map(parse_hashcode).collect(); let base_count = res .values() diff --git a/eurochef/shared/src/maps.rs b/eurochef/shared/src/maps.rs index d3b66e1..e3f1dbf 100644 --- a/eurochef/shared/src/maps.rs +++ b/eurochef/shared/src/maps.rs @@ -98,7 +98,9 @@ impl TriggerValue { #[derive(Copy, Clone, Debug, Deserialize)] #[serde(rename_all = "lowercase")] +#[derive(Default)] pub enum DefinitionDataType { + #[default] Unknown32, U32, Float, @@ -164,22 +166,14 @@ pub fn format_hashcode(hashcodes: &IntMap, hc: Hashcode) -> St } else { format!("{hc_base_stripped}_Unknown_{hc:08x}") } + } else if is_local { + format!("HT_Local_Invalid_{hc:08x}") } else { - if is_local { - format!("HT_Local_Invalid_{hc:08x}") - } else { - format!("HT_Invalid_{hc:08x}") - } + format!("HT_Invalid_{hc:08x}") } } } -impl Default for DefinitionDataType { - fn default() -> Self { - DefinitionDataType::Unknown32 - } -} - // https://github.com/Swyter/poptools/blob/9a22651d7cb16a1edb7894c36e9695138b25b2c1/pop_djinn_sav.bt#L32 fn human_num(v: u32) -> String { let i = v as i32; @@ -194,5 +188,5 @@ fn human_num(v: u32) -> String { if f > 0.003 && f < 1e7 { return format!("{f:.2}"); } - return format!("0x{v:x}/{f:.2}"); + format!("0x{v:x}/{f:.2}") } diff --git a/eurochef/shared/src/platform/texture/gx.rs b/eurochef/shared/src/platform/texture/gx.rs index da442d6..9fef0f2 100644 --- a/eurochef/shared/src/platform/texture/gx.rs +++ b/eurochef/shared/src/platform/texture/gx.rs @@ -97,7 +97,7 @@ impl TextureDecoder for GxTextureDecoder { let mut index = 0; for y in 0..height { for x in 0..width { - let alpha = input[index * 2 + 0]; + let alpha = input[index * 2]; let illuminance = input[index * 2 + 1]; buffer[(x, y)] = [illuminance, illuminance, illuminance, alpha].into(); @@ -157,9 +157,9 @@ impl TextureDecoder for GxTextureDecoder { ensure!(output.len() == buffer.len()); output.copy_from_slice(&buffer); } - InternalFormat::CMPR => { + InternalFormat::Cmpr => { if rounded_width != width || rounded_height != height { - anyhow::bail!("Odd resolutions on CMPR are not supported yet!"); + anyhow::bail!("Odd resolutions on Cmpr are not supported yet!"); } let mut index = 0; @@ -204,11 +204,11 @@ impl TextureDecoder for GxTextureDecoder { } } - if fmt != InternalFormat::CMPR && fmt != InternalFormat::RGBA8 { + if fmt != InternalFormat::Cmpr && fmt != InternalFormat::RGBA8 { let mut src_index = 0; let (blockw, blockh) = fmt.block_size(); - for y in (0..height as u32).step_by(blockh) { - for x in (0..width as u32).step_by(blockw) { + for y in (0..height).step_by(blockh) { + for x in (0..width).step_by(blockw) { for by in 0..blockh as u32 { for bx in 0..blockw as u32 { let (sx, sy) = (src_index % width, src_index / width); @@ -244,7 +244,7 @@ enum InternalFormat { C4 = 8, C8 = 9, C14X2 = 10, - CMPR = 14, + Cmpr = 14, } impl InternalFormat { @@ -260,7 +260,7 @@ impl InternalFormat { Self::C4 => 4, Self::C8 => 8, Self::C14X2 => 16, - Self::CMPR => 4, + Self::Cmpr => 4, } } @@ -276,13 +276,13 @@ impl InternalFormat { Self::C4 => (8, 8), Self::C8 => (8, 4), Self::C14X2 => (4, 4), - Self::CMPR => (8, 8), + Self::Cmpr => (8, 8), } } pub fn from_exformat(fmt: u8) -> anyhow::Result { Ok(match fmt { - 0 => Self::CMPR, + 0 => Self::Cmpr, 1 => Self::RGBA8, 3 => Self::RGB5A3, 4 => Self::I4, @@ -343,7 +343,7 @@ fn decode_dxt_block(dst: &mut [u8], src: &[u8], pitch: u32) -> anyhow::Result<() for y in 0..4 { let mut val = lines[y]; for x in 0..4 { - let offset = (y as usize * pitch as usize + x) * 4; + let offset = (y * pitch as usize + x) * 4; // ensure!(offset + 4 < dst.len()); diff --git a/eurochef/shared/src/platform/texture/pc.rs b/eurochef/shared/src/platform/texture/pc.rs index d54a588..eb80059 100644 --- a/eurochef/shared/src/platform/texture/pc.rs +++ b/eurochef/shared/src/platform/texture/pc.rs @@ -86,7 +86,7 @@ impl TextureDecoder for PcTextureDecoder { let r = (byte[1] & 0x7c) >> 2; let a = byte[1] >> 7; - output[(x, y)] = [r as u8 * 8, g as u8 * 8, b as u8 * 8, a as u8 * 255].into(); + output[(x, y)] = [r * 8, g * 8, b * 8, a * 255].into(); } } _ => { diff --git a/eurochef/shared/src/platform/texture/xbox.rs b/eurochef/shared/src/platform/texture/xbox.rs index 2d50512..37d7b34 100644 --- a/eurochef/shared/src/platform/texture/xbox.rs +++ b/eurochef/shared/src/platform/texture/xbox.rs @@ -59,7 +59,7 @@ impl TextureDecoder for XboxTextureDecoder { } InternalFormat::ARGB8 | InternalFormat::ARGB8Linear => { for (i, bytes) in input.chunks_exact(4).enumerate() { - buffer[i * 4 + 0] = bytes[2]; + buffer[i * 4] = bytes[2]; buffer[i * 4 + 1] = bytes[1]; buffer[i * 4 + 2] = bytes[0]; buffer[i * 4 + 3] = bytes[3]; @@ -71,7 +71,7 @@ impl TextureDecoder for XboxTextureDecoder { let g = bytes[0] >> 4; let b = bytes[1] & 0x0f; let a = bytes[1] >> 4; - buffer[i * 4 + 0] = (b << 4) | b; + buffer[i * 4] = (b << 4) | b; buffer[i * 4 + 1] = (g << 4) | g; buffer[i * 4 + 2] = (r << 4) | r; buffer[i * 4 + 3] = (a << 4) | a; @@ -83,7 +83,7 @@ impl TextureDecoder for XboxTextureDecoder { let b = bytes[0] & 0x1f; let g = (bytes[0] >> 5) | ((bytes[1] & 0x07) << 3); let r = bytes[1] >> 3; - buffer[i * 4 + 0] = (b << 3) | (b >> 2); + buffer[i * 4] = (b << 3) | (b >> 2); buffer[i * 4 + 1] = (g << 2) | (g >> 4); buffer[i * 4 + 2] = (r << 3) | (r >> 2); buffer[i * 4 + 3] = 255; @@ -97,10 +97,10 @@ impl TextureDecoder for XboxTextureDecoder { let r = (byte[1] & 0x7c) >> 2; let a = byte[1] >> 7; - buffer[i * 4 + 0] = r as u8 * 8; - buffer[i * 4 + 1] = g as u8 * 8; - buffer[i * 4 + 2] = b as u8 * 8; - buffer[i * 4 + 3] = a as u8 * 255; + buffer[i * 4] = r * 8; + buffer[i * 4 + 1] = g * 8; + buffer[i * 4 + 2] = b * 8; + buffer[i * 4 + 3] = a * 255; } } InternalFormat::P8 => { @@ -122,8 +122,7 @@ impl TextureDecoder for XboxTextureDecoder { if fmt.is_swizzled() { for y in 0..height { for x in 0..width { - let load_offset = - deswizzle(x as u32, y as u32, width as u32, height as u32) as usize; + let load_offset = deswizzle(x, y, width, height) as usize; let pixel = &buffer[load_offset * 4..load_offset * 4 + 4]; @@ -153,7 +152,7 @@ fn deswizzle(x: u32, y: u32, width: u32, height: u32) -> u32 { // At least one of width and height will have run out of most-significant bits offset |= ((x | y) >> shift) << (shift * 2); - return offset; + offset } #[derive(Debug, N)] diff --git a/eurochef/shared/src/platform/texture/xenon.rs b/eurochef/shared/src/platform/texture/xenon.rs index 6b205c6..fff7776 100644 --- a/eurochef/shared/src/platform/texture/xenon.rs +++ b/eurochef/shared/src/platform/texture/xenon.rs @@ -63,7 +63,7 @@ impl TextureDecoder for XenonTextureDecoder { let g = bytes[1] >> 4; let b = bytes[0] & 0x0f; let a = bytes[0] >> 4; - buffer[i * 4 + 0] = (b << 4) | b; + buffer[i * 4] = (b << 4) | b; buffer[i * 4 + 1] = (g << 4) | g; buffer[i * 4 + 2] = (r << 4) | r; buffer[i * 4 + 3] = (a << 4) | a; @@ -75,7 +75,7 @@ impl TextureDecoder for XenonTextureDecoder { let r = bytes[1] & 0x1f; let g = (bytes[1] >> 5) | ((bytes[0] & 0x07) << 3); let b = bytes[0] >> 3; - buffer[i * 4 + 0] = (b << 3) | (b >> 2); + buffer[i * 4] = (b << 3) | (b >> 2); buffer[i * 4 + 1] = (g << 2) | (g >> 4); buffer[i * 4 + 2] = (r << 3) | (r >> 2); buffer[i * 4 + 3] = 255; @@ -83,7 +83,7 @@ impl TextureDecoder for XenonTextureDecoder { } InternalFormat::ARGB8 => { for (i, bytes) in input.chunks_exact(4).enumerate() { - buffer[i * 4 + 0] = bytes[1]; + buffer[i * 4] = bytes[1]; buffer[i * 4 + 1] = bytes[2]; buffer[i * 4 + 2] = bytes[3]; buffer[i * 4 + 3] = bytes[0]; @@ -100,9 +100,7 @@ impl TextureDecoder for XenonTextureDecoder { fn swap_endianness16(buffer: &mut [u8]) { for i in (0..buffer.len()).step_by(2) { - let a = buffer[i]; - buffer[i] = buffer[i + 1]; - buffer[i + 1] = a; + buffer.swap(i, i + 1); } } diff --git a/eurochef/shared/src/textures.rs b/eurochef/shared/src/textures.rs index 89ea66b..86e995a 100644 --- a/eurochef/shared/src/textures.rs +++ b/eurochef/shared/src/textures.rs @@ -49,7 +49,7 @@ impl UXGeoTexture { i, IdentifiableResult::new( t.common.hashcode, - Self::read(t.common.address, edb, &texture_decoder, t.flags), + Self::read(t.common.address, edb, texture_decoder.as_ref(), t.flags), ), )) } @@ -77,7 +77,7 @@ impl UXGeoTexture { i, IdentifiableResult::new( t.common.hashcode, - Self::read(t.common.address, edb, &texture_decoder, t.flags), + Self::read(t.common.address, edb, texture_decoder.as_ref(), t.flags), ), )) } @@ -88,7 +88,7 @@ impl UXGeoTexture { pub fn read( address: u32, edb: &mut EdbFile, - texture_decoder: &Box, + texture_decoder: &dyn TextureDecoder, flags: u32, ) -> anyhow::Result { edb.seek(std::io::SeekFrom::Start(address as u64))?; @@ -167,7 +167,7 @@ impl UXGeoTexture { edb.read_exact(&mut data) .context(format!("Failed to read frame {i}"))?; - if edb.header.version == 156 && clut.len() == 0 { + if edb.header.version == 156 && clut.is_empty() { let clut_size = texture_decoder.get_clut_size(tex.format)?; clut.resize(clut_size, 0); edb.read_exact(&mut clut) @@ -177,7 +177,7 @@ impl UXGeoTexture { texture_decoder .decode( &data, - if clut.len() > 0 { Some(&clut) } else { None }, + if !clut.is_empty() { Some(&clut) } else { None }, &mut output, tex.width as u32, tex.height as u32,