pub fn debug_system(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut debug_state: ResMut<DebugState>,
    keyboard_input: Res<Input<KeyCode>>,
    mut debug_events: EventWriter<ToggleDebugEvent>,
) {
    if keyboard_input.just_pressed(KeyCode::D) {
        debug!("toggling debug ...");

        debug_state.enabled = !debug_state.enabled;

        if debug_state.enabled {
            debug_state.fps_text_entity = Some(
                commands
                    .spawn_bundle(TextBundle {
                        style: Style {
                            align_self: AlignSelf::FlexEnd,
                            position_type: PositionType::Absolute,
                            position: Rect {
                                top: Val::Px(5.0),
                                left: Val::Px(15.0),
                                ..Default::default()
                            },
                            ..Default::default()
                        },
                        text: Text::with_section(
                            "fps",
                            TextStyle {
                                font: asset_server.load("fonts/Roboto-Regular.ttf"),
                                font_size: 30.0,
                                color: Color::WHITE,
                            },
                            TextAlignment::default(),
                        ),
                        ..Default::default()
                    })
                    .insert(FpsText)
                    .id(),
            );
        } else {
            if let Some(fps_text) = debug_state.fps_text_entity.take() {
                commands.entity(fps_text).despawn_recursive();
            }
        }

        debug_events.send(ToggleDebugEvent);
    }
}
/// Toggles debug on input
///
/// Sends the ToggleDebugEvent
Toggles debug on input
Sends the ToggleDebugEvent
Toggles debug on input Sends the ToggleDebugEvent
pub fn debug_system(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut debug_state: ResMut<DebugState>,
    keyboard_input: Res<Input<KeyCode>>,
    mut debug_events: EventWriter<ToggleDebugEvent>,
) {
    if keyboard_input.just_pressed(KeyCode::D) {
        debug!("toggling debug ...");
        debug_state.enabled = !debug_state.enabled;
        if debug_state.enabled {
            debug_state.fps_text_entity = Some(
                commands
                    .spawn_bundle(TextBundle {
                        style: Style {
                            align_self: AlignSelf::FlexEnd,
                            position_type: PositionType::Absolute,
                            position: Rect {
                                top: Val::Px(5.0),
                                left: Val::Px(15.0),
                                ..Default::default()
                            },
                            ..Default::default()
                        },
                        text: Text::with_section(
                            "fps",
                            TextStyle {
                                font: asset_server.load("fonts/Roboto-Regular.ttf"),
                                font_size: 30.0,
                                color: Color::WHITE,
                            },
                            TextAlignment::default(),
                        ),
                        ..Default::default()
                    })
                    .insert(FpsText)
                    .id(),
            );
        } else {
            if let Some(fps_text) = debug_state.fps_text_entity.take() {
                commands.entity(fps_text).despawn_recursive();
            }
        }
        debug_events.send(ToggleDebugEvent);
    }
}
pub fn debug_system ( mut commands : Commands , asset_server : Res < AssetServer > , mut debug_state : ResMut < DebugState > , keyboard_input : Res < Input < KeyCode > > , mut debug_events : EventWriter < ToggleDebugEvent > , ) { if keyboard_input . just_pressed ( KeyCode :: D ) { debug ! ( " " ) ; debug_state . enabled = ! debug_state . enabled ; if debug_state . enabled { debug_state . fps_text_entity = Some ( commands . spawn_bundle ( TextBundle { style : Style { align_self : AlignSelf :: FlexEnd , position_type : PositionType :: Absolute , position : Rect { top : Val :: Px ( 5.0 ) , left : Val :: Px ( 15.0 ) , .. Default :: default ( ) } , .. Default :: default ( ) } , text : Text :: with_section ( " " , TextStyle { font : asset_server . load ( " " ) , font_size : 30.0 , color : Color :: WHITE , } , TextAlignment :: default ( ) , ) , .. Default :: default ( ) } ) . insert ( FpsText ) . id ( ) , ) ; } else { if let Some ( fps_text ) = debug_state . fps_text_entity . take ( ) { commands . entity ( fps_text ) . despawn_recursive ( ) ; } } debug_events . send ( ToggleDebugEvent ) ; } }
Toggles debug on input
Sends the ToggleDebugEvent
Toggles debug on input Sends the ToggleDebugEvent
commands
Commands
asset_server
Res<AssetServer>
debug_state
ResMut<DebugState>
keyboard_input
Res<Input<KeyCode>>
debug_events
EventWriter<ToggleDebugEvent>
commands
Commands
asset_server
Res<AssetServer>
debug_state
ResMut<DebugState>
keyboard_input
Res<Input<KeyCode>>
debug_events
EventWriter<ToggleDebugEvent>