Improve how map is fetched for bullet

This commit is contained in:
Sofia 2026-07-21 01:10:42 +03:00
parent 698c9067a7
commit dcc729fc89

View File

@ -3,7 +3,7 @@ use godot::{
prelude::*, prelude::*,
}; };
use crate::{net::util::cast_ray, player::IPlayer}; use crate::{game_manager::Game, net::util::cast_ray, player::IPlayer};
pub trait Weapon { pub trait Weapon {
fn shoot(&mut self, player_rid: Rid, player_id: u16, to: Vector3, deal_damage: bool); fn shoot(&mut self, player_rid: Rid, player_id: u16, to: Vector3, deal_damage: bool);
@ -49,9 +49,13 @@ impl Weapon for Raygun {
bullet.bind_mut().source = Some(source.get_global_position()); bullet.bind_mut().source = Some(source.get_global_position());
bullet.bind_mut().target = Some(beam_end); bullet.bind_mut().target = Some(beam_end);
if let Some(mut parent) = self.base().find_parent("map") { self.run_deferred(move |_| {
parent.add_child(&bullet); if let Some(mut game) = Game::singleton()
} && let Some(map) = &mut game.bind_mut().current_map
{
map.add_child(&bullet);
}
});
} }
if deal_damage && let Some(target) = target { if deal_damage && let Some(target) = target {