wolfrpg_map_parser/command/effect_command/
scroll_screen.rs

1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::byte_utils::as_u32_le;
4use crate::command::effect_command::scroll_screen::options::Options;
5
6pub mod options;
7pub mod scroll_operation;
8pub mod scroll_speed;
9
10#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
11#[derive(PartialEq, Clone)]
12pub struct ScrollScreen {
13    options: Options,
14    x: u32,
15    y: u32
16}
17
18impl ScrollScreen {
19    pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
20        let mut offset: usize = 0;
21
22        let options: u32 = as_u32_le(&bytes[offset..offset+4]);
23        let options: Options = Options::new(options);
24        offset += 4;
25
26        let x: u32 = as_u32_le(&bytes[offset..offset+4]);
27        offset += 4;
28
29        let y: u32 = as_u32_le(&bytes[offset..offset+4]);
30        offset += 4;
31
32        offset += 3; // Command end signature
33
34        (offset, Self {
35            options,
36            x,
37            y
38        })
39    }
40
41    pub fn options(&self) -> &Options {
42        &self.options
43    }
44    
45    pub fn options_mut(&mut self) -> &mut Options {
46        &mut self.options
47    }
48
49    pub fn x(&self) -> u32 {
50        self.x
51    }
52    
53    pub fn x_mut(&mut self) -> &mut u32 {
54        &mut self.x
55    }
56
57    pub fn y(&self) -> u32 {
58        self.y
59    }
60    
61    pub fn y_mut(&mut self) -> &mut u32 {
62        &mut self.y
63    }
64}