~starkingdoms/starkingdoms

9f34e42b7dd9581502df9d3dd659ddad355153e7 — ghostlyzsh 1 year, 11 months ago f9c5c52
what is git doing
1 files changed, 53 insertions(+), 34 deletions(-)

M server/src/main.rs
M server/src/main.rs => server/src/main.rs +53 -34
@@ 131,7 131,8 @@ fn spawn_planets(mut commands: Commands) {
        .insert(AdditionalMassProperties::Mass(MARS_MASS))
        .insert(ReadMassProperties::default())
        .with_children(|children| {
            children.spawn(Collider::ball((MARS_SIZE + 3.) / SCALE))
            children
                .spawn(Collider::ball((MARS_SIZE + 3.) / SCALE))
                .insert(ActiveEvents::COLLISION_EVENTS)
                .insert(Sensor);
        })


@@ 278,7 279,7 @@ fn on_message(
                                radius: match *planet_type {
                                    PlanetType::Earth => EARTH_SIZE,
                                    PlanetType::Moon => MOON_SIZE,
                                    PlanetType::Mars => MARS_SIZE
                                    PlanetType::Mars => MARS_SIZE,
                                },
                            },
                        ));


@@ 837,8 838,14 @@ fn convert_modules(
    rapier_context: Res<RapierContext>,
    planet_query: Query<(Entity, &PlanetType, &Children)>,
    player_query: Query<&Attach, With<Player>>,
    mut attached_query: Query<(Entity, &mut PartType, &mut Attach, &Children, &Transform), Without<Player>>,
    mut collider_query: Query<(&mut Collider, &mut Transform, &Parent), (Without<Player>, Without<Attach>)>,
    mut attached_query: Query<
        (Entity, &mut PartType, &mut Attach, &Children, &Transform),
        Without<Player>,
    >,
    mut collider_query: Query<
        (&mut Collider, &mut Transform, &Parent),
        (Without<Player>, Without<Attach>),
    >,
    mut packet_send: EventWriter<ServerEvent>,
) {
    for (_planet_entity, planet_type, children) in &planet_query {


@@ 893,13 900,20 @@ fn convert_modules_recursive(
    commands: &mut Commands,
    planet_type: PlanetType,
    attach: Attach,
    attached_query: &mut Query<(Entity, &mut PartType, &mut Attach, &Children, &Transform), Without<Player>>,
    collider_query: &mut Query<(&mut Collider, &mut Transform, &Parent), (Without<Player>, Without<Attach>)>,
    attached_query: &mut Query<
        (Entity, &mut PartType, &mut Attach, &Children, &Transform),
        Without<Player>,
    >,
    collider_query: &mut Query<
        (&mut Collider, &mut Transform, &Parent),
        (Without<Player>, Without<Attach>),
    >,
    packet_send: &mut EventWriter<ServerEvent>,
) {
    for child in attach.children {
        if let Some(child) = child {
            let (module_entity, mut part_type, mut attach, children, module_transform) = attached_query.get_mut(child).unwrap();
            let (module_entity, mut part_type, mut attach, children, module_transform) =
                attached_query.get_mut(child).unwrap();
            if *part_type == PartType::Cargo {
                match planet_type {
                    PlanetType::Mars => {


@@ 909,8 923,14 @@ fn convert_modules_recursive(
                        *collider =
                            Collider::cuboid(PART_HALF_SIZE / SCALE, PART_HALF_SIZE / SCALE);
                        *transform = Transform::from_xyz(0., 0., 0.);
                        commands.get_entity(module_entity).unwrap().remove::<CanAttach>();
                        commands.get_entity(module_entity).unwrap().insert(CanAttach(15));
                        commands
                            .get_entity(module_entity)
                            .unwrap()
                            .remove::<CanAttach>();
                        commands
                            .get_entity(module_entity)
                            .unwrap()
                            .insert(CanAttach(15));
                        let packet = Packet::DespawnPart { id: child.index() };
                        let buf = serde_json::to_vec(&packet).unwrap();
                        packet_send.send(ServerEvent::Broadcast(MessageType::Text, buf.clone()));


@@ 930,8 950,7 @@ fn convert_modules_recursive(
                        *part_type = PartType::LandingThruster;
                        let (mut collider, mut transform, _) =
                            collider_query.get_mut(*children.first().unwrap()).unwrap();
                        *collider =
                            Collider::cuboid(PART_HALF_SIZE / SCALE, 18.75 / SCALE);
                        *collider = Collider::cuboid(PART_HALF_SIZE / SCALE, 18.75 / SCALE);
                        *transform = Transform::from_xyz(0., 6.25 / SCALE, 0.);
                        //commands.get_entity(module_entity).unwrap().remove::<CanAttach>();
                        let joint = PrismaticJointBuilder::new(Vec2::new(0., 1.))


@@ 943,29 962,29 @@ fn convert_modules_recursive(
                            transform: TransformBundle::from(*module_transform),
                            part_type: PartType::LandingThrusterSuspension,
                        });
                        suspension.insert(RigidBody::Dynamic)
                        .with_children(|children| {
                            children
                                .spawn(Collider::cuboid(PART_HALF_SIZE / SCALE, 1. / SCALE))
                                .insert(TransformBundle::from(Transform::from_xyz(
                                     0.,
                                    -24. / SCALE,
                                     0.,
                                )));
                        })
                        .insert(ImpulseJoint::new(module_entity, joint))
                        .insert(ExternalForce::default())
                        .insert(ExternalImpulse::default())
                        .insert(Velocity::default())
                        .insert(ReadMassProperties::default())
                        .insert(Attach {
                            associated_player: attach.associated_player,
                            parent: Some(module_entity),
                            children: [None, None, None, None],
                        });
                        suspension
                            .insert(RigidBody::Dynamic)
                            .with_children(|children| {
                                children
                                    .spawn(Collider::cuboid(PART_HALF_SIZE / SCALE, 1. / SCALE))
                                    .insert(TransformBundle::from(Transform::from_xyz(
                                        0.,
                                        -24. / SCALE,
                                        0.,
                                    )));
                            })
                            .insert(ImpulseJoint::new(module_entity, joint))
                            .insert(ExternalForce::default())
                            .insert(ExternalImpulse::default())
                            .insert(Velocity::default())
                            .insert(ReadMassProperties::default())
                            .insert(Attach {
                                associated_player: attach.associated_player,
                                parent: Some(module_entity),
                                children: [None, None, None, None],
                            });
                        attach.children[2] = Some(suspension.id());


                        let packet = Packet::DespawnPart { id: child.index() };
                        let buf = serde_json::to_vec(&packet).unwrap();
                        packet_send.send(ServerEvent::Broadcast(MessageType::Text, buf.clone()));


@@ 985,8 1004,8 @@ fn convert_modules_recursive(
                            id: suspension.id().index(),
                            part: Part {
                                part_type: PartType::LandingThrusterSuspension,
                                transform: proto_transform!(transform)
                            }
                                transform: proto_transform!(transform),
                            },
                        };
                        let buf = serde_json::to_vec(&packet).unwrap();
                        packet_send.send(ServerEvent::Broadcast(MessageType::Text, buf));