wolfrpg_map_parser/command/event_control_command/
set_transition.rs

1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::byte_utils::{as_u16_le, as_u32_le};
4
5#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6#[derive(PartialEq, Clone)]
7pub struct SetTransition {
8    transition_number: u32,
9    fade_frames: u16,
10    wait_until_done: bool
11}
12
13impl SetTransition {
14    pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
15        let mut offset: usize = 0;
16
17        let transition_number: u32 = as_u32_le(&bytes[offset..offset+4]);
18        offset += 4;
19
20        let fade_frames: u16 = as_u16_le(&bytes[offset..offset+2]);
21        offset += 2;
22
23        let wait_until_done: bool = bytes[offset] != 0;
24        offset += 1;
25
26        offset += 4; // Command end signature
27
28        (offset, Self {
29            transition_number,
30            fade_frames,
31            wait_until_done
32        })
33    }
34
35    pub fn transition_number(&self) -> u32 {
36        self.transition_number
37    }
38    
39    pub fn transition_number_mut(&mut self) -> &mut u32 {
40        &mut self.transition_number
41    }
42
43    pub fn fade_frames(&self) -> u16 {
44        self.fade_frames
45    }
46    
47    pub fn fade_frames_mut(&mut self) -> &mut u16 {
48        &mut self.fade_frames
49    }
50
51    pub fn wait_until_done(&self) -> bool {
52        self.wait_until_done
53    }
54    
55    pub fn wait_until_done_mut(&mut self) -> &mut bool {
56        &mut self.wait_until_done
57    }
58}