//! Raw token sequence around a key, for one record — the ground truth for
//! "is this field actually defaulted, or is our reader missing it?"
//! Run: pool_window <disc-root> <ID substring> <key>
use sylpheed_formats::idxd::IdxdObject;
use sylpheed_formats::pak::PakArchive;
fn main() {
    let disc = std::env::args().nth(1).unwrap();
    let want = std::env::args().nth(2).unwrap();
    let key = std::env::args().nth(3).unwrap();
    let pak = PakArchive::open(format!("{disc}/dat/GP_MAIN_GAME_E.pak")).unwrap();
    for e in pak.entries() {
        let Ok(b) = pak.read(e) else { continue };
        let Ok(o) = IdxdObject::parse(&b) else { continue };
        let Some(id) = o.get_raw("ID") else { continue };
        if !id.contains(&want) { continue; }
        let t = o.tokens();
        println!("=== {id}   get_f32({key}) = {:?}", o.get_f32(&key));
        for (i, tok) in t.iter().enumerate() {
            if tok == &key {
                let lo = i.saturating_sub(6);
                let hi = (i + 7).min(t.len());
                for j in lo..hi {
                    println!("   [{j}]{} {:?}", if j == i { " <-- key" } else { "        " }, t[j]);
                }
                println!();
            }
        }
    }
}
