1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! ### Parsers for the data
use super::file::*;
use assembly_core::nom::{
    number::complete::{le_f32, le_u32, le_u8},
    IResult,
};

pub fn parse_terrain_header(input: &[u8]) -> IResult<&[u8], TerrainHeader> {
    let (input, version) = le_u8(input)?;
    let (input, value_1) = le_u8(input)?;
    let (input, value_2) = le_u8(input)?;
    let (input, chunk_count) = le_u32(input)?;
    let (input, width_in_chunks) = le_u32(input)?;
    let (input, height_in_chunks) = le_u32(input)?;
    Ok((
        input,
        TerrainHeader {
            version,
            value_1,
            value_2,
            chunk_count,
            width_in_chunks,
            height_in_chunks,
        },
    ))
}

#[allow(clippy::just_underscores_and_digits)]
pub fn parse_height_map_header(input: &[u8]) -> IResult<&[u8], HeightMapHeader> {
    let (input, width) = le_u32(input)?;
    let (input, height) = le_u32(input)?;
    let (input, pos_x) = le_f32(input)?;
    let (input, pos_z) = le_f32(input)?;
    let (input, _1) = le_u32(input)?;
    let (input, _2) = le_u32(input)?;
    let (input, _3) = le_u32(input)?;
    let (input, _4) = le_u32(input)?;
    let (input, _5) = le_f32(input)?;
    Ok((
        input,
        HeightMapHeader {
            width,
            height,
            pos_x,
            pos_z,
            _1,
            _2,
            _3,
            _4,
            _5,
        },
    ))
}