Skip to main content

sl_types/
pathfinding.rs

1//! Pathfinding related types
2
3#[cfg(feature = "chumsky")]
4use chumsky::Parser;
5
6/// Pathfinding types
7///
8/// see <https://wiki.secondlife.com/wiki/Category:LSL_Pathfinding_Types>
9#[derive(
10    Debug,
11    Clone,
12    Hash,
13    PartialEq,
14    Eq,
15    strum::FromRepr,
16    strum::EnumIs,
17    serde::Serialize,
18    serde::Deserialize,
19)]
20#[repr(i8)]
21#[expect(
22    clippy::module_name_repetitions,
23    reason = "the type is used outside this module"
24)]
25pub enum PathfindingType {
26    /// Attachments, Linden trees & grass
27    Other = -1,
28    /// Movable obstacles, movable phantoms, physical, and volumedetect objects
29    LegacyLinkset = 0,
30    /// Avatars
31    Avatar = 1,
32    /// Pathfinding characters
33    Character = 2,
34    /// Walkable objects
35    Walkable = 3,
36    /// Static obstacles
37    StaticObstacle = 4,
38    /// Material volumes
39    MaterialVolume = 5,
40    /// Exclusion volumes
41    ExclusionVolume = 6,
42}
43
44/// parse a signed integer as a pathfinding type based on the C/LSL constant
45/// values
46///
47/// # Errors
48///
49/// returns an error if the string could not be parsed
50#[cfg(feature = "chumsky")]
51#[must_use]
52pub fn int_as_pathfinding_type_parser<'src>()
53-> impl Parser<'src, &'src str, PathfindingType, chumsky::extra::Err<chumsky::error::Rich<'src, char>>>
54{
55    crate::utils::i8_parser().try_map(|repr, span| {
56        crate::pathfinding::PathfindingType::from_repr(repr).ok_or_else(|| {
57            chumsky::error::Rich::custom(
58                span,
59                "Could not convert parsed pathfinding type i8 into PathfindingType enum",
60            )
61        })
62    })
63}