From 472a238a1cbb1a63ef40858cb3bc7fb047c32be2 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 16 Jan 2025 21:48:56 +0200 Subject: [PATCH 1/4] chore: update hexlab version --- Cargo.lock | 58 ++++++++++++++++++++++++++++++++++++------ Cargo.toml | 2 +- justfile | 2 +- src/maze/components.rs | 8 ------ 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a820783..42968c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1409,7 +1409,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "shlex", "syn", ] @@ -1813,7 +1813,7 @@ dependencies = [ "log", "rangemap", "rayon", - "rustc-hash", + "rustc-hash 1.1.0", "rustybuzz", "self_cell", "swash", @@ -1925,6 +1925,18 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +[[package]] +name = "deprecate-until" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a3767f826efbbe5a5ae093920b58b43b01734202be697e1354914e862e8e704" +dependencies = [ + "proc-macro2", + "quote", + "semver", + "syn", +] + [[package]] name = "derive_more" version = "1.0.0" @@ -2644,15 +2656,16 @@ checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df" [[package]] name = "hexlab" -version = "0.5.3" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d2fbc6c41965686841aa5ea0e1af448730d0902274e49251c7d1fb7c78fffb9" +checksum = "e247b21d6885136e4a910e1e6fac755d8dc56112c40ebf1062582f0644d62c62" dependencies = [ "bevy", "bevy_reflect", "bevy_utils", "glam", "hexx", + "pathfinding", "rand", "thiserror 2.0.6", ] @@ -2894,6 +2907,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "integer-sqrt" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "276ec31bcb4a9ee45f58bec6f9ec700ae4cf4f4f8f2fa7e06cb406bd5ffdd770" +dependencies = [ + "num-traits", +] + [[package]] name = "io-kit-sys" version = "0.4.1" @@ -3228,7 +3250,7 @@ dependencies = [ "indexmap", "log", "pp-rs", - "rustc-hash", + "rustc-hash 1.1.0", "spirv", "termcolor", "thiserror 1.0.69", @@ -3249,7 +3271,7 @@ dependencies = [ "once_cell", "regex", "regex-syntax 0.8.5", - "rustc-hash", + "rustc-hash 1.1.0", "thiserror 1.0.69", "tracing", "unicode-ident", @@ -3763,6 +3785,20 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "pathfinding" +version = "4.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301ad6aa19104eeb9af172b3d6a4ab8a5ea26234890baf2fcb1cbbc3f05f674b" +dependencies = [ + "deprecate-until", + "indexmap", + "integer-sqrt", + "num-traits", + "rustc-hash 2.1.0", + "thiserror 2.0.6", +] + [[package]] name = "percent-encoding" version = "2.3.1" @@ -4184,6 +4220,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" + [[package]] name = "rustc_version" version = "0.4.1" @@ -5224,7 +5266,7 @@ dependencies = [ "parking_lot", "profiling", "raw-window-handle", - "rustc-hash", + "rustc-hash 1.1.0", "smallvec", "thiserror 1.0.69", "wgpu-hal", @@ -5266,7 +5308,7 @@ dependencies = [ "range-alloc", "raw-window-handle", "renderdoc-sys", - "rustc-hash", + "rustc-hash 1.1.0", "smallvec", "thiserror 1.0.69", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index fecb335..234db65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ tracing = { version = "0.1", features = [ "release_max_level_warn", ] } hexx = { version = "0.19", features = ["bevy_reflect", "grid"] } -hexlab = { version = "0.5", features = ["bevy"] } +hexlab = { version = "0.6", features = ["bevy", "pathfinding"] } bevy-inspector-egui = { version = "0.28", optional = true } bevy_egui = { version = "0.31", optional = true } thiserror = "2.0" diff --git a/justfile b/justfile index eea0280..49c0731 100644 --- a/justfile +++ b/justfile @@ -8,7 +8,7 @@ native-dev: # Run native release native-release: - RUSTC_WRAPPER=sccache cargo run --release --no-default-features + RUSTC_WRAPPER=sccache cargo run --release --no-default-features # Run web dev web-dev: diff --git a/src/maze/components.rs b/src/maze/components.rs index 48cd62b..349bd62 100644 --- a/src/maze/components.rs +++ b/src/maze/components.rs @@ -95,14 +95,6 @@ impl MazeConfig { } } -// TO -// 3928551514041614914 -// (4, 0) - -// FROM -// 7365371276044996661 -// () - impl Default for MazeConfig { fn default() -> Self { Self::new( From d2dd57bcff6a0e911ba5f8892139211eb8d15ba6 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 16 Jan 2025 23:26:37 +0200 Subject: [PATCH 2/4] feat: add game stats --- src/constants.rs | 3 +++ src/hint/mod.rs | 4 +++- src/lib.rs | 2 ++ src/screens/gameplay.rs | 8 +++++--- src/stats/components.rs | 9 +++++++++ src/stats/mod.rs | 20 +++++++++++++++++++ src/stats/resources.rs | 21 ++++++++++++++++++++ src/stats/stats.rs | 22 +++++++++++++++++++++ src/stats/systems/mod.rs | 16 ++++++++++++++++ src/stats/systems/score.rs | 39 ++++++++++++++++++++++++++++++++++++++ src/stats/systems/setup.rs | 17 +++++++++++++++++ src/theme/mod.rs | 2 +- src/theme/widgets.rs | 16 ++++++++++++++++ 13 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 src/stats/components.rs create mode 100644 src/stats/mod.rs create mode 100644 src/stats/resources.rs create mode 100644 src/stats/stats.rs create mode 100644 src/stats/systems/mod.rs create mode 100644 src/stats/systems/score.rs create mode 100644 src/stats/systems/setup.rs diff --git a/src/constants.rs b/src/constants.rs index c79e214..a31d151 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -3,3 +3,6 @@ pub const WALL_OVERLAP_MODIFIER: f32 = 1.25; pub const FLOOR_Y_OFFSET: u8 = 200; pub const MOVEMENT_COOLDOWN: f32 = 1.0; // one second cooldown pub const TITLE: &str = "Maze Ascension: The Labyrinth of Echoes"; + +pub const FLOOR_SCORE_MULTIPLIER: f32 = 100.; +pub const TIME_SCORE_MULTIPLIER: f32 = 10.0; diff --git a/src/hint/mod.rs b/src/hint/mod.rs index 371febd..08ea313 100644 --- a/src/hint/mod.rs +++ b/src/hint/mod.rs @@ -3,9 +3,11 @@ pub mod components; mod systems; use bevy::{ecs::system::RunSystemOnce, prelude::*}; +use components::IdleTimer; pub(super) fn plugin(app: &mut App) { - app.add_plugins(systems::plugin); + app.register_type::() + .add_plugins(systems::plugin); } pub fn spawn_hint_command(world: &mut World) { diff --git a/src/lib.rs b/src/lib.rs index 10921fe..e634cde 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,7 @@ pub mod hint; pub mod maze; pub mod player; pub mod screens; +pub mod stats; pub mod theme; use bevy::{ @@ -69,6 +70,7 @@ impl Plugin for AppPlugin { floor::plugin, player::plugin, hint::plugin, + stats::plugin, )); // Enable dev tools for dev builds. diff --git a/src/screens/gameplay.rs b/src/screens/gameplay.rs index 7374933..b41de50 100644 --- a/src/screens/gameplay.rs +++ b/src/screens/gameplay.rs @@ -1,8 +1,9 @@ //! The screen state for the main gameplay. -use crate::player::spawn_player_command; -use crate::screens::Screen; -use crate::{hint::spawn_hint_command, maze::spawn_level_command}; +use crate::{ + hint::spawn_hint_command, maze::spawn_level_command, player::spawn_player_command, + screens::Screen, stats::spawn_stats_command, +}; use bevy::{input::common_conditions::input_just_pressed, prelude::*}; @@ -13,6 +14,7 @@ pub(super) fn plugin(app: &mut App) { spawn_level_command, spawn_player_command, spawn_hint_command, + spawn_stats_command, ) .chain(), ); diff --git a/src/stats/components.rs b/src/stats/components.rs new file mode 100644 index 0000000..8aad2aa --- /dev/null +++ b/src/stats/components.rs @@ -0,0 +1,9 @@ +use bevy::prelude::*; + +#[derive(Debug, Reflect, Component, Deref, DerefMut)] +#[reflect(Component)] +pub struct Score(pub usize); + +#[derive(Debug, Reflect, Component)] +#[reflect(Component)] +pub struct StatsText; diff --git a/src/stats/mod.rs b/src/stats/mod.rs new file mode 100644 index 0000000..76c2c8a --- /dev/null +++ b/src/stats/mod.rs @@ -0,0 +1,20 @@ +pub mod components; +pub mod resources; +pub mod stats; +mod systems; + +use bevy::{ecs::system::RunSystemOnce, prelude::*}; +use components::Score; +use resources::{FloorTimer, GameTimer}; + +pub(super) fn plugin(app: &mut App) { + app.register_type::() + .init_resource::() + .init_resource::() + .insert_resource(FloorTimer(Timer::from_seconds(0.0, TimerMode::Once))) + .add_plugins(systems::plugin); +} + +pub fn spawn_stats_command(world: &mut World) { + let _ = world.run_system_once(systems::setup::setup); +} diff --git a/src/stats/resources.rs b/src/stats/resources.rs new file mode 100644 index 0000000..5c7123f --- /dev/null +++ b/src/stats/resources.rs @@ -0,0 +1,21 @@ +use bevy::prelude::*; + +#[derive(Debug, Reflect, Resource, Deref, DerefMut)] +#[reflect(Resource)] +pub struct GameTimer(pub Timer); + +#[derive(Debug, Reflect, Resource, Deref, DerefMut)] +#[reflect(Resource)] +pub struct FloorTimer(pub Timer); + +impl Default for GameTimer { + fn default() -> Self { + Self(Timer::from_seconds(0.0, TimerMode::Once)) + } +} + +impl Default for FloorTimer { + fn default() -> Self { + Self(Timer::from_seconds(0.0, TimerMode::Once)) + } +} diff --git a/src/stats/stats.rs b/src/stats/stats.rs new file mode 100644 index 0000000..95289b1 --- /dev/null +++ b/src/stats/stats.rs @@ -0,0 +1,22 @@ +use bevy::prelude::*; + +pub trait StatsContainer { + fn ui_stats(&mut self) -> EntityCommands; +} + +impl StatsContainer for Commands<'_, '_> { + fn ui_stats(&mut self) -> EntityCommands { + self.spawn(( + Name::new("Stats Root"), + Node { + position_type: PositionType::Absolute, + top: Val::Px(10.), + right: Val::Px(10.), + row_gap: Val::Px(8.), + align_items: AlignItems::End, + flex_direction: FlexDirection::Column, + ..default() + }, + )) + } +} diff --git a/src/stats/systems/mod.rs b/src/stats/systems/mod.rs new file mode 100644 index 0000000..f469cfc --- /dev/null +++ b/src/stats/systems/mod.rs @@ -0,0 +1,16 @@ +mod score; +pub mod setup; + +use bevy::prelude::*; +use score::{update_score, update_score_display}; + +use crate::screens::Screen; + +pub(super) fn plugin(app: &mut App) { + app.add_systems( + Update, + (update_score, update_score_display) + .chain() + .run_if(in_state(Screen::Gameplay)), + ); +} diff --git a/src/stats/systems/score.rs b/src/stats/systems/score.rs new file mode 100644 index 0000000..537b419 --- /dev/null +++ b/src/stats/systems/score.rs @@ -0,0 +1,39 @@ +use bevy::prelude::*; + +use crate::{ + constants::{FLOOR_SCORE_MULTIPLIER, TIME_SCORE_MULTIPLIER}, + floor::components::{CurrentFloor, Floor}, + stats::{components::Score, resources::GameTimer}, +}; + +pub fn update_score( + mut score_query: Query<&mut Score>, + mut game_timer: ResMut, + floor_query: Query<&Floor, With>, + time: Res