wolfrpg_map_parser/command/set_variable_plus_command/
position.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
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::byte_utils::as_u32_le;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct Position {
    target: u8,
    position_x: u32,
    position_y: u32
}

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

        let target: u8 = bytes[offset];
        offset += 1;

        offset += 1; // Unknown, probably padding

        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;

        (offset, Self {
            target,
            position_x,
            position_y,
        })
    }

    pub fn target(&self) -> u8 {
        self.target
    }

    pub fn target_mut(&mut self) -> &mut u8 {
        &mut self.target
    }

    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
    }
}