wolfrpg_map_parser/command/event_control_command/
move_route.rs

1pub mod options;
2
3#[cfg(feature = "serde")]
4use serde::{Serialize, Deserialize};
5use crate::byte_utils::as_u32_le;
6use crate::common::r#move::Move;
7use crate::command::event_control_command::move_route::options::Options;
8
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10#[derive(PartialEq, Clone)]
11#[allow(unused)]
12pub struct MoveRoute {
13    target: u32,
14    unknown1: u32,
15    unknown2: u32,
16    options: Options,
17    move_count: u32,
18    moves: Vec<Move>
19}
20
21impl MoveRoute {
22    pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
23        let mut offset: usize = 0;
24
25        let target: u32 = as_u32_le(&bytes[offset..offset+4]);
26        offset += 4;
27
28        let unknown1: u32 = as_u32_le(&bytes[offset..offset+4]);
29        offset += 4;
30
31        let unknown2: u32 = as_u32_le(&bytes[offset..offset+4]);
32        offset += 4;
33
34        let options: u8 = bytes[offset];
35        let options: Options = Options::new(options);
36        offset += 1;
37
38        let move_count: u32 = as_u32_le(&bytes[offset..offset+4]);
39        offset += 4;
40
41        let (bytes_read, moves): (usize, Vec<Move>)
42            = Move::parse_multiple(&bytes[offset..], move_count);
43        offset += bytes_read;
44
45        (offset, Self {
46            target,
47            unknown1,
48            unknown2,
49            options,
50            move_count,
51            moves
52        })
53    }
54
55    pub fn target(&self) -> u32 {
56        self.target
57    }
58    
59    pub fn target_mut(&mut self) -> &mut u32 {
60        &mut self.target
61    }
62
63    pub fn options(&self) -> &Options {
64        &self.options
65    }
66    
67    pub fn options_mut(&mut self) -> &mut Options {
68        &mut self.options
69    }
70
71    pub fn move_count(&self) -> u32 {
72        self.move_count
73    }
74    
75    pub fn move_count_mut(&mut self) -> &mut u32 {
76        &mut self.move_count
77    }
78
79    pub fn moves(&self) -> &Vec<Move> {
80        &self.moves
81    }
82    
83    pub fn moves_mut(&mut self) -> &mut Vec<Move> {
84        &mut self.moves
85    }
86}