wolfrpg_map_parser/command/effect_command/
base.rs

1pub mod options;
2pub mod effect_type;
3pub mod effect_target;
4pub mod character_effect_type;
5pub mod map_effect_type;
6pub mod picture_effect_type;
7
8#[cfg(feature = "serde")]
9use serde::{Serialize, Deserialize};
10use crate::byte_utils::as_u32_le;
11use crate::command::effect_command::base::options::Options;
12
13#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14#[derive(PartialEq, Clone)]
15pub struct Base {
16    options: Options,
17    duration: u32,
18    target: u32,
19    range: u32,
20    value1: u32,
21    value2: u32,
22    value3: u32
23}
24
25impl Base {
26    pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
27        let mut offset: usize = 0;
28
29        let options: u32 = as_u32_le(&bytes[offset..offset + 4]);
30        let options: Options = Options::new(options);
31        offset += 4;
32
33        let duration: u32 = as_u32_le(&bytes[offset..offset + 4]);
34        offset += 4;
35
36        let target: u32 = as_u32_le(&bytes[offset..offset + 4]);
37        offset += 4;
38
39        let range: u32 = as_u32_le(&bytes[offset..offset + 4]);
40        offset += 4;
41
42        let value1: u32 = as_u32_le(&bytes[offset..offset + 4]);
43        offset += 4;
44
45        let value2: u32 = as_u32_le(&bytes[offset..offset + 4]);
46        offset += 4;
47
48        let value3: u32 = as_u32_le(&bytes[offset..offset + 4]);
49        offset += 4;
50
51        offset += 3; // Command end signature
52
53        (offset, Self {
54            options,
55            duration,
56            target,
57            range,
58            value1,
59            value2,
60            value3
61        })
62    }
63
64    pub fn options(&self) -> &Options {
65        &self.options
66    }
67    
68    pub fn options_mut(&mut self) -> &mut Options {
69        &mut self.options
70    }
71
72    pub fn duration(&self) -> u32 {
73        self.duration
74    }
75    
76    pub fn duration_mut(&mut self) -> &mut u32 {
77        &mut self.duration
78    }
79
80    pub fn target(&self) -> u32 {
81        self.target
82    }
83    
84    pub fn target_mut(&mut self) -> &mut u32 {
85        &mut self.target
86    }
87
88    pub fn range(&self) -> u32 {
89        self.range
90    }
91    
92    pub fn range_mut(&mut self) -> &mut u32 {
93        &mut self.range
94    }
95
96    pub fn value1(&self) -> u32 {
97        self.value1
98    }
99    
100    pub fn value1_mut(&mut self) -> &mut u32 {
101        &mut self.value1
102    }
103
104    pub fn value2(&self) -> u32 {
105        self.value2
106    }
107    
108    pub fn value2_mut(&mut self) -> &mut u32 {
109        &mut self.value2
110    }
111
112    pub fn value3(&self) -> u32 {
113        self.value3
114    }
115    
116    pub fn value3_mut(&mut self) -> &mut u32 {
117        &mut self.value3
118    }
119}