9e2eb5a07b
This commit also implements a custom error type to capture why a World/Board failed to load -- which I might end up tearing out.
44 lines
1.2 KiB
Rust
44 lines
1.2 KiB
Rust
mod world;
|
|
|
|
use std::{env, error::Error, fs, process::exit};
|
|
use world::World;
|
|
|
|
fn to_latin1(bytes: &[u8]) -> String {
|
|
bytes.iter().map(|&x| x as char).collect()
|
|
}
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
let args: Vec<String> = env::args().collect();
|
|
if args.len() != 2 {
|
|
eprintln!("Usage: {} WORLD_FILE", args[0]);
|
|
exit(1);
|
|
}
|
|
|
|
let bytes = fs::read(&args[1])?;
|
|
let mut world = World::from_bytes(&bytes)?;
|
|
|
|
// Print some of the data parsed.
|
|
// TODO: Implement some macros, or other code modification
|
|
// Then, we can try writing a copy to disk.
|
|
println!("num boards: {}", &world.boards.len());
|
|
for board in &world.boards {
|
|
println!("board: {}", to_latin1(&board.name));
|
|
for stat in &board.stats {
|
|
let (x, y) = (stat.x as usize, stat.y as usize);
|
|
println!(
|
|
" stat at ({}, {}): {:?}, {:?}",
|
|
x,
|
|
y,
|
|
board.terrain[(x - 1) + (y - 1) * 60],
|
|
to_latin1(&stat.code)
|
|
);
|
|
}
|
|
}
|
|
|
|
// Try to write a modified world file
|
|
world.boards.reverse();
|
|
fs::write("tmp.zzt", world.to_bytes()?)?;
|
|
|
|
Ok(())
|
|
}
|