cleanup
This commit is contained in:
parent
96d1169eb9
commit
f13fc7167d
69
src/actor.rs
69
src/actor.rs
|
@ -208,65 +208,60 @@ pub fn handle_input(
|
||||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
settings: ResMut<settings::Settings>,
|
settings: ResMut<settings::Settings>,
|
||||||
q_talker: Query<(&chat::Talker, &Transform), (Without<actor::Player>, Without<Camera>)>,
|
q_talker: Query<(&chat::Talker, &Transform), (Without<actor::Player>, Without<Camera>)>,
|
||||||
mut player: Query<(Entity, &mut Actor, &mut Transform), (With<actor::Player>, Without<Camera>)>,
|
mut player: Query<(Entity, &mut Transform), (With<actor::Player>, Without<Camera>)>,
|
||||||
q_camera: Query<&Transform, With<Camera>>,
|
q_camera: Query<&Transform, With<Camera>>,
|
||||||
mut q_vehicles: Query<(Entity, &mut Visibility, &Transform), (With<actor::Vehicle>, Without<actor::Player>, Without<Camera>)>,
|
mut q_vehicles: Query<(Entity, &mut Visibility, &Transform), (With<actor::Vehicle>, Without<actor::Player>, Without<Camera>)>,
|
||||||
mut ew_conv: EventWriter<chat::StartConversationEvent>,
|
mut ew_conv: EventWriter<chat::StartConversationEvent>,
|
||||||
mut ew_vehicle: EventWriter<VehicleEnterExitEvent>,
|
mut ew_vehicle: EventWriter<VehicleEnterExitEvent>,
|
||||||
q_player_drives: Query<Entity, With<PlayerDrivesThis>>,
|
q_player_drives: Query<Entity, With<PlayerDrivesThis>>,
|
||||||
) {
|
) {
|
||||||
if q_camera.is_empty() {
|
if q_camera.is_empty() || player.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let camtrans = q_camera.get_single().unwrap();
|
let camtrans = q_camera.get_single().unwrap();
|
||||||
|
let (player_entity, player) = player.get_single().unwrap();
|
||||||
|
|
||||||
if keyboard_input.just_pressed(settings.key_interact) {
|
if keyboard_input.just_pressed(settings.key_interact) {
|
||||||
// Talking to people
|
// Talking to people
|
||||||
if let Ok((_player_entity, _player_actor, _player)) = player.get_single() {
|
let objects: Vec<(chat::Talker, &Transform)> = q_talker
|
||||||
let objects: Vec<(chat::Talker, &Transform)> = q_talker
|
.iter()
|
||||||
.iter()
|
.map(|(talker, transform)| (talker.clone(), transform))
|
||||||
.map(|(talker, transform)| (talker.clone(), transform))
|
.collect();
|
||||||
.collect();
|
// TODO: replace Transform.translation with Position
|
||||||
// TODO: replace Transform.translation with Position
|
if let (Some(talker), dist) = camera::find_closest_target::<chat::Talker>(objects, camtrans) {
|
||||||
if let (Some(talker), dist) = camera::find_closest_target::<chat::Talker>(objects, camtrans) {
|
if dist <= MAX_TRANSMISSION_DISTANCE {
|
||||||
if dist <= MAX_TRANSMISSION_DISTANCE {
|
ew_conv.send(chat::StartConversationEvent{talker: talker.clone()});
|
||||||
ew_conv.send(chat::StartConversationEvent{talker: talker.clone()});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Entering Vehicles
|
// Entering Vehicles
|
||||||
if q_player_drives.is_empty() {
|
if q_player_drives.is_empty() {
|
||||||
if let Ok((player_entity, _player_actor, player)) = player.get_single_mut() {
|
for (vehicle_entity, _visibility, vehicle_transform) in q_vehicles.iter_mut() {
|
||||||
for (vehicle_entity, _visibility, vehicle_transform) in q_vehicles.iter_mut() {
|
if vehicle_transform.translation.distance_squared(player.translation) <= MAX_INTERACT_DISTANCE * MAX_INTERACT_DISTANCE {
|
||||||
if vehicle_transform.translation.distance_squared(player.translation) <= MAX_INTERACT_DISTANCE * MAX_INTERACT_DISTANCE {
|
commands.entity(vehicle_entity).insert(ActorVehicleBeingEntered);
|
||||||
commands.entity(vehicle_entity).insert(ActorVehicleBeingEntered);
|
commands.entity(player_entity).insert(ActorEnteringVehicle);
|
||||||
commands.entity(player_entity).insert(ActorEnteringVehicle);
|
ew_vehicle.send(VehicleEnterExitEvent{
|
||||||
ew_vehicle.send(VehicleEnterExitEvent{
|
vehicle: vehicle_entity,
|
||||||
vehicle: vehicle_entity,
|
driver: player_entity,
|
||||||
driver: player_entity,
|
is_entering: q_player_drives.is_empty(),
|
||||||
is_entering: q_player_drives.is_empty(),
|
is_player: true,
|
||||||
is_player: true,
|
});
|
||||||
});
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if keyboard_input.just_pressed(settings.key_vehicle) {
|
else if keyboard_input.just_pressed(settings.key_vehicle) {
|
||||||
// Exiting Vehicles
|
// Exiting Vehicles
|
||||||
if let Ok((player_entity, _player_actor, _player)) = player.get_single_mut() {
|
for vehicle_entity in &q_player_drives {
|
||||||
for vehicle_entity in &q_player_drives {
|
commands.entity(vehicle_entity).insert(ActorVehicleBeingEntered);
|
||||||
commands.entity(vehicle_entity).insert(ActorVehicleBeingEntered);
|
commands.entity(player_entity).insert(ActorEnteringVehicle);
|
||||||
commands.entity(player_entity).insert(ActorEnteringVehicle);
|
ew_vehicle.send(VehicleEnterExitEvent{
|
||||||
ew_vehicle.send(VehicleEnterExitEvent{
|
vehicle: vehicle_entity,
|
||||||
vehicle: vehicle_entity,
|
driver: player_entity,
|
||||||
driver: player_entity,
|
is_entering: false,
|
||||||
is_entering: false,
|
is_player: true,
|
||||||
is_player: true,
|
});
|
||||||
});
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue