~starkingdoms/starkingdoms

b963b15e4783be48ee0241ae0acc31d622e00412 — core 1 year, 11 months ago 1362477 + b55a3b3
Merge remote-tracking branch 'origin/bevy_rewrite' into bevy_rewrite
1 files changed, 163 insertions(+), 28 deletions(-)

M server/src/main.rs
M server/src/main.rs => server/src/main.rs +163 -28
@@ 76,8 76,7 @@ fn main() {
        .add_systems(Update, on_message)
        .add_systems(Update, on_close)
        .add_systems(FixedUpdate, on_position_change)
        .add_systems(FixedUpdate, gravity_update)
        .add_systems(FixedUpdate, player_input_update)
        .add_systems(FixedUpdate, (gravity_update, player_input_update).chain())
        .add_systems(FixedUpdate, convert_modules)
        //.insert_resource(Time::<Fixed>::from_seconds(1.0/20.0))
        .run();


@@ 478,6 477,15 @@ fn on_message(
                                        let mut children = [None, None, None, None];
                                        if let Some(loose_attach) = module.4 {
                                            commands.entity(entity).remove::<LooseAttach>();
                                            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],
                                                    });
                                            }
                                            children = loose_attach.children;
                                        }
                                        let mut module_entity = commands.entity(module.0);


@@ 488,6 496,20 @@ fn on_message(
                                            children,
                                        });
                                        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;
                                            transform.translation = vec3(
                                                p_pos.x + 53. / SCALE * angle.sin(),
                                                p_pos.y - 53. / SCALE * angle.cos(),
                                                0.,
                                            );
                                            transform.rotation =
                                                Quat::from_euler(EulerRot::ZYX, angle, 0., 0.);
                                        }
                                        break;
                                    } else if attach.children[0] == None
                                        && -30. / SCALE < rel_y


@@ 500,18 522,23 @@ fn on_message(
                                            p_pos.y + 53. / SCALE * angle.cos(),
                                            0.,
                                        );
                                        module.2.rotation = Quat::from_euler(
                                            EulerRot::ZYX,
                                            angle + std::f32::consts::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));
                                        let mut children = [None, None, None, None];
                                        if let Some(loose_attach) = module.4 {
                                            commands.entity(entity).remove::<LooseAttach>();
                                            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],
                                                    });
                                            }
                                            children = loose_attach.children;
                                        }
                                        let mut module_entity = commands.entity(module.0);


@@ 522,6 549,20 @@ fn on_message(
                                            children,
                                        });
                                        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;
                                            transform.translation = vec3(
                                                p_pos.x - 53. / SCALE * angle.sin(),
                                                p_pos.y + 53. / SCALE * angle.cos(),
                                                0.,
                                            );
                                            transform.rotation =
                                                Quat::from_euler(EulerRot::ZYX, angle + PI, 0., 0.);
                                        }
                                        break;
                                    } else if attach.children[1] == None
                                        && -30. / SCALE < rel_x


@@ 536,7 577,7 @@ fn on_message(
                                        );
                                        module.2.rotation = Quat::from_euler(
                                            EulerRot::ZYX,
                                            angle + (std::f32::consts::PI / 2.),
                                            angle + (PI / 2.),
                                            0.,
                                            0.,
                                        );


@@ 547,6 588,15 @@ fn on_message(
                                        let mut children = [None, None, None, None];
                                        if let Some(loose_attach) = module.4 {
                                            commands.entity(entity).remove::<LooseAttach>();
                                            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],
                                                    });
                                            }
                                            children = loose_attach.children;
                                        }
                                        let mut module_entity = commands.entity(module.0);


@@ 557,6 607,24 @@ fn on_message(
                                            children,
                                        });
                                        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;
                                            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.,
                                            );
                                        }
                                        break;
                                    } else if attach.children[3] == None
                                        && 15. / SCALE < rel_x


