~starkingdoms/starkingdoms

2320c21d84801da5730ab5e7021cc94deb0e2435 — ghostlyzsh 1 year, 11 months ago b0af8db
loading bug fixes
1 files changed, 20 insertions(+), 13 deletions(-)

M server/src/main.rs
M server/src/main.rs => server/src/main.rs +20 -13
@@ 276,25 276,20 @@ fn on_message(
                        0.0,
                    );
                    transform.rotate_z(angle);
                    let mut entity_id = commands.spawn(PlayerBundle {
                        part: PartBundle {
                    let mut entity_id = commands.spawn((
                        PartBundle {
                            part_type: PartType::Hearty,
                            transform: TransformBundle::from(transform),
                            flags: PartFlags { attached: false },
                        },
                        player: Player {
                        Player {
                            addr: *from,
                            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,


@@ 315,14 310,19 @@ fn on_message(
                        .insert(RigidBody::Dynamic);
                    let id = entity_id.id().index();

                    let entity = entity_id.id();
                    let mut attach = Attach {
                        associated_player: None,
                        parent: None,
                        children: [None, None, None, None],
                    };
                    if let Some(save) = save {
                        // attempt to decode the savefile
                        if let Ok(savefile) = unpack_savefile(&app_keys.app_key, save) {
                            // HEY! GHOSTLY! THIS SAVE FILE IS VALID! PLEASE LOAD IT!
                            // THANKS!

                            let entity = entity_id.id();
                            load_savefile(
                            let children = load_savefile(
                                &mut commands,
                                transform,
                                entity,


@@ 331,6 331,7 @@ fn on_message(
                                &mut attached_query,
                                &mut part_query,
                            );
                            attach.children = children;
                        } else {
                            let packet = Packet::Message {
                                message_type: packet::MessageType::Error,


@@ 345,6 346,8 @@ fn on_message(
                    } else {
                        // nothing to do
                    }
                    let mut entity_id = commands.entity(entity);
                    entity_id.insert(attach);

                    // tell this player the planets
                    let mut planets = Vec::new();


@@ 979,6 982,7 @@ fn load_savefile(
    let mut ret = [None, None, None, None];
    for (i, child) in children.iter().enumerate() {
        if let Some(child) = child {
            let part_type = PartType::from(child.part_type);
            //let attachable = can_attach != None;

            let p_pos = transform.translation;


@@ 1023,7 1027,7 @@ fn load_savefile(
                module.id()
            };

            let children = if PartType::from(child.part_type) != PartType::LandingThruster {
            let children = if part_type != PartType::LandingThruster {
                load_savefile(
                    commands,
                    transform,


@@ 1067,6 1071,9 @@ fn load_savefile(
                .insert(ExternalImpulse::default())
                .insert(Velocity::default())
                .insert(ReadMassProperties::default());
            if part_type == PartType::Hub {
                module.insert(CanAttach(15));
            }

            let joint = FixedJointBuilder::new()
                .local_anchor1(vec2(offset.x / SCALE, offset.y / SCALE))


@@ 1074,7 1081,7 @@ fn load_savefile(

            module.insert(ImpulseJoint::new(parent, joint));

            if PartType::from(child.part_type) == PartType::LandingThruster {
            if part_type == PartType::LandingThruster {
                let joint = PrismaticJointBuilder::new(Vec2::new(0., 1.))
                    .local_anchor1(Vec2::new(0., 0.))
                    .local_anchor2(Vec2::new(0., 0.))