This commit is contained in:
yuni 2024-04-05 20:01:44 +02:00
parent 96d1169eb9
commit f13fc7167d

View file

@ -208,21 +208,21 @@ 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))
@ -233,10 +233,8 @@ pub fn handle_input(
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);
@ -252,10 +250,8 @@ pub fn handle_input(
} }
} }
} }
}
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);
@ -269,7 +265,6 @@ pub fn handle_input(
} }
} }
} }
}
pub fn handle_vehicle_enter_exit( pub fn handle_vehicle_enter_exit(
mut commands: Commands, mut commands: Commands,