wolfrpg_map_parser/command/picture_command/show/
state.rs1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::command::picture_command::show::base::Base;
4use crate::command::picture_command::options::Options;
5use crate::command::picture_command::show::color_values::ColorValues;
6use crate::command::picture_command::show::colors::Colors;
7use crate::command::picture_command::show::free_transform::FreeTransform;
8use crate::command::picture_command::show::delay::Delay;
9use crate::command::picture_command::show::range::Range;
10use crate::command::picture_command::show::zoom::Zoom;
11
12#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
13#[derive(PartialEq, Clone)]
14pub enum State {
15 Base(Base),
16 Colors(Colors),
17 Delay(Delay),
18 Range(Range),
19 ColorValues(ColorValues),
20 Zoom(Zoom),
21 FreeTransform(FreeTransform)
22}
23
24impl State {
25 pub(crate) fn parse_base(bytes: &[u8], options: &Options) -> (usize, Option<u32>, Self) {
26 let (bytes_read, filename_variable, state): (usize, Option<u32>, Base)
27 = Base::parse(bytes, options);
28
29 (bytes_read, filename_variable, Self::Base(state))
30 }
31
32 pub(crate) fn parse_colors(bytes: &[u8], _: &Options) -> (usize, Option<u32>, Self) {
33 let (bytes_read, filename_variable, state): (usize, Option<u32>, Colors)
34 = Colors::parse(bytes);
35
36 (bytes_read, filename_variable, Self::Colors(state))
37 }
38
39 pub(crate) fn parse_delay(bytes: &[u8], _: &Options) -> (usize, Option<u32>, State) {
40 let (bytes_read, filename_variable, state): (usize, Option<u32>, Delay)
41 = Delay::parse(bytes);
42
43 (bytes_read, filename_variable, Self::Delay(state))
44 }
45
46 pub(crate) fn parse_range(bytes: &[u8], _: &Options) -> (usize, Option<u32>, State) {
47 let (bytes_read, filename_variable, state): (usize, Option<u32>, Range)
48 = Range::parse(bytes);
49
50 (bytes_read, filename_variable, Self::Range(state))
51 }
52
53 pub(crate) fn parse_color_values(bytes: &[u8], _: &Options) -> (usize, Option<u32>, State) {
54 let (bytes_read, filename_variable, state): (usize, Option<u32>, ColorValues)
55 = ColorValues::parse(bytes);
56
57 (bytes_read, filename_variable, Self::ColorValues(state))
58 }
59
60 pub(crate) fn parse_zoom(bytes: &[u8], _: &Options) -> (usize, Option<u32>, State) {
61 let (bytes_read, filename_variable, state): (usize, Option<u32>, Zoom)
62 = Zoom::parse(bytes);
63
64 (bytes_read, filename_variable, Self::Zoom(state))
65 }
66
67 pub(crate) fn parse_free_transform(bytes: &[u8], _: &Options) -> (usize, Option<u32>, State) {
68 let (bytes_read, filename_variable, state): (usize, Option<u32>, FreeTransform)
69 = FreeTransform::parse(bytes);
70
71 (bytes_read, filename_variable, Self::FreeTransform(state))
72 }
73}