From b55a3b32f8f03750b06d06db6394ec7a0a80f5e5 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Sat, 6 Jan 2024 14:01:31 -0600 Subject: [PATCH] suspension limits --- server/src/main.rs | 141 ++++++++++++++++++++++++++++----------------- 1 file changed, 89 insertions(+), 52 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 34de1dab95c59d7692bcc2dcbd4363db5ed23226..d3cd7a071bb79f4d8f5f76598a86b7be90be8839 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -478,11 +478,13 @@ fn on_message( if let Some(loose_attach) = module.4 { commands.entity(entity).remove::(); if *module.1 == PartType::LandingThruster { - commands.entity(loose_attach.children[2].unwrap()).insert(Attach { - associated_player: attach.associated_player, - parent: Some(entity), - children: [None, None, None, None] - }); + commands + .entity(loose_attach.children[2].unwrap()) + .insert(Attach { + associated_player: attach.associated_player, + parent: Some(entity), + children: [None, None, None, None], + }); } children = loose_attach.children; } @@ -496,7 +498,10 @@ fn on_message( attach.children[2] = Some(module.0); if *module.1 == PartType::LandingThruster { let loose_attach = module.4.unwrap().clone(); - let mut transform = part_query.get_mut(loose_attach.children[2].unwrap()).unwrap().2; + let mut transform = part_query + .get_mut(loose_attach.children[2].unwrap()) + .unwrap() + .2; transform.translation = vec3( p_pos.x + 53. / SCALE * angle.sin(), p_pos.y - 53. / SCALE * angle.cos(), @@ -517,12 +522,8 @@ fn on_message( p_pos.y + 53. / SCALE * angle.cos(), 0., ); - module.2.rotation = Quat::from_euler( - EulerRot::ZYX, - angle + PI, - 0., - 0., - ); + module.2.rotation = + Quat::from_euler(EulerRot::ZYX, angle + PI, 0., 0.); module.3.linvel = velocity.linvel; let joint = FixedJointBuilder::new() .local_anchor1(vec2(0. / SCALE, 53. / SCALE)); @@ -530,11 +531,13 @@ fn on_message( if let Some(loose_attach) = module.4 { commands.entity(entity).remove::(); if *module.1 == PartType::LandingThruster { - commands.entity(loose_attach.children[2].unwrap()).insert(Attach { - associated_player: attach.associated_player, - parent: Some(entity), - children: [None, None, None, None] - }); + commands + .entity(loose_attach.children[2].unwrap()) + .insert(Attach { + associated_player: attach.associated_player, + parent: Some(entity), + children: [None, None, None, None], + }); } children = loose_attach.children; } @@ -548,7 +551,10 @@ fn on_message( attach.children[0] = Some(module.0); if *module.1 == PartType::LandingThruster { let loose_attach = module.4.unwrap().clone(); - let mut transform = part_query.get_mut(loose_attach.children[2].unwrap()).unwrap().2; + let mut transform = part_query + .get_mut(loose_attach.children[2].unwrap()) + .unwrap() + .2; transform.translation = vec3( p_pos.x - 53. / SCALE * angle.sin(), p_pos.y + 53. / SCALE * angle.cos(), @@ -583,11 +589,13 @@ fn on_message( if let Some(loose_attach) = module.4 { commands.entity(entity).remove::(); if *module.1 == PartType::LandingThruster { - commands.entity(loose_attach.children[2].unwrap()).insert(Attach { - associated_player: attach.associated_player, - parent: Some(entity), - children: [None, None, None, None] - }); + commands + .entity(loose_attach.children[2].unwrap()) + .insert(Attach { + associated_player: attach.associated_player, + parent: Some(entity), + children: [None, None, None, None], + }); } children = loose_attach.children; } @@ -601,14 +609,21 @@ fn on_message( attach.children[1] = Some(module.0); if *module.1 == PartType::LandingThruster { let loose_attach = module.4.unwrap().clone(); - let mut transform = part_query.get_mut(loose_attach.children[2].unwrap()).unwrap().2; + let mut transform = part_query + .get_mut(loose_attach.children[2].unwrap()) + .unwrap() + .2; transform.translation = vec3( p_pos.x + 53. / SCALE * angle.cos(), p_pos.y + 53. / SCALE * angle.sin(), 0., ); - transform.rotation = - Quat::from_euler(EulerRot::ZYX, angle + (PI / 2.), 0., 0.); + transform.rotation = Quat::from_euler( + EulerRot::ZYX, + angle + (PI / 2.), + 0., + 0., + ); } break; } else if attach.children[3] == None @@ -636,11 +651,13 @@ fn on_message( if let Some(loose_attach) = module.4 { commands.entity(entity).remove::(); if *module.1 == PartType::LandingThruster { - commands.entity(loose_attach.children[2].unwrap()).insert(Attach { - associated_player: attach.associated_player, - parent: Some(entity), - children: [None, None, None, None] - }); + commands + .entity(loose_attach.children[2].unwrap()) + .insert(Attach { + associated_player: attach.associated_player, + parent: Some(entity), + children: [None, None, None, None], + }); } children = loose_attach.children; } @@ -654,14 +671,21 @@ fn on_message( attach.children[3] = Some(module.0); if *module.1 == PartType::LandingThruster { let loose_attach = module.4.unwrap().clone(); - let mut transform = part_query.get_mut(loose_attach.children[2].unwrap()).unwrap().2; + let mut transform = part_query + .get_mut(loose_attach.children[2].unwrap()) + .unwrap() + .2; transform.translation = vec3( p_pos.x - 53. / SCALE * angle.cos(), p_pos.y - 53. / SCALE * angle.sin(), 0., ); - transform.rotation = - Quat::from_euler(EulerRot::ZYX, angle - (PI / 2.), 0., 0.); + transform.rotation = Quat::from_euler( + EulerRot::ZYX, + angle - (PI / 2.), + 0., + 0., + ); } break; } @@ -675,7 +699,9 @@ fn on_message( commands.entity(select).insert(LooseAttach { children: module.3.children, }); - commands.entity(module.3.children[2].unwrap()).remove::(); + commands + .entity(module.3.children[2].unwrap()) + .remove::(); } else { detach_recursive( &mut commands, @@ -842,7 +868,9 @@ fn detach_recursive( commands.entity(entity).insert(LooseAttach { children: attach.children, }); - commands.entity(attach.children[2].unwrap()).remove::(); + commands + .entity(attach.children[2].unwrap()) + .remove::(); continue; } else if *part_type == PartType::LandingThrusterSuspension { let parent = attach.parent.unwrap(); @@ -937,11 +965,13 @@ fn attach_on_module_tree( if let Some(loose_attach) = loose_attach { commands.entity(entity).remove::(); if *module.1 == PartType::LandingThruster { - commands.entity(loose_attach.children[2].unwrap()).insert(Attach { - associated_player: attach.associated_player, - parent: Some(entity), - children: [None, None, None, None] - }); + commands + .entity(loose_attach.children[2].unwrap()) + .insert(Attach { + associated_player: attach.associated_player, + parent: Some(entity), + children: [None, None, None, None], + }); } children = loose_attach.children; } @@ -976,11 +1006,13 @@ fn attach_on_module_tree( if let Some(loose_attach) = loose_attach { commands.entity(entity).remove::(); if *module.1 == PartType::LandingThruster { - commands.entity(loose_attach.children[2].unwrap()).insert(Attach { - associated_player: attach.associated_player, - parent: Some(entity), - children: [None, None, None, None] - }); + commands + .entity(loose_attach.children[2].unwrap()) + .insert(Attach { + associated_player: attach.associated_player, + parent: Some(entity), + children: [None, None, None, None], + }); } children = loose_attach.children; } @@ -1015,11 +1047,13 @@ fn attach_on_module_tree( if let Some(loose_attach) = loose_attach { commands.entity(entity).remove::(); if *module.1 == PartType::LandingThruster { - commands.entity(loose_attach.children[2].unwrap()).insert(Attach { - associated_player: attach.associated_player, - parent: Some(entity), - children: [None, None, None, None] - }); + commands + .entity(loose_attach.children[2].unwrap()) + .insert(Attach { + associated_player: attach.associated_player, + parent: Some(entity), + children: [None, None, None, None], + }); } children = loose_attach.children; } @@ -1044,7 +1078,9 @@ fn attach_on_module_tree( attached_query, part_query, ) - } else { false }; + } else { + false + }; } } return ret; @@ -1174,6 +1210,7 @@ fn convert_modules_recursive( .local_anchor1(Vec2::new(0., 0.)) .local_anchor2(Vec2::new(0., 0.)) .motor_position(0., 150., 10.) + .limits([0., 50. / SCALE]) .build(); let mut suspension = commands.spawn(PartBundle { transform: TransformBundle::from(*module_transform),