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    pub(crate) fn from_catalog_id(id: &str) -> Option<Self> {
95        Some(match id {
96            "add" => Self::Add,
97            "subtract" => Self::Subtract,
98            "multiply" => Self::Multiply,
99            "divide" => Self::Divide,
100            "modulo" => Self::Modulo,
101            "min" => Self::Min,
102            "max" => Self::Max,
103            "raiseToPower" => Self::RaiseToPower,
104            "appendToArray" => Self::AppendToArray,
105            "removeFromArrayByValue" => Self::RemoveFromArrayByValue,
106            "removeFromArrayByIndex" => Self::RemoveFromArrayByIndex,
107            _ => return None,
108        })
109    }
110
111    /// The canonical catalog operator id (`add`, `removeFromArrayByIndex`)
112    /// the Workshop modify-operator position resolves this operation from.
113    /// Public since `rule-content-v1` names modify operands by this id.
114    pub fn catalog_id(self) -> &'static str {
115        match self {
116            Self::Add => "add",
117            Self::Subtract => "subtract",
118            Self::Multiply => "multiply",
119            Self::Divide => "divide",
120            Self::Modulo => "modulo",
121            Self::Min => "min",
122            Self::Max => "max",
123            Self::RaiseToPower => "raiseToPower",
124            Self::AppendToArray => "appendToArray",
125            Self::RemoveFromArrayByValue => "removeFromArrayByValue",
126            Self::RemoveFromArrayByIndex => "removeFromArrayByIndex",
127        }
128    }
129}