aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--rust/src/buff_ball.rs79
-rw-r--r--rust/src/buff_bounce.rs74
-rw-r--r--rust/src/buff_extra.rs35
-rw-r--r--rust/src/buff_phase.rs60
-rw-r--r--rust/src/buff_trait.rs9
-rw-r--r--rust/src/lib.rs7
6 files changed, 262 insertions, 2 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)
+ }
+}
diff --git a/rust/src/buff_bounce.rs b/rust/src/buff_bounce.rs
new file mode 100644
index 0000000..179642d
--- /dev/null
+++ b/rust/src/buff_bounce.rs
@@ -0,0 +1,74 @@
+use gdnative::api::*;
+use gdnative::prelude::*;
+use crate::buff_trait::Buff;
+
+struct BuffBounce {
+ name: String,
+ description: String,
+ rigid_body: Option<Ref<RigidBody>>,
+
+ target_bounciness: f64,
+ previous_bounciness: f64
+}
+
+impl BuffBounce {
+ fn new(rigid_body: Option<Ref<RigidBody>>) -> Self {
+ BuffBounce {
+ name: String::from("Bounce"),
+ description: String::from("Let's the die bounce more than usual."),
+ rigid_body,
+
+ target_bounciness: 1.0,
+ previous_bounciness: 0.0
+ }
+ }
+}
+
+impl Buff for BuffBounce {
+ unsafe fn execute_buff(&mut self) {
+ // make sure the rigid body exists
+ match &self.rigid_body {
+ Some(body) => {
+ let safe_body = body.assume_safe();
+
+ // get the physics material
+ match safe_body.physics_material_override() {
+ Some(mat) => {
+ let save_mat = mat.assume_safe();
+ self.previous_bounciness = save_mat.bounce();
+ save_mat.set_bounce(self.target_bounciness);
+ },
+ None => godot_warn!("Physics material was not found")
+ }
+ },
+ None => godot_warn!("No rigid body initialized to apply properties to")
+ }
+ }
+
+ unsafe fn revert_buff(&mut self) {
+ // make sure the rigid body exists
+ match &self.rigid_body {
+ Some(body) => {
+ let safe_body = body.assume_safe();
+
+ // get the physics material
+ match safe_body.physics_material_override() {
+ Some(mat) => {
+ let save_mat = mat.assume_safe();
+ save_mat.set_bounce(self.previous_bounciness);
+ },
+ None => godot_warn!("Physics material was not found")
+ }
+ },
+ None => godot_warn!("No rigid body initialized to apply properties to")
+ }
+ }
+
+ fn get_name(self) -> GodotString {
+ GodotString::from_str(self.name)
+ }
+
+ fn get_description(self) -> GodotString {
+ GodotString::from_str(self.description)
+ }
+}
diff --git a/rust/src/buff_extra.rs b/rust/src/buff_extra.rs
new file mode 100644
index 0000000..473cdde
--- /dev/null
+++ b/rust/src/buff_extra.rs
@@ -0,0 +1,35 @@
+use gdnative::api::*;
+use gdnative::prelude::*;
+use crate::buff_trait::Buff;
+
+struct BuffExtra {
+ name: String,
+ description: String,
+}
+
+impl BuffExtra {
+ fn new() -> Self {
+ BuffExtra {
+ name: String::from("Extra Stroke"),
+ description: String::from("One additional stroke that doesn't count"),
+ }
+ }
+}
+
+impl Buff for BuffExtra {
+ unsafe fn execute_buff(&mut self) {
+ todo!()
+ }
+
+ unsafe fn revert_buff(&mut self) {
+ todo!()
+ }
+
+ fn get_name(self) -> GodotString {
+ GodotString::from_str(self.name)
+ }
+
+ fn get_description(self) -> GodotString {
+ GodotString::from_str(self.description)
+ }
+}
diff --git a/rust/src/buff_phase.rs b/rust/src/buff_phase.rs
new file mode 100644
index 0000000..e64508e
--- /dev/null
+++ b/rust/src/buff_phase.rs
@@ -0,0 +1,60 @@
+use gdnative::api::*;
+use gdnative::prelude::*;
+use crate::buff_trait::Buff;
+
+struct BuffPhase {
+ name: String,
+ description: String,
+ rigid_body: Option<Ref<RigidBody>>,
+
+ wall_layer_bit: i64,
+}
+
+impl BuffPhase {
+ fn new(rigid_body: Option<Ref<RigidBody>>) -> Self {
+ // calculate the bit for the mask to enable/ disable collision detection
+ let mask_layer = 2;
+ let mask_bit = 2_i64.pow(mask_layer - 1);
+
+ BuffPhase {
+ name: String::from("Phase"),
+ description: String::from("Phases through thin fences"),
+ rigid_body,
+
+ wall_layer_bit: mask_bit,
+ }
+ }
+}
+
+impl Buff for BuffPhase {
+ unsafe fn execute_buff(&mut self) {
+ match &self.rigid_body {
+ Some(body) => {
+ // actually disable the collision to the fences
+ let save_body = body.assume_safe();
+ save_body.set_collision_mask_bit(self.wall_layer_bit, false);
+ },
+ None => godot_warn!("Rigid body not found")
+ }
+ }
+
+ unsafe fn revert_buff(& mut self) {
+ // make sure the rigid body exists
+ match &self.rigid_body {
+ Some(body) => {
+ // actually enable the collision again
+ let save_body = body.assume_safe();
+ save_body.set_collision_mask_bit(self.wall_layer_bit, false);
+ },
+ None => godot_warn!("Rigid body not found")
+ }
+ }
+
+ fn get_name(self) -> GodotString {
+ GodotString::from_str(self.name)
+ }
+
+ fn get_description(self) -> GodotString {
+ GodotString::from_str(self.description)
+ }
+}
diff --git a/rust/src/buff_trait.rs b/rust/src/buff_trait.rs
new file mode 100644
index 0000000..d0e9fba
--- /dev/null
+++ b/rust/src/buff_trait.rs
@@ -0,0 +1,9 @@
+use gdnative::api::*;
+use gdnative::prelude::*;
+
+pub trait Buff {
+ unsafe fn execute_buff(&mut self);
+ unsafe fn revert_buff(&mut self);
+ fn get_name(self) -> GodotString;
+ fn get_description(self) -> GodotString;
+}
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index 7958395..534955f 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -1,6 +1,10 @@
mod game;
mod spinning_cube;
-mod test;
+mod buff_bounce;
+mod buff_phase;
+mod buff_trait;
+mod buff_ball;
+mod buff_extra;
use gdnative::prelude::{godot_init, InitHandle};
@@ -8,7 +12,6 @@ use gdnative::prelude::{godot_init, InitHandle};
fn init(handle: InitHandle) {
handle.add_class::<game::Game>();
handle.add_class::<spinning_cube::SpinningCube>();
- handle.add_class::<test::SpinningCubeReverse>();
}
// macros that create the entry-points of the dynamic library.