wolfrpg_map_parser/command/sound_command/
state.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::command::sound_command::filename::Filename;
use crate::command::sound_command::options::Options;
use crate::command::sound_command::sound_type::SoundType;
use crate::command::sound_command::variable::Variable;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub enum State {
    Filename(Filename),
    Variable(Variable),
    FreeAll
}

impl State {
    pub fn parse_filename(bytes: &[u8], options: &Options, _: &SoundType) -> (usize, Self) {
        let (bytes_read, state): (usize, Filename) = Filename::parse(bytes, options);

        (bytes_read, Self::Filename(state))
    }

    pub fn parse_variable(bytes: &[u8], options: &Options, _: &SoundType) -> (usize, Self) {
        let (bytes_read, state): (usize, Variable) = Variable::parse(bytes, options);

        (bytes_read, Self::Variable(state))
    }

    pub fn parse_free_all(_: &[u8], _: &Options, sound_type: &SoundType) -> (usize, State) {
        match *sound_type {
            SoundType::Variable => (10, State::FreeAll),
            _ => (2, State::FreeAll),
        }
    }
}