From e833d4c0329987dbf4d59cae0ca733306b367b85 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Wed, 10 Jan 2024 15:58:54 -0800 Subject: [PATCH] tweaks --- src/main.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 803d76e..3165930 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1086,24 +1086,21 @@ fn get_some_texture(material:vmt_parser::material::Material)->AResultAResult>>>(find_stuff:&F,search_name:String)->AResult>{ +fn get_vmtAResult>>>(find_stuff:&F,search_name:String)->AResult{ println!("looking for {}",search_name); if let Some(stuff)=find_stuff(search_name)?{ //decode vmt and then write let stuff=String::from_utf8(stuff)?; let material=vmt_parser::from_str(stuff.as_str())?; println!("vmt material={:?}",material); - return Ok(Some(material)); + return Ok(material); } - Ok(None) + Err(anyhow::Error::msg("vmt not found")) } fn recursive_vmt_loaderAResult>>>(find_stuff:&F,material:vmt_parser::material::Material)->AResult>>{ match get_some_texture(material)?{ - VMTContent::VMT(s)=>match get_vmt(find_stuff,s)?{ - Some(mat)=>recursive_vmt_loader(find_stuff,mat), - None=>Ok(None), - }, + VMTContent::VMT(s)=>recursive_vmt_loader(find_stuff,get_vmt(find_stuff,s)?), VMTContent::VTF(s)=>find_stuff(s), VMTContent::Patch(mat)=>recursive_vmt_loader(find_stuff, mat.resolve(|search_name| @@ -1113,8 +1110,8 @@ fn recursive_vmt_loaderAResult>>>(find_stuff:&F,ma } )? ), - VMTContent::Unsupported=>Ok(None), - VMTContent::Unresolved=>Ok(None), + VMTContent::Unsupported=>Err(anyhow::Error::msg("Unsupported vmt")), + VMTContent::Unresolved=>Err(anyhow::Error::msg("Unresolved vmt")), } } @@ -1219,16 +1216,13 @@ fn extract_textures(paths:Vec,vpk_path:std::path::PathBuf)-> texture_file_name.pop(); texture_file_name.push(stem); //somehow search for both files - let mut texture_file_name2=texture_file_name.clone(); + let mut texture_file_name_vmt=texture_file_name.clone(); texture_file_name.set_extension("vtf"); - texture_file_name2.set_extension("vmt"); + texture_file_name_vmt.set_extension("vmt"); if let Some(stuff)=find_stuff(texture_file_name.to_string_lossy().to_string())?{ return Ok(Some(stuff)) } - if let Some(mat)=get_vmt(&find_stuff,texture_file_name2.to_string_lossy().to_string())?{ - return recursive_vmt_loader(&find_stuff,mat); - } - Ok(None) + recursive_vmt_loader(&find_stuff,get_vmt(&find_stuff,texture_file_name_vmt.to_string_lossy().to_string())?) }; if let Some(stuff)=loader(texture_name.to_string_lossy().to_string())?{ found_texture=true;