wolfrpg_map_parser/command/effect_command/
scroll_screen.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
58
59
60
61
62
63
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::byte_utils::as_u32_le;
use crate::command::effect_command::scroll_screen::options::Options;

pub mod options;
pub mod scroll_operation;
pub mod scroll_speed;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct ScrollScreen {
    options: Options,
    x: u32,
    y: u32
}

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

        let options: u32 = as_u32_le(&bytes[offset..offset+4]);
        let options: Options = Options::new(options);
        offset += 4;

        let x: u32 = as_u32_le(&bytes[offset..offset+4]);
        offset += 4;

        let y: u32 = as_u32_le(&bytes[offset..offset+4]);
        offset += 4;

        offset += 3; // Command end signature

        (offset, Self {
            options,
            x,
            y
        })
    }

    pub fn options(&self) -> &Options {
        &self.options
    }
    
    pub fn options_mut(&mut self) -> &mut Options {
        &mut self.options
    }

    pub fn x(&self) -> u32 {
        self.x
    }
    
    pub fn x_mut(&mut self) -> &mut u32 {
        &mut self.x
    }

    pub fn y(&self) -> u32 {
        self.y
    }
    
    pub fn y_mut(&mut self) -> &mut u32 {
        &mut self.y
    }
}