wolfrpg_map_parser/command/
event_control_command.rs

1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::command::event_control_command::erase_event::EraseEvent;
4use crate::command::event_control_command::label::Label;
5use crate::command::event_control_command::loop_command::Loop;
6use crate::command::event_control_command::loop_count::LoopCount;
7use crate::command::event_control_command::move_route::MoveRoute;
8use crate::command::event_control_command::set_transition::SetTransition;
9use crate::command::event_control_command::wait::Wait;
10
11pub mod loop_command;
12pub mod set_transition;
13pub mod move_route;
14pub mod erase_event;
15pub mod wait;
16pub mod loop_count;
17pub mod label;
18
19const COMMAND_END_SIGNATURE_LENGTH: usize = 3;
20
21#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
22#[derive(PartialEq, Clone)]
23pub enum EventControlCommand {
24    Loop(Loop),
25    BreakLoop,
26    GotoLoopStart,
27    PrepareTransition,
28    ExecuteTransition,
29    SetTransition(SetTransition),
30    MoveRoute(MoveRoute),
31    WaitForMoveRoute,
32    MoveDuringEventsOn,
33    MoveDuringEventsOff,
34    GotoTitle,
35    GameEnd,
36    StopNonPictureGraphicUpdates,
37    ResumeNonPictureGraphicUpdates,
38    ForceExitEvent,
39    EraseEvent(EraseEvent),
40    Wait(Wait),
41    LoopCount(LoopCount),
42    LabelPoint(Label),
43    LabelJump(Label)
44}
45
46impl EventControlCommand {
47    fn parse_empty_command(command: EventControlCommand) -> (usize, Self) {
48        (COMMAND_END_SIGNATURE_LENGTH, command)
49    }
50    pub(crate) fn parse_loop(bytes: &[u8]) -> (usize, u32, Self) {
51        let (bytes_read, commands_read, command): (usize, u32, Loop) = Loop::parse(bytes);
52
53        (bytes_read, commands_read, Self::Loop(command))
54    }
55
56    pub(crate) fn parse_break_loop(_: &[u8]) -> (usize, Self) {
57        Self::parse_empty_command(Self::BreakLoop)
58    }
59
60    pub(crate) fn parse_goto_loop_start(_: &[u8]) -> (usize, Self) {
61        Self::parse_empty_command(Self::GotoLoopStart)
62    }
63
64    pub(crate) fn parse_prepare_transition(_: &[u8]) -> (usize, Self) {
65        Self::parse_empty_command(Self::PrepareTransition)
66    }
67
68    pub(crate) fn parse_execute_transition(_: &[u8]) -> (usize, Self) {
69        Self::parse_empty_command(Self::ExecuteTransition)
70    }
71
72    pub(crate) fn parse_set_transition(bytes: &[u8]) -> (usize, Self) {
73        let (bytes_read, command): (usize, SetTransition) = SetTransition::parse(bytes);
74
75        (bytes_read, Self::SetTransition(command))
76    }
77
78    pub(crate) fn parse_move_route(bytes: &[u8]) -> (usize, Self) {
79        let (bytes_read, command): (usize, MoveRoute) = MoveRoute::parse(bytes);
80
81        (bytes_read, Self::MoveRoute(command))
82    }
83
84    pub(crate) fn parse_wait_for_move_route(_: &[u8]) -> (usize, Self) {
85        Self::parse_empty_command(Self::WaitForMoveRoute)
86    }
87
88    pub(crate) fn parse_move_during_events_on(_: &[u8]) -> (usize, Self) {
89        Self::parse_empty_command(Self::MoveDuringEventsOn)
90    }
91
92    pub(crate) fn parse_move_during_events_off(_: &[u8]) -> (usize, Self) {
93        Self::parse_empty_command(Self::MoveDuringEventsOff)
94    }
95
96    pub(crate) fn parse_goto_title(_: &[u8]) -> (usize, Self) {
97        Self::parse_empty_command(Self::GotoTitle)
98    }
99
100    pub(crate) fn parse_game_end(_: &[u8]) -> (usize, Self) {
101        Self::parse_empty_command(Self::GameEnd)
102    }
103
104    pub(crate) fn parse_stop_non_picture_graphic_updates(_: &[u8]) -> (usize, Self) {
105        Self::parse_empty_command(Self::StopNonPictureGraphicUpdates)
106    }
107
108    pub(crate) fn parse_resume_non_picture_graphic_updates(_: &[u8]) -> (usize, Self) {
109        Self::parse_empty_command(Self::ResumeNonPictureGraphicUpdates)
110    }
111
112    pub(crate) fn parse_force_exit_event(_: &[u8]) -> (usize, Self) {
113        Self::parse_empty_command(Self::ForceExitEvent)
114    }
115
116    pub(crate) fn parse_erase_event(bytes: &[u8]) -> (usize, Self) {
117        let (bytes_read, command): (usize, EraseEvent) = EraseEvent::parse(bytes);
118
119        (bytes_read, Self::EraseEvent(command))
120    }
121
122    pub(crate) fn parse_wait(bytes: &[u8]) -> (usize, Self) {
123        let (bytes_read, command): (usize, Wait) = Wait::parse(bytes);
124
125        (bytes_read, Self::Wait(command))
126    }
127
128    pub(crate) fn parse_loop_count(bytes: &[u8]) -> (usize, u32, Self) {
129        let (bytes_read, commands_read, command): (usize, u32, LoopCount) = LoopCount::parse(bytes);
130
131        (bytes_read, commands_read, Self::LoopCount(command))
132    }
133
134    pub(crate) fn parse_label_point(bytes: &[u8]) -> (usize, Self) {
135        let (bytes_read, command): (usize, Label) = Label::parse(bytes);
136
137        (bytes_read, Self::LabelPoint(command))
138    }
139
140    pub(crate) fn parse_label_jump(bytes: &[u8]) -> (usize, Self) {
141        let (bytes_read, command): (usize, Label) = Label::parse(bytes);
142
143        (bytes_read, Self::LabelJump(command))
144    }
145 }