From 30d4656ac9bf5b06717d11869bb9016a367102f5 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Mon, 24 Mar 2025 12:48:53 -0500 Subject: [PATCH] attachment bug fixed and attached modules light up --- crates/client/src/components.rs | 2 +- crates/client/src/lib.rs | 2 +- crates/client/src/networking/mod.rs | 51 +++++++++++++++++++++-------- crates/client/src/rendering/mod.rs | 2 -- crates/server/src/module/mod.rs | 7 ++-- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/crates/client/src/components.rs b/crates/client/src/components.rs index ee513daa40cc977f1dd9e024569f8721ee23251b..c49bd96c7f32d074577ef6e96f392ef0b1f4949e 100644 --- a/crates/client/src/components.rs +++ b/crates/client/src/components.rs @@ -58,7 +58,7 @@ pub struct Player; #[derive(Component, Debug, Clone, Copy)] pub struct Planet; #[derive(Component, Debug, Clone, Copy)] -pub struct Part; +pub struct Part(pub bool); // Part(attached) #[derive(Component, Debug, Clone, Copy)] pub struct ServerId(pub u32); diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 827c16025fdacc77dfa8cb7be318dcdb0fcd699e..5da87b168bd8ff1f0dcfc9ca4fde012b3d99a022 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -51,7 +51,7 @@ pub fn start() { translation: Translation3::new(0.0, 0.0, 0.0), rotation: Rotation2::new(0.0), scale: Scale3::new(25.0, 25.0, 1.0), - }, Texture { name: "hearty.svg".to_string() }, Player, Part)); + }, Texture { name: "hearty.svg".to_string() }, Player, Part(false))); let event_loop = EventLoop::new().unwrap(); event_loop.set_control_flow(ControlFlow::Wait); diff --git a/crates/client/src/networking/mod.rs b/crates/client/src/networking/mod.rs index 105699501538a4bbd692bee4eedb25bbf09af8e4..7c657269418121ca897d5c302824555ba873416a 100644 --- a/crates/client/src/networking/mod.rs +++ b/crates/client/src/networking/mod.rs @@ -13,6 +13,29 @@ pub mod ws; #[path = "ws_native.rs"] pub mod ws; +fn texture_name(part_type: PartType, attached: bool) -> String { + use PartType::*; + if attached { + match part_type { + Placeholder => panic!("AHHHH PLACEHOLDER PANIC"), + Hearty => "hearty.svg", + Cargo => "cargo_on.svg", + Hub => "hub_on.svg", + LandingThruster => "landingthruster_on.svg", + LandingThrusterSuspension => "landingleg.svg", + }.to_string() + } else { + match part_type { + Placeholder => panic!("AHHHH PLACEHOLDER PANIC"), + Hearty => "hearty.svg", + Cargo => "cargo_off.svg", + Hub => "hub_off.svg", + LandingThruster => "landingthruster_off.svg", + LandingThrusterSuspension => "landingleg.svg", + }.to_string() + } +} + pub fn process_packets( world: &mut World, send_packet_events: &mut Events, @@ -39,7 +62,7 @@ pub fn process_packets( scale: Scale3::new(25.0, 25.0, 1.0), }, Texture { name: "hearty.svg".to_string(), - }, ServerId(player.0), Part)); + }, ServerId(player.0), Part(false))); } } SpawnPlayer { id, username } => { @@ -50,24 +73,16 @@ pub fn process_packets( scale: Scale3::new(25.0, 25.0, 1.0), }, Texture { name: "hearty.svg".to_string(), - }, ServerId(*id), Part)); + }, ServerId(*id), Part(false))); } SpawnPart { id, part } => { - use PartType::*; world.spawn((Transform { translation: Translation3::new(part.transform.x, part.transform.y, 0.0), rotation: Rotation2::new(part.transform.rot), scale: Scale3::new(25.0, 25.0, 1.0), }, Texture { - name: match part.part_type { - Placeholder => panic!("AHHHH PLACEHOLDER PANIC"), - Hearty => "hearty.svg", - Cargo => "cargo_off.svg", - Hub => "hub_off.svg", - LandingThruster => "landingthruster_off.svg", - LandingThrusterSuspension => "landingleg.svg", - }.to_string() - }, ServerId(*id), Part)); + name: texture_name(part.part_type, part.flags.attached), + }, ServerId(*id), Part(part.flags.attached))); } PartPositions { parts } => { for (id, part) in parts { @@ -90,12 +105,20 @@ pub fn process_packets( camera.y = -part.transform.y; } } - let mut part_query = world.query_filtered::<(&ServerId, &mut Transform), With>(); - for (server_id, mut transform) in part_query.iter_mut(world) { + let mut part_query = world.query::<(Entity, &ServerId, &mut Transform, &mut Texture, &mut Part)>(); + for (entity, server_id, mut transform, mut texture, mut bevy_part) in part_query.iter_mut(world) { if server_id.0 == *id { transform.translation.x = part.transform.x; transform.translation.y = part.transform.y; transform.rotation = Rotation2::new(part.transform.rot); + + if part.flags.attached && !bevy_part.0 { + texture.name = texture_name(part.part_type, part.flags.attached); + bevy_part.0 = true; + } else if !part.flags.attached && bevy_part.0 { + texture.name = texture_name(part.part_type, part.flags.attached); + bevy_part.0 = false; + } } } } diff --git a/crates/client/src/rendering/mod.rs b/crates/client/src/rendering/mod.rs index 51368fd94520f7d81b1fe5f781e0671de44b0c04..d43f57ddce10140504f00418aa911af5715e8061 100644 --- a/crates/client/src/rendering/mod.rs +++ b/crates/client/src/rendering/mod.rs @@ -339,11 +339,9 @@ impl ApplicationHandler for App { _ => return, }; let camera = self.world.get_resource::().unwrap(); - tracing::info!("{}, {}", self.mouse_pos.x, self.mouse_pos.y); let view = camera.to_cursor_matrix(); let pos = view * Vector3::new(self.mouse_pos.x as f32, self.mouse_pos.y as f32, 1.0); let pos = pos / pos.z; - tracing::info!("{}, {}", pos.x, pos.y); self.send_packet_events.send(SendPacket(Packet::PlayerMouseInput { x: pos.x, y: pos.y, diff --git a/crates/server/src/module/mod.rs b/crates/server/src/module/mod.rs index 5e61fbf6a2ee5eab60998b224a185d78ebbd2794..466cfb73bb142d13037cf64cba8015b47d87db7e 100644 --- a/crates/server/src/module/mod.rs +++ b/crates/server/src/module/mod.rs @@ -650,9 +650,12 @@ pub fn break_modules( if part_type.0 == c_PartType::LandingThrusterSuspension { continue; } - let handle = joints.get(&entity).unwrap(); + let handle = match joints.get(&entity) { + Some(handle) => handle, + None => continue + }; let joint = rapier_context.impulse_joints.get(*handle).unwrap(); - if joint.impulses.magnitude() > 0.2 { + if joint.impulses.magnitude() > 2.0 { flags.attached = false; detach_list.push((entity, *part_type, attach.clone())); }