wolfrpg_map_parser/command/sound_command/
filename.rs1use crate::byte_utils::{as_u32_le, parse_string};
2use crate::command::sound_command::operation::Operation;
3use crate::command::sound_command::options::Options;
4use crate::command::sound_command::variable::Variable;
5#[cfg(feature = "serde")]
6use serde::{Serialize, Deserialize};
7
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9#[derive(PartialEq, Clone)]
10pub struct Filename {
11 variable_state: Variable,
12 volume: u32,
13 tempo: u32,
14 loop_point: Option<u32>,
15 sound_filename: String
16}
17
18impl Filename {
19 pub(crate) fn parse(bytes: &[u8], options: &Options) -> (usize, Self) {
20 let mut offset: usize = 0;
21
22 let (bytes_read, variable_state): (usize, Variable) = Variable::parse(bytes, options);
23 offset += bytes_read;
24
25 let volume: u32 = as_u32_le(&bytes[offset..offset + 4]);
26 offset += 4;
27
28 let tempo: u32 = as_u32_le(&bytes[offset..offset + 4]);
29 offset += 4;
30
31 let loop_point: Option<u32> = match *options.operation() {
32 Operation::SetSE => None,
33 _ => {
34 let loop_point: u32 = as_u32_le(&bytes[offset..offset + 4]);
35 offset += 4;
36
37 Some(loop_point)
38 }
39 };
40
41 let (bytes_read, sound_filename): (usize, String) = parse_string(&bytes[offset..]);
42 offset += bytes_read;
43
44 (offset, Self {
45 variable_state,
46 volume,
47 tempo,
48 loop_point,
49 sound_filename
50 })
51 }
52
53 pub fn delay_playback(&self) -> Option<u32> {
54 self.variable_state.delay_playback()
55 }
56
57 pub fn delay_playback_mut(&mut self) -> &mut Option<u32> {
58 self.variable_state.delay_playback_mut()
59 }
60
61 pub fn fade_time(&self) -> Option<u32> {
62 self.variable_state.fade_time()
63 }
64
65 pub fn fade_time_mut(&mut self) -> &mut Option<u32> {
66 self.variable_state.fade_time_mut()
67 }
68
69 pub fn variable(&self) -> u32 {
70 self.variable_state.variable()
71 }
72
73 pub fn variable_mut(&mut self) -> &mut u32 {
74 self.variable_state.variable_mut()
75 }
76
77 pub fn start_time(&self) -> u32 {
78 self.variable_state.start_time()
79 }
80
81 pub fn start_time_mut(&mut self) -> &mut u32 {
82 self.variable_state.start_time_mut()
83 }
84
85 pub fn volume(&self) -> u32 {
86 self.volume
87 }
88
89 pub fn volume_mut(&mut self) -> &mut u32 {
90 &mut self.volume
91 }
92
93 pub fn tempo(&self) -> u32 {
94 self.tempo
95 }
96
97 pub fn tempo_mut(&mut self) -> &mut u32 {
98 &mut self.tempo
99 }
100
101 pub fn loop_point(&self) -> Option<u32> {
102 self.loop_point
103 }
104
105 pub fn loop_point_mut(&mut self) -> &mut Option<u32> {
106 &mut self.loop_point
107 }
108
109 pub fn sound_filename(&self) -> &str {
110 &self.sound_filename
111 }
112
113 pub fn sound_filename_mut(&mut self) -> &mut String {
114 &mut self.sound_filename
115 }
116}