Deduplicate unxwb code

This commit is contained in:
Simon Bruder 2020-06-24 17:38:46 +02:00
parent 7dbb8c1e62
commit 8afe245e05
No known key found for this signature in database
GPG key ID: 6F03E0000CC5B62F

View file

@ -102,23 +102,22 @@ fn main() -> Result<()> {
let wave_bank = WaveBank::parse(&xwb_data)?; let wave_bank = WaveBank::parse(&xwb_data)?;
info!("Opened wave bank “{}” from {:?}", wave_bank.name, opts.file); info!("Opened wave bank “{}” from {:?}", wave_bank.name, opts.file);
match opts.single_entry { let entries = match opts.single_entry {
Some(name) => { Some(name) => match wave_bank.sounds.get(&name) {
let sound = match wave_bank.sounds.get(&name) { Some(_) => vec![name],
Some(sound) => sound, None => return error(format!("Entry {} not found in wave bank", name)),
None => return error(format!("Entry {} not found in wave bank", name)), },
}; None => wave_bank.sounds.keys().cloned().collect(),
fs::write(format!("{}.wav", name), &sound.to_wav()?)?; };
}
None => { for (name, sound) in wave_bank.sounds {
for (name, sound) in wave_bank.sounds { if entries.contains(&name) {
if opts.list_entries { if opts.list_entries {
println!("{}", name); println!("{}", name);
continue; continue;
}
info!("Extracting {}", name);
fs::write(format!("{}.wav", name), &sound.to_wav()?)?;
} }
info!("Extracting {}", name);
fs::write(format!("{}.wav", name), &sound.to_wav()?)?;
} }
} }
} }