use std::{env, fs::File};
use image::Pixel;
use caco::agnostic::{FlatClodMut, FormattableClumpMut};
use caco::wad::DoomWad;
use caco::fmts::d2::palette::Playpal;
fn main() {
let args = env::args().skip(1).collect::<Vec<String>>();
if args.len() != 2 {
eprintln!("please provide an input wad and output wad\ncargo run --example invert_palettes in.wad out.wad");
std::process::exit(1);
}
let mut in_wad_file = File::open(&args[0])
.expect(&format!("couldn't open {}", &args[0]));
let mut out_wad_file = File::create(&args[1])
.expect(&format!("couldn't open {}", &args[1]));
let mut wad = DoomWad::load(&mut in_wad_file).expect("input wad was invalid format");
if let Some(l) = wad.clump_by_name_mut("PLAYPAL") {
if let Ok(mut p) = l.try_interpret_as::<Playpal>() {
for t in &mut p.tints {
for c in &mut t.colors { c.invert(); }
}
p.commit().expect("somehow the palette data became invalid (literally impossible...)");
}
}
wad.save(&mut out_wad_file).expect("couldn't save wad out...");
}