Mii rendering and parsing library

add vfl-cli

j0.lol 43b035d9 68296dc5

+77 -13
+77 -13
crates/vfl-cli/src/main.rs
··· 3 3 use std::io::BufReader; 4 4 use std::path::PathBuf; 5 5 use vfl::charinfo::nx::BinRead; 6 + use vfl::res::tex::nx::{ResourceTexture, TextureElement}; 6 7 7 8 // TODO: use real names 8 9 // https://github.com/ariankordi/ffl/blob/97eecdf3688f92c4c95cecf5d6ab3e84c0ee42c0/tools/FFLResource.py#L448 ··· 41 42 index: usize, 42 43 output: PathBuf, 43 44 }, 45 + 46 + /// Show existant textures 47 + TextureExists { 48 + #[arg(short, long)] 49 + resource_file: PathBuf, 50 + #[arg(value_enum, short, long)] 51 + texture_type: TextureType, 52 + }, 44 53 } 45 54 46 55 // This is kind of `clap`-slop. I just need a quick debug tool. ··· 62 71 let res_file = std::fs::read(resource_file).unwrap(); 63 72 64 73 // *YandereDev Voice* If only there was a better way... 65 - let texture_element = match texture_type { 66 - TextureType::Hat => res_tex.hat[index], 67 - TextureType::Eye => res_tex.eye[index], 68 - TextureType::Eyebrow => res_tex.eyebrow[index], 69 - TextureType::Beard => res_tex.beard[index], 70 - TextureType::Wrinkle => res_tex.wrinkle[index], 71 - TextureType::Makeup => res_tex.makeup[index], 72 - TextureType::Glass => res_tex.glass[index], 73 - TextureType::Mole => res_tex.mole[index], 74 - TextureType::Mouth => res_tex.mouth[index], 75 - TextureType::Mustache => res_tex.mustache[index], 76 - TextureType::NoseLine => res_tex.noseline[index], 77 - }; 74 + let texture_element = lookup_texture_type(texture_type, index, res_tex).unwrap(); 78 75 let el = texture_element.get_image(&res_file).unwrap().unwrap(); 79 76 el.save(output).unwrap(); 80 77 } 78 + Subcommands::TextureExists { 79 + resource_file, 80 + texture_type, 81 + } => { 82 + let res_tex = ResourceTexture::read(&mut BufReader::new( 83 + File::open(resource_file.clone()).unwrap(), 84 + )) 85 + .unwrap(); 86 + let res_file = std::fs::read(resource_file).unwrap(); 87 + 88 + let mut exists = vec![]; 89 + for index in 0..match texture_type { 90 + TextureType::Hat => res_tex.hat.len(), 91 + TextureType::Eye => res_tex.eye.len(), 92 + TextureType::Eyebrow => res_tex.eyebrow.len(), 93 + TextureType::Beard => res_tex.beard.len(), 94 + TextureType::Wrinkle => res_tex.wrinkle.len(), 95 + TextureType::Makeup => res_tex.makeup.len(), 96 + TextureType::Glass => res_tex.glass.len(), 97 + TextureType::Mole => res_tex.mole.len(), 98 + TextureType::Mouth => res_tex.mouth.len(), 99 + TextureType::Mustache => res_tex.mustache.len(), 100 + TextureType::NoseLine => res_tex.noseline.len(), 101 + } { 102 + let texture_element = lookup_texture_type(texture_type, index, res_tex).unwrap(); 103 + if (texture_element.texture.width == 0 && texture_element.texture.height == 0) 104 + || (texture_element.texture.width == 8 && texture_element.texture.height == 8) 105 + { 106 + exists.push(false); 107 + continue; 108 + } 109 + let texture = texture_element.get_image(&res_file).unwrap(); 110 + 111 + let valid = texture.is_some(); 112 + 113 + exists.push(valid); 114 + } 115 + 116 + println!( 117 + "{:#?}", 118 + exists 119 + .iter() 120 + .enumerate() 121 + .filter_map(|(num, bool)| if *bool { Some(num) } else { None }) 122 + .collect::<Vec<_>>() 123 + ) 124 + } 125 + } 126 + } 127 + 128 + fn lookup_texture_type( 129 + texture_type: TextureType, 130 + index: usize, 131 + res_tex: ResourceTexture, 132 + ) -> Option<TextureElement> { 133 + match texture_type { 134 + TextureType::Hat => res_tex.hat.get(index).copied(), 135 + TextureType::Eye => res_tex.eye.get(index).copied(), 136 + TextureType::Eyebrow => res_tex.eyebrow.get(index).copied(), 137 + TextureType::Beard => res_tex.beard.get(index).copied(), 138 + TextureType::Wrinkle => res_tex.wrinkle.get(index).copied(), 139 + TextureType::Makeup => res_tex.makeup.get(index).copied(), 140 + TextureType::Glass => res_tex.glass.get(index).copied(), 141 + TextureType::Mole => res_tex.mole.get(index).copied(), 142 + TextureType::Mouth => res_tex.mouth.get(index).copied(), 143 + TextureType::Mustache => res_tex.mustache.get(index).copied(), 144 + TextureType::NoseLine => res_tex.noseline.get(index).copied(), 81 145 } 82 146 }