From d1bac1c41a75fdf901e1f7c5f604783f0685190a Mon Sep 17 00:00:00 2001 From: David Date: Sat, 16 Jul 2022 20:38:58 +0200 Subject: make buffs work --- rust/src/buff_phase.rs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'rust/src/buff_phase.rs') diff --git a/rust/src/buff_phase.rs b/rust/src/buff_phase.rs index e64508e..f69fecc 100644 --- a/rust/src/buff_phase.rs +++ b/rust/src/buff_phase.rs @@ -2,16 +2,16 @@ use gdnative::api::*; use gdnative::prelude::*; use crate::buff_trait::Buff; -struct BuffPhase { +pub struct BuffPhase { name: String, description: String, - rigid_body: Option>, + rigid_body: Box>, wall_layer_bit: i64, } impl BuffPhase { - fn new(rigid_body: Option>) -> Self { + pub fn new(rigid_body: Box>) -> 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); @@ -20,7 +20,6 @@ impl BuffPhase { name: String::from("Phase"), description: String::from("Phases through thin fences"), rigid_body, - wall_layer_bit: mask_bit, } } @@ -28,26 +27,12 @@ impl BuffPhase { 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") - } + // actually disable the collision to the fences + self.rigid_body.assume_safe().set_collision_mask_bit(self.wall_layer_bit, false); } 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") - } + self.rigid_body.assume_safe().set_collision_mask_bit(self.wall_layer_bit, false); } fn get_name(self) -> GodotString { -- cgit