~starkingdoms/starkingdoms

1f79f7af795a52fb3152befc12f42fa42821b20d — ghostlyzsh 1 year, 11 months ago db4a4e6
can now reattach landing thruster
1 files changed, 53 insertions(+), 13 deletions(-)

M server/src/main.rs
M server/src/main.rs => server/src/main.rs +53 -13
@@ 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<PlanetType>, Without<Player>, Without<Attach>),
    >,
    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::<LooseAttach>();
                                            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::<LooseAttach>();
                                            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::<LooseAttach>();
                                            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::<LooseAttach>();
                                            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::<ImpulseJoint>();
                                    commands.entity(select).remove::<Attach>();
                                    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::<Attach>();
                if *part_type == PartType::LandingThruster {
                    commands.entity(entity).remove::<ImpulseJoint>();
                    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::<ImpulseJoint>();
                    detach_recursive(commands, attach.clone(), attached_query);


@@ 780,7 814,13 @@ fn attach_on_module_tree(
        (Without<PlanetType>, Without<Player>),
    >,
    part_query: &mut Query<
        (Entity, &PartType, &mut Transform, &mut Velocity, Option<&LooseAttach>),
        (
            Entity,
            &PartType,
            &mut Transform,
            &mut Velocity,
            Option<&LooseAttach>,
        ),
        (Without<PlanetType>, Without<Player>, Without<Attach>),
    >,
) -> bool {