aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/buff_ball.rs
diff options
context:
space:
mode:
authorLibravatar IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com>2022-07-16 15:03:50 +0200
committerLibravatar IcECreAm777 <31211782+IcECreAm777@users.noreply.github.com>2022-07-16 15:03:50 +0200
commit4435579498beefeb75b524111d24b1cb922cd22a (patch)
tree026b0ad61d6abb5deb736e69015a897a3283c6cf /rust/src/buff_ball.rs
parentf2ad01fe09709bc32b9b06a0aecc4c1b4d0a870d (diff)
parent9739b6d40258440cef4f7664f501efa81497263b (diff)
download2022-4435579498beefeb75b524111d24b1cb922cd22a.tar.gz
2022-4435579498beefeb75b524111d24b1cb922cd22a.tar.bz2
2022-4435579498beefeb75b524111d24b1cb922cd22a.zip
Merge branch 'BuffSystem'
Diffstat (limited to '')
-rw-r--r--rust/src/buff_ball.rs79
1 files changed, 79 insertions, 0 deletions
diff --git a/rust/src/buff_ball.rs b/rust/src/buff_ball.rs
new file mode 100644
index 0000000..4b89dbb
--- /dev/null
+++ b/rust/src/buff_ball.rs
@@ -0,0 +1,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)
+ }
+}