@@ 571,7 639,7 @@ fn on_message(
                                        );
                                        module.2.rotation = Quat::from_euler(
                                            EulerRot::ZYX,
                                            angle - (std::f32::consts::PI / 2.),
                                            angle - (PI / 2.),
                                            0.,
                                            0.,
                                        );


@@ 582,6 650,15 @@ fn on_message(
                                        let mut children = [None, None, None, None];
                                        if let Some(loose_attach) = module.4 {
                                            commands.entity(entity).remove::<LooseAttach>();
                                            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],
                                                    });
                                            }
                                            children = loose_attach.children;
                                        }
                                        let mut module_entity = commands.entity(module.0);


@@ 592,6 669,24 @@ fn on_message(
                                            children,
                                        });
                                        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;
                                            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.,
                                            );
                                        }
                                        break;
                                    }
                                } else if attached_query.contains(select) {


@@ 599,17 694,21 @@ fn on_message(
                                    let parent = module.3.parent.unwrap();
                                    commands.entity(select).remove::<ImpulseJoint>();
                                    commands.entity(select).remove::<Attach>();
                                    let children_attach = module.3.clone();
                                    if *module.1 == PartType::LandingThruster {
                                        commands.entity(entity).insert(LooseAttach {
                                            children: attach.children,
                                        commands.entity(select).insert(LooseAttach {
                                            children: module.3.children,
                                        });
                                        commands
                                            .entity(module.3.children[2].unwrap())
                                            .remove::<Attach>();
                                    } else {
                                        detach_recursive(
                                            &mut commands,
                                            module.3.clone(),
                                            &mut attached_query,
                                        );
                                    }
                                    let children_attach = module.3.clone();
                                    detach_recursive(
                                        &mut commands,
                                        module.3.clone(),
                                        &mut attached_query,
                                    );
                                    if attached_query.contains(parent) {
                                        {
                                            let mut parent_attach =


@@ 766,13 865,17 @@ fn detach_recursive(
                    attached_query.get(child).unwrap();
                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(attach.children[2].unwrap())
                        .remove::<Attach>();
                    continue;
                } else if *part_type == PartType::LandingThrusterSuspension {
                    let parent = attach.parent.unwrap();
                    let parent_attach = attached_query.get(parent).unwrap().3;
                    println!("suspension {:?} {:?}", parent_attach.children, entity);
                    commands.entity(parent).insert(LooseAttach {
                        children: parent_attach.children,
                    });


@@ 861,6 964,15 @@ fn attach_on_module_tree(
                let mut children = [None, None, None, None];
                if let Some(loose_attach) = loose_attach {
                    commands.entity(entity).remove::<LooseAttach>();
                    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],
                            });
                    }
                    children = loose_attach.children;
                }
                let mut module_entity = commands.entity(module.0);


@@ 893,6 1005,15 @@ fn attach_on_module_tree(
                let mut children = [None, None, None, None];
                if let Some(loose_attach) = loose_attach {
                    commands.entity(entity).remove::<LooseAttach>();
                    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],
                            });
                    }
                    children = loose_attach.children;
                }
                let mut module_entity = commands.entity(module.0);


@@ 925,6 1046,15 @@ fn attach_on_module_tree(
                let mut children = [None, None, None, None];
                if let Some(loose_attach) = loose_attach {
                    commands.entity(entity).remove::<LooseAttach>();
                    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],
                            });
                    }
                    children = loose_attach.children;
                }
                let mut module_entity = commands.entity(module.0);


@@ 938,15 1068,19 @@ fn attach_on_module_tree(
                return true;
            }
            ret = ret
                | attach_on_module_tree(
                    x,
                    y,
                    commands,
                    attach.clone(),
                    select,
                    attached_query,
                    part_query,
                );
                | if *module.1 != PartType::LandingThruster {
                    attach_on_module_tree(
                        x,
                        y,
                        commands,
                        attach.clone(),
                        select,
                        attached_query,
                        part_query,
                    )
                } else {
                    false
                };
        }
    }
    return ret;


@@ 1076,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),