1#[cfg(feature = "chumsky")]
4use chumsky::{Parser, prelude::just, text::whitespace};
5
6#[cfg(feature = "chumsky")]
7use crate::utils::f32_parser;
8
9#[derive(Debug, Clone, PartialEq)]
11pub struct Vector {
12 pub x: f32,
14 pub y: f32,
16 pub z: f32,
18}
19
20#[cfg(feature = "chumsky")]
28#[must_use]
29pub fn vector_parser<'src>()
30-> impl Parser<'src, &'src str, Vector, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
31 just('<')
32 .then(whitespace().or_not())
33 .ignore_then(f32_parser())
34 .then_ignore(whitespace().or_not())
35 .then_ignore(just(','))
36 .then_ignore(whitespace().or_not())
37 .then(f32_parser())
38 .then_ignore(whitespace().or_not())
39 .then_ignore(just(','))
40 .then_ignore(whitespace().or_not())
41 .then(f32_parser())
42 .then_ignore(whitespace().or_not())
43 .then_ignore(just('>'))
44 .map(|((x, y), z)| Vector { x, y, z })
45}
46
47impl From<crate::map::RegionCoordinates> for Vector {
48 fn from(value: crate::map::RegionCoordinates) -> Self {
49 Self {
50 x: value.x(),
51 y: value.y(),
52 z: value.z(),
53 }
54 }
55}
56
57#[derive(Debug, Clone, PartialEq)]
59pub struct Rotation {
60 pub x: f32,
62 pub y: f32,
64 pub z: f32,
66 pub s: f32,
68}
69
70#[cfg(feature = "chumsky")]
78#[must_use]
79pub fn rotation_parser<'src>()
80-> impl Parser<'src, &'src str, Rotation, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
81 just('<')
82 .then(whitespace().or_not())
83 .ignore_then(f32_parser())
84 .then_ignore(whitespace().or_not())
85 .then_ignore(just(','))
86 .then_ignore(whitespace().or_not())
87 .then(f32_parser())
88 .then_ignore(whitespace().or_not())
89 .then_ignore(just(','))
90 .then_ignore(whitespace().or_not())
91 .then(f32_parser())
92 .then_ignore(whitespace().or_not())
93 .then_ignore(just(','))
94 .then_ignore(whitespace().or_not())
95 .then(f32_parser())
96 .then_ignore(whitespace().or_not())
97 .then_ignore(just('>'))
98 .map(|(((x, y), z), s)| Rotation { x, y, z, s })
99}