From e7dac4c49a3aee9a3a2a11e4e08abadfa02616f7 Mon Sep 17 00:00:00 2001 From: Louis Capitanchik <contact@louiscap.co> Date: Sat, 20 Aug 2022 22:19:01 +0100 Subject: [PATCH] Debug last pressed button --- .gitlab-ci.yml | 8 ++-- Cargo.lock | 1 + assets/jamsplash.png | 4 +- assets/kenney_blocks.ttf | 3 ++ game_core/Cargo.toml | 1 + game_core/src/assets/startup.rs | 1 + game_core/src/main.rs | 1 + game_core/src/system/debug.rs | 63 +++++++++++++++++++++++++++++++ game_core/src/system/mod.rs | 1 + game_core/src/system/resources.rs | 2 +- game_core/src/system/utilities.rs | 4 ++ 11 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 assets/kenney_blocks.ttf create mode 100644 game_core/src/system/debug.rs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 315d11e..d45c4a4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,7 @@ build-windows: artifacts: expire_in: 1 day paths: - - target/x86_64-pc-windows-gnu/release/${BINARY_NAME}.exe + - target/x86_64-pc-windows-gnu/release/game_core.exe only: - trunk @@ -48,7 +48,7 @@ build-linux: artifacts: expire_in: 1 day paths: - - target/x86_64-unknown-linux-gnu/release/${BINARY_NAME} + - target/x86_64-unknown-linux-gnu/release/game_core only: - trunk @@ -73,7 +73,7 @@ build-arm64: artifacts: expire_in: 1 day paths: - - target/aarch64-unknown-linux-gnu/release/${BINARY_NAME} + - target/aarch64-unknown-linux-gnu/release/game_core only: - trunk @@ -100,7 +100,7 @@ build-web: artifacts: expire_in: 1 day paths: - - ${BINARY_FOLDER}/dist/ + - game_core/dist/ only: - trunk diff --git a/Cargo.lock b/Cargo.lock index c6a7a85..4ba8122 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -415,6 +415,7 @@ dependencies = [ "bevy_ecs", "bevy_math", "bevy_utils", + "serde", ] [[package]] diff --git a/assets/jamsplash.png b/assets/jamsplash.png index 8a600a3..f1dad4f 100644 --- a/assets/jamsplash.png +++ b/assets/jamsplash.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9d9461d43ff1217e0911bb400582db3e300ff0c0365572da4192728d44d251db -size 112087 +oid sha256:8b77c446b6fcd749257c724fae63af953f424930caedec8e32b3a8f498ad2c21 +size 112360 diff --git a/assets/kenney_blocks.ttf b/assets/kenney_blocks.ttf new file mode 100644 index 0000000..059ebf3 --- /dev/null +++ b/assets/kenney_blocks.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bb2f9ba39f4fa7d8dbb3d3d1af05c2517b848f278bbe4f7ab53e518f2429bad5 +size 30508 diff --git a/game_core/Cargo.toml b/game_core/Cargo.toml index 02656c7..664ed9c 100644 --- a/game_core/Cargo.toml +++ b/game_core/Cargo.toml @@ -35,4 +35,5 @@ features = [ "png", "hdr", "x11", + "serialize", ] diff --git a/game_core/src/assets/startup.rs b/game_core/src/assets/startup.rs index 7013a56..d415476 100644 --- a/game_core/src/assets/startup.rs +++ b/game_core/src/assets/startup.rs @@ -14,6 +14,7 @@ pub fn start_preload_resources(mut commands: Commands) { pub fn start_load_resources(mut loader: AssetTypeLoader) { loader.load_images(&[("jamsplash.png", "splash")]); loader.load_audio(&[("splash_sting.mp3", "splash_sting")]); + loader.load_font(&[("kenney_blocks.ttf", "blocks")]); } pub fn check_load_resources(mut commands: Commands, loader: AssetTypeLoader) { diff --git a/game_core/src/main.rs b/game_core/src/main.rs index f8a6d3a..9c372ea 100644 --- a/game_core/src/main.rs +++ b/game_core/src/main.rs @@ -18,5 +18,6 @@ fn main() { game_core::multiplayer::OutgoingEvent, game_core::multiplayer::IncomingEvent, >::new()) + .add_plugin(game_core::system::debug::DebugTextBundle) .run(); } diff --git a/game_core/src/system/debug.rs b/game_core/src/system/debug.rs new file mode 100644 index 0000000..6e118c9 --- /dev/null +++ b/game_core/src/system/debug.rs @@ -0,0 +1,63 @@ +use bevy::prelude::*; +use iyes_loopless::prelude::AppLooplessStateExt; + +use crate::assets::AssetHandles; +use crate::system::flow::AppState; +use crate::system::utilities::TRANSPARENT; + +#[derive(Component)] +pub struct Character; + +pub fn create_debug_text(mut commands: Commands, assets: Res<AssetHandles>) { + commands + .spawn_bundle(NodeBundle { + style: Style { + position_type: PositionType::Absolute, + size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + ..Default::default() + }, + color: TRANSPARENT.into(), + ..Default::default() + }) + .with_children(|children| { + children + .spawn_bundle(TextBundle { + text: Text::from_section( + " ", + TextStyle { + color: Color::WHITE, + font_size: 48.0, + font: assets.font("blocks"), + }, + ), + ..Default::default() + }) + .insert(Character); + }); +} + +pub fn set_last_character( + input: Res<Input<KeyCode>>, + mut query: Query<&mut Text, With<Character>>, +) { + let last_key = input + .get_just_released() + .map(|key| format!("{:?}", key)) + .reduce(|acc, current| format!("{}, {}", acc, current)); + + if let Some(last_key) = last_key { + for mut text in &mut query { + text.sections[0].value = last_key.clone(); + } + } +} + +pub struct DebugTextBundle; +impl Plugin for DebugTextBundle { + fn build(&self, app: &mut App) { + app.add_enter_system(AppState::Menu, create_debug_text) + .add_system(set_last_character); + } +} diff --git a/game_core/src/system/mod.rs b/game_core/src/system/mod.rs index 309ab32..4e12c88 100644 --- a/game_core/src/system/mod.rs +++ b/game_core/src/system/mod.rs @@ -1,4 +1,5 @@ pub mod camera; +pub mod debug; pub mod flow; pub mod load_config; pub mod resources; diff --git a/game_core/src/system/resources.rs b/game_core/src/system/resources.rs index 7798b37..4973279 100644 --- a/game_core/src/system/resources.rs +++ b/game_core/src/system/resources.rs @@ -19,7 +19,7 @@ impl Plugin for DefaultResourcesPlugin { } else { WindowMode::Windowed }, - title: String::from("Bevy 2D Template"), + title: String::from("Realm Fantastique"), present_mode: PresentMode::AutoNoVsync, ..Default::default() }) diff --git a/game_core/src/system/utilities.rs b/game_core/src/system/utilities.rs index 0244a87..6a0fcab 100644 --- a/game_core/src/system/utilities.rs +++ b/game_core/src/system/utilities.rs @@ -1,3 +1,5 @@ +use bevy::prelude::Color; + #[inline] pub fn f32_max(a: f32, b: f32) -> f32 { if a > b { @@ -30,3 +32,5 @@ pub fn f32_min_mag(a: f32, b: f32) -> f32 { b.abs() } } + +pub const TRANSPARENT: Color = Color::rgba(0.0, 0.0, 0.0, 0.0); -- GitLab