~starkingdoms/starkingdoms

3394e014119412fa74989e1e24f62249fd65b8a6 — ghostlyzsh 1 year, 11 months ago b13d8b9
git stupid
1 files changed, 113 insertions(+), 66 deletions(-)

M server/src/main.rs
M server/src/main.rs => server/src/main.rs +113 -66
@@ 236,27 236,27 @@ fn on_login(
                        0.0,
                    );
                    transform.rotate_z(angle);
                    let mut entity_id = world
                        .spawn(PlayerBundle {
                            part: PartBundle {
                                part_type: PartType::Hearty,
                                transform: TransformBundle::from(transform),
                                flags: PartFlags { attached: false },
                            },
                            player: Player {
                                addr: *addr,
                                username: username.to_string(),
                                input: component::Input::default(),
                                selected: None,
                                save_eligibility: false,
                            },
                            attach: Attach {
                                associated_player: None,
                                parent: None,
                                children: [None, None, None, None],
                            },
                        });
                    entity_id.insert(Collider::cuboid(
                    let mut entity_id = world.spawn(PlayerBundle {
                        part: PartBundle {
                            part_type: PartType::Hearty,
                            transform: TransformBundle::from(transform),
                            flags: PartFlags { attached: false },
                        },
                        player: Player {
                            addr: *addr,
                            username: username.to_string(),
                            input: component::Input::default(),
                            selected: None,
                            save_eligibility: false,
                        },
                        attach: Attach {
                            associated_player: None,
                            parent: None,
                            children: [None, None, None, None],
                        },
                    });
                    entity_id
                        .insert(Collider::cuboid(
                            PART_HALF_SIZE / SCALE,
                            PART_HALF_SIZE / SCALE,
                        ))


@@ 275,7 275,6 @@ fn on_login(
                        .insert(RigidBody::Dynamic);
                    let id = entity_id.id().index();


                    let mut planet_query = world.query::<(Entity, &PlanetType, &Transform)>();
                    // tell this player the planets
                    let mut planets = Vec::new();


@@ 301,7 300,13 @@ fn on_login(
                    event_queue.push(ServerEvent::Send(*addr, MessageType::Text, buf));

                    // tell the player already existing users
                    let mut player_query = world.query_filtered::<(Entity, &mut Player, &Transform, &Velocity, &mut Attach), Without<PlanetType>>();
                    let mut player_query = world.query_filtered::<(
                        Entity,
                        &mut Player,
                        &Transform,
                        &Velocity,
                        &mut Attach,
                    ), Without<PlanetType>>();
                    let mut players = Vec::new();
                    for (entity, player, _, _, _) in player_query.iter(&world) {
                        players.push((entity.index(), player.username.clone()));


@@ 326,9 331,16 @@ fn on_login(
                    event_queue.push(ServerEvent::Broadcast(MessageType::Text, buf));

                    // tell the player where parts are
                    let mut part_query = world.query_filtered::<(Entity, &PartType, &mut Transform, &mut Velocity,
                                                                 Option<&LooseAttach>, &mut PartFlags),
                                                             (Without<PlanetType>, Without<Player>, Without<Attach>)>();
                    let mut part_query =
                        world.query_filtered::<(
                            Entity,
                            &PartType,
                            &mut Transform,
                            &mut Velocity,
                            Option<&LooseAttach>,
                            &mut PartFlags,
                        ), (Without<PlanetType>, Without<Player>, Without<Attach>)>(
                        );
                    let mut parts = Vec::new();
                    for (entity, part_type, transform, _, _, flags) in part_query.iter(&world) {
                        parts.push((


@@ 342,10 354,20 @@ fn on_login(
                            },
                        ));
                    }
                    let mut attached_query = world.query_filtered::<(Entity, &PartType, &mut Transform,
                                                                 &mut Attach, &Velocity, Option<&CanAttach>, Option<&LooseAttach>, &mut PartFlags),
                                                                 (Without<PlanetType>, Without<Player>)>();
                    for (entity, part_type, transform, _, _, _, _, flags) in attached_query.iter(&world) {
                    let mut attached_query = world.query_filtered::<(
                        Entity,
                        &PartType,
                        &mut Transform,
                        &mut Attach,
                        &Velocity,
                        Option<&CanAttach>,
                        Option<&LooseAttach>,
                        &mut PartFlags,
                    ), (Without<PlanetType>, Without<Player>)>(
                    );
                    for (entity, part_type, transform, _, _, _, _, flags) in
                        attached_query.iter(&world)
                    {
                        parts.push((
                            entity.index(),
                            Part {


@@ 386,7 408,16 @@ fn on_login(
                            // HEY! GHOSTLY! THIS SAVE FILE IS VALID! PLEASE LOAD IT!
                            // THANKS!
                            let mut attach = entity_id.get_mut::<Attach>().unwrap();
                            load_savefile(world, transform, entity_id.id(), entity_id.id(), &mut attach, savefile.children, &mut attached_query, &mut part_query);
                            load_savefile(
                                world,
                                transform,
                                entity_id.id(),
                                entity_id.id(),
                                &mut attach,
                                savefile.children,
                                &mut attached_query,
                                &mut part_query,
                            );
                        } else {
                            let packet = Packet::Message {
                                message_type: packet::MessageType::Error,


@@ 445,7 476,7 @@ fn load_savefile(
    for (i, child) in children.iter().enumerate() {
        if let Some(child) = child {
            //let attachable = can_attach != None;
            

            let p_pos = transform.translation;
            let angle = transform.rotation.to_euler(EulerRot::ZYX).0;
            let mut offset = Vec2::ZERO;


@@ 464,43 495,52 @@ fn load_savefile(
                angle_offset = -PI / 2.;
            }
            let mut module = world.spawn(PartBundle {
                transform: TransformBundle::from(Transform::from_xyz(
                               p_pos.x + offset.x / SCALE * angle.cos(),
                               p_pos.y + offset.y / SCALE * angle.sin(),
                               0.,
                           ).with_rotation(Quat::from_euler(EulerRot::ZYX, angle + angle_offset, 0., 0.))),
                transform: TransformBundle::from(
                    Transform::from_xyz(
                        p_pos.x + offset.x / SCALE * angle.cos(),
                        p_pos.y + offset.y / SCALE * angle.sin(),
                        0.,
                    )
                    .with_rotation(Quat::from_euler(
                        EulerRot::ZYX,
                        angle + angle_offset,
                        0.,
                        0.,
                    )),
                ),
                part_type: child.part_type.into(),
                flags: PartFlags { attached: true },
            });
            module.insert(RigidBody::Dynamic)
            .with_children(|children| {
                children
                    .spawn(Collider::cuboid(18.75 / SCALE, 23.4375 / SCALE))
                    .insert(TransformBundle::from(Transform::from_xyz(
                        0.,
                        1.5625 / SCALE,
                        0.,
                    )));
            })
            .insert(AdditionalMassProperties::MassProperties(MassProperties {
                local_center_of_mass: vec2(0.0, 0.0),
                mass: 0.0001,
                principal_inertia: 0.005,
            }))
            .insert(ExternalForce::default())
            .insert(ExternalImpulse::default())
            .insert(Velocity::default())
            .insert(ReadMassProperties::default());
            module
                .insert(RigidBody::Dynamic)
                .with_children(|children| {
                    children
                        .spawn(Collider::cuboid(18.75 / SCALE, 23.4375 / SCALE))
                        .insert(TransformBundle::from(Transform::from_xyz(
                            0.,
                            1.5625 / SCALE,
                            0.,
                        )));
                })
                .insert(AdditionalMassProperties::MassProperties(MassProperties {
                    local_center_of_mass: vec2(0.0, 0.0),
                    mass: 0.0001,
                    principal_inertia: 0.005,
                }))
                .insert(ExternalForce::default())
                .insert(ExternalImpulse::default())
                .insert(Velocity::default())
                .insert(ReadMassProperties::default());
            let joint = FixedJointBuilder::new()
                .local_anchor1(vec2(-53. / SCALE, 0. / SCALE))
                .local_basis2(-PI / 2.);
            let mut children = [None, None, None, None];
            if PartType::from(child.part_type) == PartType::LandingThruster {
                module.insert(Attach {
                        associated_player: Some(player_id),
                        parent: Some(module.id()),
                        children: [None, None, None, None],
                    });
                    associated_player: Some(player_id),
                    parent: Some(module.id()),
                    children: [None, None, None, None],
                });
                let joint = PrismaticJointBuilder::new(Vec2::new(0., 1.))
                    .local_anchor1(Vec2::new(0., 0.))
                    .local_anchor2(Vec2::new(0., 0.))


@@ 508,11 548,19 @@ fn load_savefile(
                    .limits([0., 50. / SCALE])
                    .build();
                let mut suspension = world.spawn(PartBundle {
                    transform: TransformBundle::from(Transform::from_xyz(
                                   p_pos.x + offset.x / SCALE * angle.cos(),
                                   p_pos.y + offset.y / SCALE * angle.sin(),
                                   0.,
                               ).with_rotation(Quat::from_euler(EulerRot::ZYX, angle + angle_offset, 0., 0.))),
                    transform: TransformBundle::from(
                        Transform::from_xyz(
                            p_pos.x + offset.x / SCALE * angle.cos(),
                            p_pos.y + offset.y / SCALE * angle.sin(),
                            0.,
                        )
                        .with_rotation(Quat::from_euler(
                            EulerRot::ZYX,
                            angle + angle_offset,
                            0.,
                            0.,
                        )),
                    ),
                    part_type: PartType::LandingThrusterSuspension,
                    flags: PartFlags { attached: false },
                });


@@ 1066,7 1114,6 @@ fn on_message(
    }
}


fn construct_save_data(
    attach: Attach,
    attached_query: &Query<