@@ 182,11 182,7 @@ fn module_spawn(
let mut rng = rand::thread_rng();
rng.gen::<f32>() * std::f32::consts::PI * 2.
};
- let mut transform = Transform::from_xyz(
- angle.cos() * 30.0,
- angle.sin() * 30.0,
- 0.0,
- );
+ let mut transform = Transform::from_xyz(angle.cos() * 30.0, angle.sin() * 30.0, 0.0);
transform.rotate_z(angle);
if part_query.iter().count() < FREE_MODULE_CAP {
let flags = PartFlags { attached: false };
@@ 200,11 196,7 @@ fn module_spawn(
.with_children(|children| {
children
.spawn(Collider::cuboid(0.375, 0.46875))
- .insert(TransformBundle::from(Transform::from_xyz(
- 0.,
- 0.03125,
- 0.,
- )));
+ .insert(TransformBundle::from(Transform::from_xyz(0., 0.03125, 0.)));
})
.insert(AdditionalMassProperties::MassProperties(MassProperties {
local_center_of_mass: vec2(0.0, 0.0),
@@ 282,11 274,8 @@ fn on_message(
let mut rng = rand::thread_rng();
rng.gen::<f32>() * std::f32::consts::PI * 2.
};
- let mut transform = Transform::from_xyz(
- angle.cos() * 30.0,
- angle.sin() * 30.0,
- 0.0,
- );
+ let mut transform =
+ Transform::from_xyz(angle.cos() * 30.0, angle.sin() * 30.0, 0.0);
transform.rotate_z(angle);
let mut entity_id = commands.spawn((
PartBundle {
@@ 303,10 292,7 @@ fn on_message(
},
));
entity_id
- .insert(Collider::cuboid(
- 0.5,
- 0.5,
- ))
+ .insert(Collider::cuboid(0.5, 0.5))
.insert(AdditionalMassProperties::MassProperties(MassProperties {
local_center_of_mass: vec2(0.0, 0.0),
mass: HEARTY_MASS,
@@ 570,8 556,8 @@ fn on_message(
Quat::from_euler(EulerRot::ZYX, angle, 0., 0.);
module.3.linvel = velocity.linvel;
module.5.attached = true;
- let joint = FixedJointBuilder::new()
- .local_anchor1(vec2(0., -1.06));
+ let joint =
+ FixedJointBuilder::new().local_anchor1(vec2(0., -1.06));
let mut children = [None, None, None, None];
if let Some(loose_attach) = module.4 {
commands.entity(entity).remove::<LooseAttach>();
@@ 624,8 610,8 @@ fn on_message(
Quat::from_euler(EulerRot::ZYX, angle + PI, 0., 0.);
module.3.linvel = velocity.linvel;
module.5.attached = true;
- let joint = FixedJointBuilder::new()
- .local_anchor1(vec2(0., 1.06));
+ let joint =
+ FixedJointBuilder::new().local_anchor1(vec2(0., 1.06));
let mut children = [None, None, None, None];
if let Some(loose_attach) = module.4 {
commands.entity(entity).remove::<LooseAttach>();
@@ 835,16 821,14 @@ fn on_message(
attach.children[i] = None;
let mut module =
attached_query.get_mut(select).unwrap();
- module.2.translation =
- vec3(x, y, 0.);
+ module.2.translation = vec3(x, y, 0.);
if *module.1 == PartType::LandingThruster {
let sub_entity =
children_attach.children[2].unwrap();
let mut suspension = attached_query
.get_mut(sub_entity)
.unwrap();
- suspension.2.translation =
- vec3(x, y, 0.);
+ suspension.2.translation = vec3(x, y, 0.);
}
}
}
@@ 889,15 873,9 @@ fn on_message(
let angle = -transform.rotation.z;
let x = rel_x * angle.cos() - rel_y * angle.sin();
let y = rel_x * angle.sin() + rel_y * angle.cos();
- let mut bound =
- [-0.5, 0.5, -0.5, 0.5]; // left, right, top, bottom
+ let mut bound = [-0.5, 0.5, -0.5, 0.5]; // left, right, top, bottom
if let PartType::Cargo = part_type {
- bound = [
- -0.375,
- 0.375,
- -0.5,
- 0.4375,
- ];
+ bound = [-0.375, 0.375, -0.5, 0.4375];
}
if bound[0] < x && x < bound[1] && bound[2] < y && y < bound[3] {
@@ 915,15 893,9 @@ fn on_message(
let angle = -transform.rotation.z;
let x = rel_x * angle.cos() - rel_y * angle.sin();
let y = rel_x * angle.sin() + rel_y * angle.cos();
- let mut bound =
- [-0.5, 0.5, -0.5, 0.5]; // left, right, top, bottom
+ let mut bound = [-0.5, 0.5, -0.5, 0.5]; // left, right, top, bottom
if let PartType::Cargo = part_type {
- bound = [
- -0.375,
- 0.375,
- -0.5,
- 0.4375
- ];
+ bound = [-0.375, 0.375, -0.5, 0.4375];
}
if bound[0] < x && x < bound[1] && bound[2] < y && y < bound[3] {
@@ 1094,15 1066,15 @@ fn load_savefile(
})
.insert(AdditionalMassProperties::MassProperties(MassProperties {
local_center_of_mass: vec2(0.0, 0.0),
- mass: if part_type == PartType::Cargo {
- CARGO_MASS
- } else if part_type == PartType::Hub {
- HUB_MASS
- } else if part_type == PartType::LandingThruster {
- LANDING_THRUSTER_MASS
- } else {
- 1.
- },
+ mass: if part_type == PartType::Cargo {
+ CARGO_MASS
+ } else if part_type == PartType::Hub {
+ HUB_MASS
+ } else if part_type == PartType::LandingThruster {
+ LANDING_THRUSTER_MASS
+ } else {
+ 1.
+ },
principal_inertia: 7.5,
}))
.insert(ExternalForce::default())
@@ 1127,11 1099,8 @@ fn load_savefile(
let mut suspension = commands.spawn(PartBundle {
transform: TransformBundle::from(
Transform::from_xyz(
- p_pos.x + offset.x * angle.cos()
- - offset.y * angle.sin(),
- p_pos.y
- + offset.x * angle.sin()
- + offset.y * angle.cos(),
+ p_pos.x + offset.x * angle.cos() - offset.y * angle.sin(),
+ p_pos.y + offset.x * angle.sin() + offset.y * angle.cos(),
0.,
)
.with_rotation(Quat::from_euler(
@@ 1149,11 1118,7 @@ fn load_savefile(
.with_children(|children| {
children
.spawn(Collider::cuboid(0.5, 0.02))
- .insert(TransformBundle::from(Transform::from_xyz(
- 0.,
- -0.48,
- 0.,
- )));
+ .insert(TransformBundle::from(Transform::from_xyz(0., -0.48, 0.)));
})
.insert(ImpulseJoint::new(module_id, joint))
.insert(ExternalForce::default())
@@ 1560,19 1525,24 @@ fn convert_modules_recursive(
packet_send: &mut EventWriter<WsEvent>,
) {
for child in attach.children.iter().flatten() {
- let (module_entity, mut part_type, mut attach, mut mass_prop, children, module_transform, part_flags) =
- attached_query.get_mut(*child).unwrap();
+ let (
+ module_entity,
+ mut part_type,
+ mut attach,
+ mut mass_prop,
+ children,
+ module_transform,
+ part_flags,
+ ) = attached_query.get_mut(*child).unwrap();
if *part_type == PartType::Cargo {
match planet_type {
PlanetType::Mars => {
*part_type = PartType::Hub;
- *mass_prop = AdditionalMassProperties::MassProperties(
- MassProperties {
- local_center_of_mass: Vec2::new(0.0, 0.0),
- mass: HUB_MASS,
- principal_inertia: 7.5,
- }
- );
+ *mass_prop = AdditionalMassProperties::MassProperties(MassProperties {
+ local_center_of_mass: Vec2::new(0.0, 0.0),
+ mass: HUB_MASS,
+ principal_inertia: 7.5,
+ });
let (mut collider, mut transform, _) =
collider_query.get_mut(*children.first().unwrap()).unwrap();
*collider = Collider::cuboid(0.5, 0.5);
@@ 1606,13 1576,11 @@ fn convert_modules_recursive(
}
PlanetType::Moon => {
*part_type = PartType::LandingThruster;
- *mass_prop = AdditionalMassProperties::MassProperties(
- MassProperties {
- local_center_of_mass: Vec2::new(0.0, 0.0),
- mass: LANDING_THRUSTER_MASS,
- principal_inertia: 7.5,
- }
- );
+ *mass_prop = AdditionalMassProperties::MassProperties(MassProperties {
+ local_center_of_mass: Vec2::new(0.0, 0.0),
+ mass: LANDING_THRUSTER_MASS,
+ principal_inertia: 7.5,
+ });
let (mut collider, mut transform, _) =
collider_query.get_mut(*children.first().unwrap()).unwrap();
*collider = Collider::cuboid(0.5, 0.375);
@@ 1634,11 1602,7 @@ fn convert_modules_recursive(
.with_children(|children| {
children
.spawn(Collider::cuboid(0.5, 0.02))
- .insert(TransformBundle::from(Transform::from_xyz(
- 0.,
- -0.48,
- 0.,
- )));
+ .insert(TransformBundle::from(Transform::from_xyz(0., -0.48, 0.)));
})
.insert(ImpulseJoint::new(module_entity, joint))
.insert(ExternalForce::default())
@@ 2025,10 1989,7 @@ fn player_input_update(
let thruster_pos_cast =
rot2d(thruster_pos_uncast, rot) + transform.translation.xy();
let thruster_force = force_multiplier * HEARTY_THRUSTER_FORCE;
- let thruster_vec = vec2(
- -thruster_force * rot.sin(),
- thruster_force * rot.cos(),
- );
+ let thruster_vec = vec2(-thruster_force * rot.sin(), thruster_force * rot.cos());
let thruster_force = ExternalForce::at_point(
thruster_vec,
thruster_pos_cast,
@@ 2076,10 2037,7 @@ fn search_thrusters(
}
if input.up && 3. * PI / 4. < relative_angle && relative_angle < 5. * PI / 4. {
let thruster_force = ExternalForce::at_point(
- Vec2::new(
- -force_mult * angle.sin(),
- force_mult * angle.cos(),
- ),
+ Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()),
transform.translation.xy(),
transform.translation.xy(),
);
@@ 2091,10 2049,7 @@ fn search_thrusters(
|| (7. * PI / 4. < relative_angle && relative_angle < 2. * PI))
{
let thruster_force = ExternalForce::at_point(
- Vec2::new(
- -force_mult * angle.sin(),
- force_mult * angle.cos(),
- ),
+ Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()),
transform.translation.xy(),
transform.translation.xy(),
);
@@ 2107,10 2062,7 @@ fn search_thrusters(
&& relative_pos.x > 0.48
{
let thruster_force = ExternalForce::at_point(
- Vec2::new(
- -force_mult * angle.sin(),
- force_mult * angle.cos(),
- ),
+ Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()),
transform.translation.xy(),
transform.translation.xy(),
);
@@ 2122,10 2074,7 @@ fn search_thrusters(
&& relative_pos.x < -0.48
{
let thruster_force = ExternalForce::at_point(
- Vec2::new(
- -force_mult * angle.sin(),
- force_mult * angle.cos(),
- ),
+ Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()),
transform.translation.xy(),
transform.translation.xy(),
);
@@ 2135,10 2084,7 @@ fn search_thrusters(
if PI / 4. < relative_angle && relative_angle < 3. * PI / 4. {
if relative_pos.y < -0.48 {
let thruster_force = ExternalForce::at_point(
- Vec2::new(
- -force_mult * angle.sin(),
- force_mult * angle.cos(),
- ),
+ Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()),
transform.translation.xy(),
transform.translation.xy(),
);
@@ 2147,10 2093,7 @@ fn search_thrusters(
}
if -0.48 < relative_pos.y && relative_pos.y < 0.48 {
let thruster_force = ExternalForce::at_point(
- Vec2::new(
- -force_mult * angle.sin(),
- force_mult * angle.cos(),
- ),
+ Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()),
transform.translation.xy(),
transform.translation.xy(),
);
@@ 2161,10 2104,7 @@ fn search_thrusters(
if 5. * PI / 4. < relative_angle && relative_angle < 7. * PI / 4. {
if relative_pos.y > 0.48 {
let thruster_force = ExternalForce::at_point(
- Vec2::new(
- -force_mult * angle.sin(),
- force_mult * angle.cos(),
- ),
+ Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()),
transform.translation.xy(),
transform.translation.xy(),
);
@@ 2173,10 2113,7 @@ fn search_thrusters(
}
if -0.48 < relative_pos.y && relative_pos.y < 0.48 {
let thruster_force = ExternalForce::at_point(
- Vec2::new(
- -force_mult * angle.sin(),
- force_mult * angle.cos(),
- ),
+ Vec2::new(-force_mult * angle.sin(), force_mult * angle.cos()),
transform.translation.xy(),
transform.translation.xy(),
);