wolfrpg_map_parser/command/sound_command/
state.rs

1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::command::sound_command::filename::Filename;
4use crate::command::sound_command::options::Options;
5use crate::command::sound_command::sound_type::SoundType;
6use crate::command::sound_command::variable::Variable;
7
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9#[derive(PartialEq, Clone)]
10pub enum State {
11    Filename(Filename),
12    Variable(Variable),
13    FreeAll
14}
15
16impl State {
17    pub(crate) fn parse_filename(bytes: &[u8], options: &Options, _: &SoundType) -> (usize, Self) {
18        let (bytes_read, state): (usize, Filename) = Filename::parse(bytes, options);
19
20        (bytes_read, Self::Filename(state))
21    }
22
23    pub(crate) fn parse_variable(bytes: &[u8], options: &Options, _: &SoundType) -> (usize, Self) {
24        let (bytes_read, state): (usize, Variable) = Variable::parse(bytes, options);
25
26        (bytes_read, Self::Variable(state))
27    }
28
29    pub(crate) fn parse_free_all(_: &[u8], _: &Options, sound_type: &SoundType) -> (usize, State) {
30        match *sound_type {
31            SoundType::Variable => (10, State::FreeAll),
32            _ => (2, State::FreeAll),
33        }
34    }
35}