use crate::serde_helpers::impl_bitfield_serde;
#[cfg(feature = "chumsky")]
use chumsky::{Parser, prelude::just, text::whitespace};
#[cfg(feature = "chumsky")]
use crate::utils::f32_parser;
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
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, serde::Serialize, serde::Deserialize)]
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 })
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct ScriptPermissions(pub i32);
impl ScriptPermissions {
pub const DEBIT: i32 = 1 << 1;
pub const TAKE_CONTROLS: i32 = 1 << 2;
pub const TRIGGER_ANIMATION: i32 = 1 << 4;
pub const ATTACH: i32 = 1 << 5;
pub const CHANGE_LINKS: i32 = 1 << 7;
pub const TRACK_CAMERA: i32 = 1 << 10;
pub const CONTROL_CAMERA: i32 = 1 << 11;
pub const TELEPORT: i32 = 1 << 12;
pub const EXPERIENCE: i32 = 1 << 13;
pub const SILENT_ESTATE_MANAGEMENT: i32 = 1 << 14;
pub const OVERRIDE_ANIMATIONS: i32 = 1 << 15;
pub const RETURN_OBJECTS: i32 = 1 << 16;
#[must_use]
pub const fn contains(self, mask: i32) -> bool {
self.0 & mask == mask
}
}
impl_bitfield_serde!(
ScriptPermissions,
i32,
"DEBIT" => ScriptPermissions::DEBIT,
"TAKE_CONTROLS" => ScriptPermissions::TAKE_CONTROLS,
"TRIGGER_ANIMATION" => ScriptPermissions::TRIGGER_ANIMATION,
"ATTACH" => ScriptPermissions::ATTACH,
"CHANGE_LINKS" => ScriptPermissions::CHANGE_LINKS,
"TRACK_CAMERA" => ScriptPermissions::TRACK_CAMERA,
"CONTROL_CAMERA" => ScriptPermissions::CONTROL_CAMERA,
"TELEPORT" => ScriptPermissions::TELEPORT,
"EXPERIENCE" => ScriptPermissions::EXPERIENCE,
"SILENT_ESTATE_MANAGEMENT" => ScriptPermissions::SILENT_ESTATE_MANAGEMENT,
"OVERRIDE_ANIMATIONS" => ScriptPermissions::OVERRIDE_ANIMATIONS,
"RETURN_OBJECTS" => ScriptPermissions::RETURN_OBJECTS,
);