@@ 59,7 59,9 @@ fn main() {
let key = std::fs::read_to_string("/etc/starkingdoms/app_key").unwrap();
App::new()
- .insert_resource(AppKeys { app_key: key.into_bytes() })
+ .insert_resource(AppKeys {
+ app_key: key.into_bytes(),
+ })
.insert_resource(TwiteServerConfig {
addr: Ipv4Addr::new(0, 0, 0, 0),
port: 3000,
@@ 254,8 256,11 @@ fn on_message(
let packet: Packet = err_or_cont!(serde_json::from_str(&data));
match packet {
- Packet::ClientLogin { username, save, jwt } => {
-
+ Packet::ClientLogin {
+ username,
+ save,
+ jwt,
+ } => {
let angle: f32 = {
let mut rng = rand::thread_rng();
rng.gen::<f32>() * std::f32::consts::PI * 2.
@@ 266,7 271,7 @@ fn on_message(
0.0,
);
transform.rotate_z(angle);
- let entity_id = commands
+ let mut entity_id = commands
.spawn(PlayerBundle {
part: PartBundle {
part_type: PartType::Hearty,
@@ 285,8 290,8 @@ fn on_message(
parent: None,
children: [None, None, None, None],
},
- })
- .insert(Collider::cuboid(
+ });
+ entity_id.insert(Collider::cuboid(
PART_HALF_SIZE / SCALE,
PART_HALF_SIZE / SCALE,
))
@@ 310,8 315,17 @@ fn on_message(
if let Ok(savefile) = unpack_savefile(&app_keys.app_key, save) {
// HEY! GHOSTLY! THIS SAVE FILE IS VALID! PLEASE LOAD IT!
// THANKS!
-
- load_savefile(&mut commands, transform, entity_id, entity_id, &mut attach, savefile.children, &mut attached_query, &mut part_query);
+
+ let entity = entity_id.id();
+ load_savefile(
+ &mut commands,
+ transform,
+ entity,
+ entity,
+ savefile.children,
+ &mut attached_query,
+ &mut part_query,
+ );
} else {
let packet = Packet::Message {
message_type: packet::MessageType::Error,
@@ 918,7 932,6 @@ fn load_savefile(
transform: Transform,
player_id: Entity,
parent: Entity,
- parent_attach: &mut Attach,
children: Vec<Option<SaveModule>>,
attached_query: &mut Query<
(
@@ 944,12 957,12 @@ fn load_savefile(
),
(Without<PlanetType>, Without<Player>, Without<Attach>),
>,
-) -> bool {
- let mut ret = false;
+) -> [Option<Entity>; 4] {
+ let mut ret = [None, None, None, None];
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;
@@ 967,44 980,64 @@ fn load_savefile(
offset = Vec2::new(-53., -53.);
angle_offset = -PI / 2.;
}
- let module = commands.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.))),
- part_type: child.part_type.into(),
- flags: PartFlags { attached: true },
- })
- .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 mut module = commands
+ .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.,
+ )),
+ ),
+ part_type: child.part_type.into(),
+ flags: PartFlags { attached: true },
+ });
+ let module_id = module.id();
+ 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 mut children = if PartType::from(child.part_type) != PartType::LandingThruster {
+ load_savefile(
+ commands,
+ transform,
+ player_id,
+ module_id,
+ child.children.clone(),
+ attached_query,
+ part_query,
+ )
+ } else { [None, None, None, None] };
let joint = FixedJointBuilder::new()
.local_anchor1(vec2(-53. / SCALE, 0. / SCALE))
.local_basis2(-PI / 2.);
- let mut children = [None, None, None, None];
- if child.part_type.into() == PartType::LandingThruster {
+ 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.))
@@ 1012,11 1045,19 @@ fn load_savefile(
.limits([0., 50. / SCALE])
.build();
let mut suspension = commands.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 },
});
@@ 1031,7 1072,7 @@ fn load_savefile(
0.,
)));
})
- .insert(ImpulseJoint::new(module.id(), joint))
+ .insert(ImpulseJoint::new(module_id, joint))
.insert(ExternalForce::default())
.insert(ExternalImpulse::default())
.insert(Velocity::default())
@@ 1043,7 1084,7 @@ fn load_savefile(
}))
.insert(Attach {
associated_player: Some(player_id),
- parent: Some(module.id()),
+ parent: Some(module_id),
children: [None, None, None, None],
});
children[2] = Some(suspension.id());
@@ 1054,23 1095,8 @@ fn load_savefile(
parent: Some(parent),
children,
});
- attached_query.get_mut(parent).children[3] = Some(module);
//module.5.attached = true;
-
- ret = ret
- | if *child.part_type.into() != PartType::LandingThruster {
- load_savefile(
- commands,
- transform,
- player_id,
- module.id(),
- child.children,
- attached_query,
- part_query,
- )
- } else {
- false
- };
+ ret[i] = Some(module.id());
}
}
return ret;