wolfrpg_map_parser/command/chip_management_command/
overwrite_map_chips.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::byte_utils::as_u32_le;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct OverwriteMapChips{
    layer: u32,
    position_x: u32,
    position_y: u32,
    width: u32,
    height: u32,
    chip: u32
}

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

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

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

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

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

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

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

        offset += 3; // Command end signature

        (offset, Self {
            layer,
            position_x,
            position_y,
            width,
            height,
            chip
        })
    }

    pub fn layer(&self) -> u32 {
        self.layer
    }
    
    pub fn layer_mut(&mut self) -> &mut u32 {
        &mut self.layer
    }

    pub fn position_x(&self) -> u32 {
        self.position_x
    }
    
    pub fn position_x_mut(&mut self) -> &mut u32 {
        &mut self.position_x
    }

    pub fn position_y(&self) -> u32 {
        self.position_y
    }
    
    pub fn position_y_mut(&mut self) -> &mut u32 {
        &mut self.position_y
    }

    pub fn width(&self) -> u32 {
        self.width
    }
    
    pub fn width_mut(&mut self) -> &mut u32 {
        &mut self.width
    }

    pub fn height(&self) -> u32 {
        self.height
    }
    
    pub fn height_mut(&mut self) -> &mut u32 {
        &mut self.height
    }

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