wolfrpg_map_parser/command/event_control_command/
set_transition.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_u16_le, as_u32_le};

#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct SetTransition {
    transition_number: u32,
    fade_frames: u16,
    wait_until_done: bool
}

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

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

        let fade_frames: u16 = as_u16_le(&bytes[offset..offset+2]);
        offset += 2;

        let wait_until_done: bool = bytes[offset] != 0;
        offset += 1;

        offset += 4; // Command end signature

        (offset, Self {
            transition_number,
            fade_frames,
            wait_until_done
        })
    }

    pub fn transition_number(&self) -> u32 {
        self.transition_number
    }
    
    pub fn transition_number_mut(&mut self) -> &mut u32 {
        &mut self.transition_number
    }

    pub fn fade_frames(&self) -> u16 {
        self.fade_frames
    }
    
    pub fn fade_frames_mut(&mut self) -> &mut u16 {
        &mut self.fade_frames
    }

    pub fn wait_until_done(&self) -> bool {
        self.wait_until_done
    }
    
    pub fn wait_until_done_mut(&mut self) -> &mut bool {
        &mut self.wait_until_done
    }
}