# Objective Fixes #16104 ## Solution I removed all instances of `:?` and put them back one by one where it caused an error. I removed some bevy_utils helper functions that were only used in 2 places and don't add value. See: #11478 ## Testing CI should catch the mistakes ## Migration Guide `bevy::utils::{dbg,info,warn,error}` were removed. Use `bevy::utils::tracing::{debug,info,warn,error}` instead. --------- Co-authored-by: SpecificProtagonist <vincentjunge@posteo.net>
		
			
				
	
	
		
			61 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
//! Iterates and prints gamepad input and connection events.
 | 
						|
 | 
						|
use bevy::{
 | 
						|
    input::gamepad::{
 | 
						|
        GamepadAxisChangedEvent, GamepadButtonChangedEvent, GamepadButtonStateChangedEvent,
 | 
						|
        GamepadConnectionEvent, GamepadEvent,
 | 
						|
    },
 | 
						|
    prelude::*,
 | 
						|
};
 | 
						|
 | 
						|
fn main() {
 | 
						|
    App::new()
 | 
						|
        .add_plugins(DefaultPlugins)
 | 
						|
        .add_systems(Update, (gamepad_events, gamepad_ordered_events))
 | 
						|
        .run();
 | 
						|
}
 | 
						|
 | 
						|
fn gamepad_events(
 | 
						|
    mut connection_events: EventReader<GamepadConnectionEvent>,
 | 
						|
    // Handles the continuous measure of an axis, equivalent to GamepadAxes::get.
 | 
						|
    mut axis_changed_events: EventReader<GamepadAxisChangedEvent>,
 | 
						|
    // Handles the continuous measure of how far a button has been pressed down, equivalent to `GamepadButtons::get`.
 | 
						|
    mut button_changed_events: EventReader<GamepadButtonChangedEvent>,
 | 
						|
    // Handles the boolean measure of whether a button is considered pressed or unpressed, as
 | 
						|
    // defined by the thresholds in `GamepadSettings::button_settings`.
 | 
						|
    // When the threshold is crossed and the button state changes, this event is emitted.
 | 
						|
    mut button_input_events: EventReader<GamepadButtonStateChangedEvent>,
 | 
						|
) {
 | 
						|
    for connection_event in connection_events.read() {
 | 
						|
        info!("{:?}", connection_event);
 | 
						|
    }
 | 
						|
    for axis_changed_event in axis_changed_events.read() {
 | 
						|
        info!(
 | 
						|
            "{:?} of {} is changed to {}",
 | 
						|
            axis_changed_event.axis, axis_changed_event.entity, axis_changed_event.value
 | 
						|
        );
 | 
						|
    }
 | 
						|
    for button_changed_event in button_changed_events.read() {
 | 
						|
        info!(
 | 
						|
            "{:?} of {} is changed to {}",
 | 
						|
            button_changed_event.button, button_changed_event.entity, button_changed_event.value
 | 
						|
        );
 | 
						|
    }
 | 
						|
    for button_input_event in button_input_events.read() {
 | 
						|
        info!("{:?}", button_input_event);
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
// If you require in-frame relative event ordering, you can also read the `Gamepad` event
 | 
						|
// stream directly. For standard use-cases, reading the events individually or using the
 | 
						|
// `Input<T>` or `Axis<T>` resources is preferable.
 | 
						|
fn gamepad_ordered_events(mut gamepad_events: EventReader<GamepadEvent>) {
 | 
						|
    for gamepad_event in gamepad_events.read() {
 | 
						|
        match gamepad_event {
 | 
						|
            GamepadEvent::Connection(connection_event) => info!("{:?}", connection_event),
 | 
						|
            GamepadEvent::Button(button_event) => info!("{:?}", button_event),
 | 
						|
            GamepadEvent::Axis(axis_event) => info!("{:?}", axis_event),
 | 
						|
        }
 | 
						|
    }
 | 
						|
}
 |