wolfrpg_map_parser/command/set_variable_plus_command/
position.rs

1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::byte_utils::as_u32_le;
4
5#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6#[derive(PartialEq, Clone)]
7pub struct Position {
8    target: u8,
9    position_x: u32,
10    position_y: u32
11}
12
13impl Position {
14    pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
15        let mut offset: usize = 0;
16
17        let target: u8 = bytes[offset];
18        offset += 1;
19
20        offset += 1; // Unknown, probably padding
21
22        let position_x: u32 = as_u32_le(&bytes[offset..offset+4]);
23        offset += 4;
24
25        let position_y: u32 = as_u32_le(&bytes[offset..offset+4]);
26        offset += 4;
27
28        (offset, Self {
29            target,
30            position_x,
31            position_y,
32        })
33    }
34
35    pub fn target(&self) -> u8 {
36        self.target
37    }
38
39    pub fn target_mut(&mut self) -> &mut u8 {
40        &mut self.target
41    }
42
43    pub fn position_x(&self) -> u32 {
44        self.position_x
45    }
46
47    pub fn position_x_mut(&mut self) -> &mut u32 {
48        &mut self.position_x
49    }
50
51    pub fn position_y(&self) -> u32 {
52        self.position_y
53    }
54
55    pub fn position_y_mut(&mut self) -> &mut u32 {
56        &mut self.position_y
57    }
58}