From 1f79f7af795a52fb3152befc12f42fa42821b20d Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Sat, 6 Jan 2024 00:18:37 -0600 Subject: [PATCH] can now reattach landing thruster --- server/src/main.rs | 66 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 88a0c1069b3bc156e5e2232f7151615a158d0a60..799ef3154cbfd1f4e9cd0432155b99363d3085a4 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -195,7 +195,13 @@ fn on_message( mut commands: Commands, planet_query: Query<(Entity, &PlanetType, &Transform)>, mut part_query: Query< - (Entity, &PartType, &mut Transform, &mut Velocity, Option<&LooseAttach>), + ( + Entity, + &PartType, + &mut Transform, + &mut Velocity, + Option<&LooseAttach>, + ), (Without, Without, Without), >, mut attached_query: Query< @@ -465,12 +471,17 @@ fn on_message( module.3.linvel = velocity.linvel; let joint = FixedJointBuilder::new() .local_anchor1(vec2(0. / SCALE, -53. / SCALE)); + let mut children = [None, None, None, None]; + if let Some(loose_attach) = module.4 { + commands.entity(entity).remove::(); + children = loose_attach.children; + } let mut module_entity = commands.entity(module.0); module_entity.insert(ImpulseJoint::new(entity, joint)); module_entity.insert(Attach { associated_player: Some(entity), parent: Some(entity), - children: [None, None, None, None], + children, }); attach.children[2] = Some(module.0); break; @@ -494,12 +505,17 @@ fn on_message( module.3.linvel = velocity.linvel; let joint = FixedJointBuilder::new() .local_anchor1(vec2(0. / SCALE, 53. / SCALE)); + let mut children = [None, None, None, None]; + if let Some(loose_attach) = module.4 { + commands.entity(entity).remove::(); + children = loose_attach.children; + } let mut module_entity = commands.entity(module.0); module_entity.insert(ImpulseJoint::new(entity, joint)); module_entity.insert(Attach { associated_player: Some(entity), parent: Some(entity), - children: [None, None, None, None], + children, }); attach.children[0] = Some(module.0); break; @@ -524,12 +540,17 @@ fn on_message( let joint = FixedJointBuilder::new() .local_anchor1(vec2(53. / SCALE, 0. / SCALE)) .local_basis2(std::f32::consts::PI / 2.); + let mut children = [None, None, None, None]; + if let Some(loose_attach) = module.4 { + commands.entity(entity).remove::(); + children = loose_attach.children; + } let mut module_entity = commands.entity(module.0); module_entity.insert(ImpulseJoint::new(entity, joint)); module_entity.insert(Attach { associated_player: Some(entity), parent: Some(entity), - children: [None, None, None, None], + children, }); attach.children[1] = Some(module.0); break; @@ -554,12 +575,17 @@ fn on_message( let joint = FixedJointBuilder::new() .local_anchor1(vec2(-53. / SCALE, 0. / SCALE)) .local_basis2(-std::f32::consts::PI / 2.); + let mut children = [None, None, None, None]; + if let Some(loose_attach) = module.4 { + commands.entity(entity).remove::(); + children = loose_attach.children; + } let mut module_entity = commands.entity(module.0); module_entity.insert(ImpulseJoint::new(entity, joint)); module_entity.insert(Attach { associated_player: Some(entity), parent: Some(entity), - children: [None, None, None, None], + children, }); attach.children[3] = Some(module.0); break; @@ -570,7 +596,9 @@ fn on_message( commands.entity(select).remove::(); commands.entity(select).remove::(); if *module.1 == PartType::LandingThruster { - commands.entity(entity).insert(LooseAttach { children: attach.children }); + commands.entity(entity).insert(LooseAttach { + children: attach.children, + }); } let children_attach = module.3.clone(); detach_recursive( @@ -604,8 +632,11 @@ fn on_message( module.2.translation = vec3(x / SCALE, y / SCALE, 0.); if *module.1 == PartType::LandingThruster { - let sub_entity = children_attach.children[2].unwrap(); - let mut suspension = attached_query.get_mut(sub_entity).unwrap(); + let sub_entity = + children_attach.children[2].unwrap(); + let mut suspension = attached_query + .get_mut(sub_entity) + .unwrap(); suspension.2.translation = vec3(x / SCALE, y / SCALE, 0.); } @@ -628,8 +659,7 @@ fn on_message( } // move module to cursor since no attach let mut part = part_query.get_mut(select).unwrap(); - part.2.translation = - vec3(x / SCALE, y / SCALE, 0.); + part.2.translation = vec3(x / SCALE, y / SCALE, 0.); if *part.1 == PartType::LandingThruster { if let Some(loose_attach) = part.4 { let sub_entity = loose_attach.children[2].unwrap(); @@ -733,11 +763,15 @@ fn detach_recursive( commands.entity(entity).remove::(); if *part_type == PartType::LandingThruster { commands.entity(entity).remove::(); - commands.entity(entity).insert(LooseAttach { children: attach.children }); + commands.entity(entity).insert(LooseAttach { + children: attach.children, + }); } else if *part_type == PartType::LandingThrusterSuspension { let parent = attach.parent.unwrap(); let parent_attach = attached_query.get(parent).unwrap().3; - commands.entity(parent).insert(LooseAttach { children: parent_attach.children }); + commands.entity(parent).insert(LooseAttach { + children: parent_attach.children, + }); } else { commands.entity(entity).remove::(); detach_recursive(commands, attach.clone(), attached_query); @@ -780,7 +814,13 @@ fn attach_on_module_tree( (Without, Without), >, part_query: &mut Query< - (Entity, &PartType, &mut Transform, &mut Velocity, Option<&LooseAttach>), + ( + Entity, + &PartType, + &mut Transform, + &mut Velocity, + Option<&LooseAttach>, + ), (Without, Without, Without), >, ) -> bool {