Add component_data utility
This commit is contained in:
parent
57cf820ac0
commit
e509969033
1 changed files with 41 additions and 0 deletions
41
examples/component_data.rs
Normal file
41
examples/component_data.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
//! Like `load.rs` but a better format for inspecting component custom data.
|
||||||
|
|
||||||
|
use std::{collections::HashMap, env::args_os, fs::File, io::BufReader, process::exit};
|
||||||
|
|
||||||
|
use blotter::BlotterFile;
|
||||||
|
|
||||||
|
fn main() -> Result<(), blotter::error::Error> {
|
||||||
|
let infile = args_os().nth(1).unwrap_or_else(usage);
|
||||||
|
let mut reader = BufReader::new(File::open(infile)?);
|
||||||
|
let blotter_file = BlotterFile::read(&mut reader)?.migrate();
|
||||||
|
let name_map: HashMap<u16, &str> = blotter_file
|
||||||
|
.component_types
|
||||||
|
.iter()
|
||||||
|
.map(|ty| (ty.numeric_id, ty.text_id.as_str()))
|
||||||
|
.collect();
|
||||||
|
for component in &blotter_file.components {
|
||||||
|
let name = name_map
|
||||||
|
.get(&component.type_id)
|
||||||
|
.copied()
|
||||||
|
.unwrap_or("(unknown)");
|
||||||
|
let data = component
|
||||||
|
.custom_data
|
||||||
|
.as_ref()
|
||||||
|
.map(Vec::as_slice)
|
||||||
|
.unwrap_or(&[]);
|
||||||
|
|
||||||
|
println!();
|
||||||
|
println!("{:?}", name);
|
||||||
|
print!(" ({:03})", data.len());
|
||||||
|
for byte in data {
|
||||||
|
print!(" {:02x}", byte);
|
||||||
|
}
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn usage<T>() -> T {
|
||||||
|
eprintln!("missing argument: input file name");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue