spring_cartographer_rs/
smt.rs

1use binrw::BinRead;
2
3#[derive(BinRead, Debug, Clone)]
4#[br(magic = b"spring tilefile\0", little)]
5pub struct SMT {
6    pub header: SMTHeader,
7
8    #[br(count = header.num_tiles)]
9    pub tiles: Vec<Tile>,
10}
11
12#[derive(BinRead, Debug, Clone)]
13#[br()]
14pub struct SMTHeader {
15    pub version: i32,          // Should just be one
16    pub num_tiles: u32,        //
17    pub tile_size: u32,        // Should just be 32
18    pub compression_type: i32, // Should always just be one
19}
20
21#[derive(BinRead, Debug, Clone)]
22#[br()]
23pub struct Tile {
24    #[br(count = 512)]
25    pub mip_map32: Vec<u8>,
26    #[br(count = 128)]
27    pub mip_map16: Vec<u8>,
28    #[br(count = 32)]
29    pub mip_map8: Vec<u8>,
30    #[br(count = 8)]
31    pub mip_map4: Vec<u8>,
32}
33
34#[cfg(test)]
35mod test {
36    use super::*;
37
38    #[test]
39    fn test() {
40        let smt_raw = include_bytes!("../.temp/great_divide_v1/maps/Great_Divide.smt");
41
42        let mut c = std::io::Cursor::new(smt_raw);
43
44        let smt = SMT::read(&mut c).unwrap();
45
46        // dbg!(String::from_utf8_lossy(&smt.header.magic_number));
47        dbg!(smt.header);
48        dbg!(smt.tiles.len());
49    }
50}