diff --git a/rust/src/player.rs b/rust/src/player.rs index f6afb79..bed8cf4 100644 --- a/rust/src/player.rs +++ b/rust/src/player.rs @@ -21,7 +21,7 @@ use crate::{ }, soldier_mesh::SoldierMesh, ui::cli::CommandLinePanel, - weapon::Raygun, + weapon::{Raygun, Weapon}, }; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] @@ -83,7 +83,7 @@ pub struct LocalPlayer { soldier_mesh: Option>, pub player_id: Option, - pub weapon: Option>, + pub weapon: Option>, movement_dir: Vector3, y_speed: f32, @@ -157,7 +157,7 @@ impl IPlayer for LocalPlayer { fn try_shoot(&mut self, to: Vector3, deal_damage: bool) -> bool { if self.shoot_cd <= 0. { if let Some(weapon) = &mut self.weapon { - weapon.bind_mut().shoot(to, deal_damage); + weapon.dyn_bind_mut().shoot(to, deal_damage); } self.shoot_cd = 0.2; true @@ -314,7 +314,7 @@ pub struct RemotePlayer { soldier_mesh: Option>, pub player_id: Option, - pub weapon: Option>, + pub weapon: Option>, movement_dir: Vector3, y_speed: f32, @@ -384,7 +384,7 @@ impl IPlayer for RemotePlayer { fn try_shoot(&mut self, to: Vector3, deal_damage: bool) -> bool { if self.shoot_cd <= 0. { if let Some(weapon) = &mut self.weapon { - weapon.bind_mut().shoot(to, deal_damage); + weapon.dyn_bind_mut().shoot(to, deal_damage); } self.shoot_cd = 0.2; true diff --git a/rust/src/soldier_mesh.rs b/rust/src/soldier_mesh.rs index 4e875b0..a94b291 100644 --- a/rust/src/soldier_mesh.rs +++ b/rust/src/soldier_mesh.rs @@ -6,7 +6,7 @@ use godot::{ prelude::*, }; -use crate::weapon::Raygun; +use crate::weapon::{Raygun, Weapon}; #[derive(GodotClass)] #[class(base=Node3D, init)] @@ -43,16 +43,19 @@ impl SoldierMesh { } } - pub fn spawn_raygun(&mut self) -> Option> { + pub fn spawn_raygun(&mut self) -> Option> { if let Some(raygun) = &self.raygun { let node = raygun.instantiate_as::(); - self.spawn_weapon(node) + self.spawn_weapon(node.into_dyn().upcast()) } else { None } } - fn spawn_weapon(&mut self, node: Gd) -> Option> { + fn spawn_weapon( + &mut self, + node: DynGd, + ) -> Option> { if let Some(hand) = &mut self.hand_attachment { hand.add_child(&node); Some(node) diff --git a/rust/src/weapon.rs b/rust/src/weapon.rs index be85b5b..49eb62b 100644 --- a/rust/src/weapon.rs +++ b/rust/src/weapon.rs @@ -3,6 +3,10 @@ use godot::{ prelude::*, }; +pub trait Weapon { + fn shoot(&mut self, to: Vector3, deal_damage: bool); +} + #[derive(GodotClass)] #[class(base=Node3D, init)] pub struct Raygun { @@ -16,8 +20,9 @@ pub struct Raygun { base: Base, } -impl Raygun { - pub fn shoot(&mut self, to: Vector3, deal_damage: bool) { +#[godot_dyn] +impl Weapon for Raygun { + fn shoot(&mut self, to: Vector3, deal_damage: bool) { if let Some(emitter) = &mut self.sound_emitter { emitter.play(); } @@ -43,8 +48,6 @@ pub struct Beam { pub source: Option, pub target: Option, - alive_for: f64, - distance: f32, girth: f32,