wolfrpg_map_parser/command/picture_command/show/
base.rs1use crate::byte_utils::as_u32_le;
2use crate::command::picture_command::display_type::DisplayType;
3use crate::command::picture_command::options::Options;
4#[cfg(feature = "serde")]
5use serde::{Serialize, Deserialize};
6
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8#[derive(PartialEq, Clone)]
9pub struct Base {
10 position_x: u32,
11 position_y: u32
12}
13
14impl Base {
15 pub(crate) fn parse(bytes: &[u8], options: &Options) -> (usize, Option<u32>, Self) {
16 let mut offset: usize = 0;
17
18 let position_x: u32 = as_u32_le(&bytes[offset..offset+4]);
19 offset += 4;
20
21 let position_y: u32 = as_u32_le(&bytes[offset..offset+4]);
22 offset += 4;
23
24 offset += 4; offset += 4; let (bytes_read, filename_variable): (usize, Option<u32>)
28 = Self::parse_filename_variable(&bytes[offset..], options);
29 offset += bytes_read;
30
31 offset += 1; (offset, filename_variable, Base{
34 position_x,
35 position_y,
36 })
37 }
38
39 fn parse_filename_variable(bytes: &[u8], options: &Options) -> (usize, Option<u32>) {
40 let mut offset: usize = 0;
41 let filename_variable: Option<u32> = match *options.display_type() {
42 DisplayType::StringVar | DisplayType::WindowByStringVar => {
43 let filename_variable: u32 = as_u32_le(&bytes[offset..offset+4]);
44 offset += 4;
45
46 Some(filename_variable)
47 }
48
49 _ => None
50 };
51
52 (offset, filename_variable)
53 }
54
55 pub fn position_x(&self) -> u32 {
56 self.position_x
57 }
58
59 pub fn position_x_mut(&mut self) -> &mut u32 {
60 &mut self.position_x
61 }
62
63 pub fn position_y(&self) -> u32 {
64 self.position_y
65 }
66
67 pub fn position_y_mut(&mut self) -> &mut u32 {
68 &mut self.position_y
69 }
70}