blob: 4b89dbb2a2bda42f2bf72752f1cdfc6ba3a0bdc0 (
plain) (
blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
use gdnative::api::*;
use gdnative::prelude::*;
use crate::buff_trait::Buff;
struct BuffBall {
name: String,
description: String,
die_body: Option<Ref<RigidBody>>,
sphere_body: Option<Ref<RigidBody>>
}
impl BuffBall {
fn new(die_body: Option<Ref<RigidBody>>, sphere_body: Option<Ref<RigidBody>>) -> Self {
BuffBall {
name: String::from("Ball"),
description: String::from("Roll the dice"),
die_body,
sphere_body
}
}
}
impl Buff for BuffBall {
unsafe fn execute_buff(&mut self) {
// make sure the sphere rigid body exists
match &self.sphere_body {
Some(sphere) => {
// make sure the dice rigid body exists
match &self.die_body {
Some(die) => {
// get the safe references from the ref<>
let save_sphere = sphere.assume_safe();
let save_die = die.assume_safe();
// set the properties of the rigid bodies
save_die.set_process(false);
save_sphere.set_process(true);
save_sphere.show();
},
None => godot_warn!("Die body not assigned")
}
},
None => godot_warn!("Sphere body not assigned")
}
}
unsafe fn revert_buff(&mut self) {
// make sure the sphere rigid body exists
match &self.sphere_body {
Some(sphere) => {
// make sure the dice rigid body exists
match &self.die_body {
Some(die) => {
// get the safe references from the ref<>
let save_sphere = sphere.assume_safe();
let save_die = die.assume_safe();
// set the properties of the rigid bodies
save_die.set_process(true);
save_sphere.set_process(false);
save_sphere.hide();
},
None => godot_warn!("Die body not assigned")
}
},
None => godot_warn!("Sphere body not assigned")
}
}
fn get_name(self) -> GodotString {
GodotString::from_str(self.name)
}
fn get_description(self) -> GodotString {
GodotString::from_str(self.description)
}
}
|