wolfrpg_map_parser/command/
event_control_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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::command::event_control_command::erase_event::EraseEvent;
use crate::command::event_control_command::label::Label;
use crate::command::event_control_command::loop_command::Loop;
use crate::command::event_control_command::loop_count::LoopCount;
use crate::command::event_control_command::move_route::MoveRoute;
use crate::command::event_control_command::set_transition::SetTransition;
use crate::command::event_control_command::wait::Wait;

pub mod loop_command;
pub mod set_transition;
pub mod move_route;
pub mod erase_event;
pub mod wait;
pub mod loop_count;
pub mod label;

const COMMAND_END_SIGNATURE_LENGTH: usize = 3;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub enum EventControlCommand {
    Loop(Loop),
    BreakLoop,
    GotoLoopStart,
    PrepareTransition,
    ExecuteTransition,
    SetTransition(SetTransition),
    MoveRoute(MoveRoute),
    WaitForMoveRoute,
    MoveDuringEventsOn,
    MoveDuringEventsOff,
    GotoTitle,
    GameEnd,
    StopNonPictureGraphicUpdates,
    ResumeNonPictureGraphicUpdates,
    ForceExitEvent,
    EraseEvent(EraseEvent),
    Wait(Wait),
    LoopCount(LoopCount),
    LabelPoint(Label),
    LabelJump(Label)
}

impl EventControlCommand {
    fn parse_empty_command(command: EventControlCommand) -> (usize, Self) {
        (COMMAND_END_SIGNATURE_LENGTH, command)
    }
    pub fn parse_loop(bytes: &[u8]) -> (usize, u32, Self) {
        let (bytes_read, commands_read, command): (usize, u32, Loop) = Loop::parse(bytes);

        (bytes_read, commands_read, Self::Loop(command))
    }

    pub fn parse_break_loop(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::BreakLoop)
    }

    pub fn parse_goto_loop_start(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::GotoLoopStart)
    }

    pub fn parse_prepare_transition(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::PrepareTransition)
    }

    pub fn parse_execute_transition(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::ExecuteTransition)
    }

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

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

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

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

    pub fn parse_wait_for_move_route(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::WaitForMoveRoute)
    }

    pub fn parse_move_during_events_on(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::MoveDuringEventsOn)
    }

    pub fn parse_move_during_events_off(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::MoveDuringEventsOff)
    }

    pub fn parse_goto_title(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::GotoTitle)
    }

    pub fn parse_game_end(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::GameEnd)
    }

    pub fn parse_stop_non_picture_graphic_updates(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::StopNonPictureGraphicUpdates)
    }

    pub fn parse_resume_non_picture_graphic_updates(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::ResumeNonPictureGraphicUpdates)
    }

    pub fn parse_force_exit_event(_: &[u8]) -> (usize, Self) {
        Self::parse_empty_command(Self::ForceExitEvent)
    }

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

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

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

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

    pub fn parse_loop_count(bytes: &[u8]) -> (usize, u32, Self) {
        let (bytes_read, commands_read, command): (usize, u32, LoopCount) = LoopCount::parse(bytes);

        (bytes_read, commands_read, Self::LoopCount(command))
    }

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

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

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

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