Skip to main content

workshop_rs/program/
shared.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum EventTeam {
3    All,
4    Team1,
5    Team2,
6}
7
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum EventTarget {
10    All,
11    Slot(u8),
12    Hero(String),
13}
14
15/// A non-ongoing player event identity.
16///
17/// Workshop can add player-scoped event identities independently of this
18/// crate. Consumers should use a wildcard arm when matching this type.
19#[non_exhaustive]
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
21pub enum PlayerEventKind {
22    DealtDamage,
23    DealtFinalBlow,
24    DealtHealing,
25    DealtKnockback,
26    Died,
27    EarnedElimination,
28    Joined,
29    Left,
30    ReceivedHealing,
31    ReceivedKnockback,
32    TookDamage,
33}
34
35impl PlayerEventKind {
36    pub(crate) fn from_catalog_id(id: &str) -> Option<Self> {
37        Some(match id {
38            "playerDealtDamage" => Self::DealtDamage,
39            "playerDealtFinalBlow" => Self::DealtFinalBlow,
40            "playerDealtHealing" => Self::DealtHealing,
41            "playerDealtKnockback" => Self::DealtKnockback,
42            "playerDied" => Self::Died,
43            "playerEarnedElimination" => Self::EarnedElimination,
44            "playerJoined" => Self::Joined,
45            "playerLeft" => Self::Left,
46            "playerReceivedHealing" => Self::ReceivedHealing,
47            "playerReceivedKnockback" => Self::ReceivedKnockback,
48            "playerTookDamage" => Self::TookDamage,
49            _ => return None,
50        })
51    }
52
53    /// The canonical catalog event id (`playerDealtDamage`) the Workshop
54    /// event section resolves this kind from. Public since
55    /// `rule-content-v1` names events by this id.
56    pub fn catalog_id(self) -> &'static str {
57        match self {
58            Self::DealtDamage => "playerDealtDamage",
59            Self::DealtFinalBlow => "playerDealtFinalBlow",
60            Self::DealtHealing => "playerDealtHealing",
61            Self::DealtKnockback => "playerDealtKnockback",
62            Self::Died => "playerDied",
63            Self::EarnedElimination => "playerEarnedElimination",
64            Self::Joined => "playerJoined",
65            Self::Left => "playerLeft",
66            Self::ReceivedHealing => "playerReceivedHealing",
67            Self::ReceivedKnockback => "playerReceivedKnockback",
68            Self::TookDamage => "playerTookDamage",
69        }
70    }
71}
72
73/// The operation used by a Workshop variable modification action.
74///
75/// Workshop can add modification operations independently of this crate.
76/// Consumers should use a wildcard arm when matching this type.
77#[non_exhaustive]
78#[derive(Debug, Clone, Copy, PartialEq, Eq)]
79pub enum ModifyOp {
80    Add,
81    Subtract,
82    Multiply,
83    Divide,
84    Modulo,
85    Min,
86    Max,
87    RaiseToPower,
88    AppendToArray,
89    RemoveFromArrayByValue,
90    RemoveFromArrayByIndex,
91}
92
93impl ModifyOp {
94    /// The operation a catalog operator id names (`add`,
95    /// `removeFromArrayByIndex`, …) — the accepted set the `paramContent`
96    /// `operations` fact declares for modify parameters. `None` for any
97    /// other catalog id.
98    pub fn from_catalog_id(id: &str) -> Option<Self> {
99        Some(match id {
100            "add" => Self::Add,
101            "subtract" => Self::Subtract,
102            "multiply" => Self::Multiply,
103            "divide" => Self::Divide,
104            "modulo" => Self::Modulo,
105            "min" => Self::Min,
106            "max" => Self::Max,
107            "raiseToPower" => Self::RaiseToPower,
108            "appendToArray" => Self::AppendToArray,
109            "removeFromArrayByValue" => Self::RemoveFromArrayByValue,
110            "removeFromArrayByIndex" => Self::RemoveFromArrayByIndex,
111            _ => return None,
112        })
113    }
114
115    /// The canonical catalog operator id (`add`, `removeFromArrayByIndex`)
116    /// the Workshop modify-operator position resolves this operation from.
117    /// Public since `rule-content-v1` names modify operands by this id.
118    pub fn catalog_id(self) -> &'static str {
119        match self {
120            Self::Add => "add",
121            Self::Subtract => "subtract",
122            Self::Multiply => "multiply",
123            Self::Divide => "divide",
124            Self::Modulo => "modulo",
125            Self::Min => "min",
126            Self::Max => "max",
127            Self::RaiseToPower => "raiseToPower",
128            Self::AppendToArray => "appendToArray",
129            Self::RemoveFromArrayByValue => "removeFromArrayByValue",
130            Self::RemoveFromArrayByIndex => "removeFromArrayByIndex",
131        }
132    }
133}