diff --git a/src/features/input/mod.rs b/src/features/input/mod.rs index 41c7225..d2dd287 100644 --- a/src/features/input/mod.rs +++ b/src/features/input/mod.rs @@ -11,6 +11,7 @@ use bevy::window::PrimaryWindow; pub mod utils; +/// Handles user input for the game. pub struct InputPlugin; impl Plugin for InputPlugin { @@ -45,6 +46,7 @@ impl Plugin for InputPlugin { } } +/// Handles right-click movement input. fn move_click( mut move_messages: MessageWriter, mouse_btn: Res>, @@ -75,6 +77,7 @@ fn move_click( } } +/// Handles left-click interactions (tile selection, shovel). fn interact_click( mut tile_click_messages: MessageWriter, mouse_btn: Res>, @@ -174,6 +177,7 @@ fn interact_click( } } } +/// Handles debug interactions (shift + left click). fn debug_click( mouse_btn: Res>, keys: Res>, @@ -220,6 +224,7 @@ fn debug_click( } } +/// Pauses/resumes the phase timer on Space press. fn phase_timer_pause( mut pause_messages: MessageWriter, keys: Res>, @@ -229,12 +234,14 @@ fn phase_timer_pause( } } +/// Skips to the next phase on Enter press. fn next_phase(mut messages: MessageWriter, keys: Res>) { if keys.just_pressed(KeyCode::Enter) { messages.write(NextPhaseMessage); } } +/// Opens the shop on 'P' press. fn shop_keybind( keys: Res>, mut commands: Commands, @@ -254,6 +261,7 @@ fn shop_keybind( } } +/// Closes popups on Escape press. fn popup_keybind( mut close_popup_messages: MessageWriter, keys: Res>, diff --git a/src/features/input/utils.rs b/src/features/input/utils.rs index 7f38b6e..2cff5e1 100644 --- a/src/features/input/utils.rs +++ b/src/features/input/utils.rs @@ -1,6 +1,7 @@ use crate::prelude::*; use bevy::window::PrimaryWindow; +/// Converts mouse position to grid coordinates, respecting UI blocks. pub fn mouse_to_grid( window: Single<&Window, With>, camera: Single<(&Camera, &GlobalTransform), With>, diff --git a/src/features/pom/actions.rs b/src/features/pom/actions.rs index 3e22179..4b2c0d6 100644 --- a/src/features/pom/actions.rs +++ b/src/features/pom/actions.rs @@ -1,5 +1,6 @@ use crate::{features::phase::components::SessionTracker, prelude::*}; +/// Actions Pom can perform on tiles. #[derive(Clone, Debug, PartialEq)] pub enum InteractionAction { Plant(ItemType), diff --git a/src/features/pom/components.rs b/src/features/pom/components.rs index 5e9866a..d6a9243 100644 --- a/src/features/pom/components.rs +++ b/src/features/pom/components.rs @@ -2,20 +2,24 @@ use crate::features::pom::actions::InteractionAction; use crate::prelude::*; use std::collections::VecDeque; +/// Marker component for the main character. #[derive(Component)] pub struct Pom; +/// Current logical position on the grid. #[derive(Component, Serialize, Deserialize, Clone, Copy, Default)] pub struct GridPosition { pub x: u32, pub y: u32, } +/// Queue of grid positions to visit. #[derive(Component, Default)] pub struct PathQueue { pub steps: VecDeque<(u32, u32)>, } +/// Movement direction state for animation. #[derive(Component, Default)] pub enum MovingState { #[default] @@ -38,6 +42,7 @@ impl MovingState { } } +/// Target tile and action for pending interaction. #[derive(Component, Default)] pub struct InteractionTarget { pub target: Option<(u32, u32)>, diff --git a/src/features/pom/messages.rs b/src/features/pom/messages.rs index 58b2355..8afc36e 100644 --- a/src/features/pom/messages.rs +++ b/src/features/pom/messages.rs @@ -1,17 +1,20 @@ use crate::features::pom::actions::InteractionAction; use crate::prelude::*; +/// Request to move Pom to a specific tile. #[derive(Message)] pub struct MoveMessage { pub x: u32, pub y: u32, } +/// Notification that a move request was invalid. #[derive(Message)] pub struct InvalidMoveMessage { pub message: String, } +/// Request to start an interaction sequence. #[derive(Message)] pub struct InteractStartMessage { pub x: u32, @@ -19,6 +22,7 @@ pub struct InteractStartMessage { pub action: InteractionAction, } +/// Notification that a tile was clicked (requesting context menu). #[derive(Message)] pub struct TileClickMessage { pub x: u32, diff --git a/src/features/pom/mod.rs b/src/features/pom/mod.rs index ed55560..2eb2cdd 100644 --- a/src/features/pom/mod.rs +++ b/src/features/pom/mod.rs @@ -11,6 +11,7 @@ pub mod messages; pub mod ui; pub mod utils; +/// Plugin controlling the main character (Pom) behavior. pub struct PomPlugin; impl Plugin for PomPlugin { @@ -34,6 +35,7 @@ impl Plugin for PomPlugin { } } +/// Draws the path Pom will follow using gizmos. fn draw_path( mut gizmos: Gizmos, query: Query<(&Transform, &PathQueue), With>, @@ -65,6 +67,7 @@ fn draw_path( } } +/// Spawns the Pom character. fn setup(mut commands: Commands, asset_server: Res, config: Res) { commands.spawn(( Pom, @@ -87,12 +90,14 @@ fn setup(mut commands: Commands, asset_server: Res, config: Res>) { for pom_entity in pom_query.iter() { commands.entity(pom_entity).despawn(); } } +/// Calculates path for manual movement requests. fn handle_move( mut move_messages: MessageReader, mut invalid_move_messages: MessageWriter, @@ -127,6 +132,7 @@ fn handle_move( } } +/// Calculates path to interaction target. fn handle_interact( mut interact_messages: MessageReader, mut pom_query: Query<(&GridPosition, &mut PathQueue, &mut InteractionTarget)>, @@ -184,6 +190,7 @@ fn handle_interact( } } +/// Executes the pending interaction when target is reached. pub fn perform_interaction( mut pom_query: Query<(&GridPosition, &mut InteractionTarget, &PathQueue)>, grid: Res, @@ -239,6 +246,7 @@ pub fn perform_interaction( } } +/// Moves the Pom character along the path. fn move_pom( time: Res