wolfrpg_map_parser/command/
effect_command.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
35
36
37
38
39
40
41
42
43
44
45
46
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};
use crate::command::effect_command::base::Base;
use crate::command::effect_command::change_color::ChangeColor;
use crate::command::effect_command::map_shake::MapShake;
use crate::command::effect_command::scroll_screen::ScrollScreen;

pub mod base;
pub mod map_shake;
pub mod scroll_screen;
pub mod change_color;

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq)]
pub enum EffectCommand {
    Base(Base),
    MapShake(MapShake),
    ScrollScreen(ScrollScreen),
    ChangeColor(ChangeColor)
}

impl EffectCommand {
    pub(crate) fn parse_base(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, Base) = Base::parse(bytes);

        (bytes_read, Self::Base(command))
    }

    pub(crate) fn parse_map_shake(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, MapShake) = MapShake::parse(bytes);

        (bytes_read, Self::MapShake(command))
    }

    pub(crate) fn parse_scroll_screen(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, ScrollScreen) = ScrollScreen::parse(bytes);

        (bytes_read, Self::ScrollScreen(command))
    }

    pub(crate) fn parse_change_color(bytes: &[u8]) -> (usize, Self) {
        let (bytes_read, command): (usize, ChangeColor) = ChangeColor::parse(bytes);

        (bytes_read, Self::ChangeColor(command))
    }
}