diff --git a/assets/fonts/FiraSans-Bold.ttf b/assets/fonts/FiraSans-Bold.ttf new file mode 100644 index 0000000..e3593fb Binary files /dev/null and b/assets/fonts/FiraSans-Bold.ttf differ diff --git a/src/debug_view.rs b/src/debug_view.rs new file mode 100644 index 0000000..8daadce --- /dev/null +++ b/src/debug_view.rs @@ -0,0 +1,61 @@ +use bevy::prelude::*; + +const DEBUG_PINK: Color = Color::rgb(0.8, 0.2, 0.2); + +#[derive(Component)] +struct DebugView; + +pub struct DebugViewPlugin; + +impl Plugin for DebugViewPlugin { + fn build(&self, app: &mut App) { + info!("setting up the DebugView plugin"); + app + .add_startup_system(init_view) + .add_system(debug_input); + } +} + +fn init_view(mut commands: Commands, asset_server: Res) { + let mut root = commands.spawn(); + + root.insert(DebugView); + root.insert_bundle(NodeBundle{ + visibility: Visibility{is_visible: false}, + style: Style{ + size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), + ..default() + }, + color: Color::NONE.into(), + ..default() + }); + + root.with_children(|parent| { + let textStyle = TextStyle{ + font: asset_server.load("fonts/FiraSans-Bold.ttf"), + font_size: 20.0, + color: DEBUG_PINK, + }; + let textBundle = TextBundle::from_section("fart", textStyle) + .with_text_alignment(TextAlignment::TOP_RIGHT) + .with_style(Style{ + align_self: AlignSelf::FlexEnd, + position_type: PositionType::Absolute, + position: UiRect { + top: Val::Px(5.0), + right: Val::Px(5.0), + ..default() + }, + ..default() + }); + parent.spawn_bundle(textBundle); + }); +} + +fn debug_input(now: Res>, mut query: Query<&mut Visibility, With>) { + let mut visibility = query.single_mut(); + + if now.just_pressed(KeyCode::F10) { + visibility.is_visible = !visibility.is_visible; + } +} diff --git a/src/main.rs b/src/main.rs index ce9fa95..1294fbe 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,13 @@ mod input; +mod debug_view; use bevy::{ input::{keyboard::KeyCode, Input}, prelude::*, }; -use input::{PlayerInput, ButtonState}; +use input::PlayerInput; +use debug_view::DebugViewPlugin; #[derive(Component)] struct Player; @@ -60,9 +62,6 @@ fn player_keyboard_input(now: Res>, mut input_state: ResMut>, mut debug_state: ResMut) { -} - fn player_movement( mut query: Query<&mut Transform, With>, input_state: Res, @@ -75,17 +74,18 @@ fn player_movement( if input_state.right.pressed { player_t.translation.x += tile.width as f32; } } -#[derive(Default, Debug)] -struct DebugView { - enabled: bool, -} - fn main() { App::new() + .insert_resource(bevy::log::LogSettings{ + // set to TRACE|DEBUG|INFO|WARN|ERROR to change log verbosity. + // INFO is the default level. + level: bevy::log::Level::INFO, + ..default() + }) .add_plugins(DefaultPlugins) + .add_plugin(DebugViewPlugin) .insert_resource(ClearColor(BACKGROUND_COLOR)) .insert_resource(PlayerInput::default()) - .insert_resource(DebugView::default()) .insert_resource(TileSize{width: TILE_WIDTH, height: TILE_HEIGHT}) .add_startup_system(setup) .add_system(player_keyboard_input)