-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathadapter.rs
More file actions
32 lines (27 loc) · 720 Bytes
/
Copy pathadapter.rs
File metadata and controls
32 lines (27 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use perro_api::prelude::*;
#[State]
struct DynamicAdapter {
#[default = NodeID::nil()]
#[node_ref(Node2D)]
pub target: NodeID,
}
lifecycle!({});
methods!({
pub fn add_to_member(
&self,
ctx: &mut ScriptContext<'_, API>,
member: String,
amount: i32,
) -> i32 {
let target = with_state!(ctx.run, DynamicAdapter, ctx.id, |state| state.target).unwrap_or_default();
if target.is_nil() {
return 0;
}
let old = get_var!(ctx.run, target, member.as_str())
.as_i32()
.unwrap_or(0);
let next = old + amount;
set_var!(ctx.run, target, member.as_str(), variant!(next));
next
}
});