#[cfg(feature = "chumsky")]
use chumsky::{Parser, prelude::just, text::whitespace};
#[cfg(feature = "chumsky")]
use crate::utils::f32_parser;
#[derive(Debug, Clone, PartialEq)]
pub struct Vector {
pub x: f32,
pub y: f32,
pub z: f32,
}
#[cfg(feature = "chumsky")]
#[must_use]
pub fn vector_parser<'src>()
-> impl Parser<'src, &'src str, Vector, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
just('<')
.then(whitespace().or_not())
.ignore_then(f32_parser())
.then_ignore(whitespace().or_not())
.then_ignore(just(','))
.then_ignore(whitespace().or_not())
.then(f32_parser())
.then_ignore(whitespace().or_not())
.then_ignore(just(','))
.then_ignore(whitespace().or_not())
.then(f32_parser())
.then_ignore(whitespace().or_not())
.then_ignore(just('>'))
.map(|((x, y), z)| Vector { x, y, z })
}
impl From<crate::map::RegionCoordinates> for Vector {
fn from(value: crate::map::RegionCoordinates) -> Self {
Self {
x: value.x(),
y: value.y(),
z: value.z(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Rotation {
pub x: f32,
pub y: f32,
pub z: f32,
pub s: f32,
}
#[cfg(feature = "chumsky")]
#[must_use]
pub fn rotation_parser<'src>()
-> impl Parser<'src, &'src str, Rotation, chumsky::extra::Err<chumsky::error::Rich<'src, char>>> {
just('<')
.then(whitespace().or_not())
.ignore_then(f32_parser())
.then_ignore(whitespace().or_not())
.then_ignore(just(','))
.then_ignore(whitespace().or_not())
.then(f32_parser())
.then_ignore(whitespace().or_not())
.then_ignore(just(','))
.then_ignore(whitespace().or_not())
.then(f32_parser())
.then_ignore(whitespace().or_not())
.then_ignore(just(','))
.then_ignore(whitespace().or_not())
.then(f32_parser())
.then_ignore(whitespace().or_not())
.then_ignore(just('>'))
.map(|(((x, y), z), s)| Rotation { x, y, z, s })
}