wolfrpg_map_parser/command/number_condition_command/
condition.rs

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