wolfrpg_map_parser/command/chip_management_command/
map_chip_settings.rs

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
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use crate::byte_utils::as_u32_le;
use crate::command::chip_management_command::options::Options;

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq)]
pub struct MapChipSettings {
    chip: u32,
    options: Options
}

impl MapChipSettings {
    pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
        let mut offset: usize = 0;

        let chip: u32 = as_u32_le(&bytes[offset..offset + 4]);
        offset += 4;

        let options: u32 = as_u32_le(&bytes[offset..offset + 4]);
        let options: Options = Options::new(options);
        offset += 4;

        offset += 3; // Offset

        (offset, Self {
            chip,
            options
        })
    }

    pub fn chip(&self) -> u32 {
        self.chip
    }
    
    pub fn chip_mut(&mut self) -> &mut Options {
        &mut self.options
    }

    pub fn options(&self) -> &Options {
        &self.options
    }
    
    pub fn options_mut(&mut self) -> &mut Options {
        &mut self.options
    }
}