forked from StrafesNET/map-tool
fine tune closures
This commit is contained in:
parent
91f452a94b
commit
7b1b381064
36
src/main.rs
36
src/main.rs
@ -1104,21 +1104,9 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->
|
||||
let mut texture_file_name2=texture_file_name.clone();
|
||||
texture_file_name.set_extension("vtf");
|
||||
texture_file_name2.set_extension("vmt");
|
||||
println!("texture_name={:?}",texture_file_name);
|
||||
let mut found_texture=false;
|
||||
//LMAO imagine having to write type names
|
||||
let mut f=|search_file_name,write_file_name|{
|
||||
if let Some(mut stuff)=match (zippyt.by_name(search_file_name),tree.get(search_file_name)){
|
||||
(Ok(mut zip_file),None)=>{
|
||||
let mut buf=Vec::new();
|
||||
zip_file.read_to_end(&mut buf)?;
|
||||
Some(buf)
|
||||
},
|
||||
(_,Some(vpk_entry))=>Some(vpk_entry.get()?.to_vec()),
|
||||
_=>None,
|
||||
}{
|
||||
found_texture=true;
|
||||
thread_handles.push(s.spawn(move||{
|
||||
let write_image=|mut stuff,write_file_name|{
|
||||
let image=vtf::from_bytes(&mut stuff)?.highres_image.decode(0)?.to_rgba8();
|
||||
|
||||
let format=if image.width()%4!=0||image.height()%4!=0{
|
||||
@ -1142,12 +1130,24 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->
|
||||
let mut writer = std::io::BufWriter::new(std::fs::File::create(dest)?);
|
||||
dds.write(&mut writer)?;
|
||||
Ok::<(),anyhow::Error>(())
|
||||
}));
|
||||
}
|
||||
Ok::<(),anyhow::Error>(())
|
||||
};
|
||||
f(texture_file_name.as_os_str().to_str().unwrap(),texture_name.clone())?;
|
||||
f(texture_file_name2.as_os_str().to_str().unwrap(),texture_name.clone())?;
|
||||
let mut find_stuff=|search_file_name|{
|
||||
//println!("search_file_name={}",search_file_name);
|
||||
Ok::<Option<Vec<u8>>,anyhow::Error>(match (zippyt.by_name(search_file_name),tree.get(search_file_name)){
|
||||
(Ok(mut zip_file),None)=>{
|
||||
let mut buf=Vec::new();
|
||||
zip_file.read_to_end(&mut buf)?;
|
||||
Some(buf)
|
||||
},
|
||||
(_,Some(vpk_entry))=>Some(vpk_entry.get()?.to_vec()),
|
||||
_=>None,
|
||||
})
|
||||
};
|
||||
if let Some(stuff)=find_stuff(texture_file_name.as_os_str().to_str().unwrap())?{
|
||||
found_texture=true;
|
||||
let texture_name=texture_name.clone();
|
||||
thread_handles.push(s.spawn(move||write_image(stuff,texture_name)));
|
||||
}
|
||||
if !found_texture{
|
||||
println!("no data");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user