diff --git a/src/features/config/components.rs b/src/features/config/components.rs index 1f3ccb8..f1c5076 100644 --- a/src/features/config/components.rs +++ b/src/features/config/components.rs @@ -2,6 +2,7 @@ use crate::prelude::*; use std::fs::File; use std::io::BufReader; +/// Global configuration loaded from file, containing balancing numbers and paths. #[derive(Resource, Deserialize, Debug)] pub struct GameConfig { pub grid_width: u32, @@ -14,6 +15,7 @@ pub struct GameConfig { pub berries_per_focus_minute: u32, } +/// Configuration for a specific type of seed. #[derive(Deserialize, Debug, Clone)] pub struct BerrySeedConfig { pub name: String, @@ -61,10 +63,12 @@ impl Default for GameConfig { } impl GameConfig { + /// Reads `config.json` from assets. pub fn read_config() -> Option { Self::read_from_path(std::path::Path::new("assets/config.json")) } + /// Reads configuration from a specific path. pub fn read_from_path(path: &std::path::Path) -> Option { let file = File::open(path).ok()?; let reader = BufReader::new(file); diff --git a/src/features/core/mod.rs b/src/features/core/mod.rs index bc0e573..cc979a0 100644 --- a/src/features/core/mod.rs +++ b/src/features/core/mod.rs @@ -2,6 +2,7 @@ use crate::prelude::*; pub mod states; +/// Handles core engine setup like camera and initial state. pub struct CorePlugin; impl Plugin for CorePlugin { @@ -11,6 +12,7 @@ impl Plugin for CorePlugin { } } +/// Spawns the main 2D camera. fn setup_camera(mut commands: Commands) { commands.spawn(Camera2d::default()); } diff --git a/src/features/core/states.rs b/src/features/core/states.rs index e14ed92..8ae853b 100644 --- a/src/features/core/states.rs +++ b/src/features/core/states.rs @@ -1,5 +1,6 @@ use crate::prelude::*; +/// Global states of the application. #[derive(States, Clone, PartialEq, Eq, Debug, Hash, Default)] pub enum AppState { #[default] diff --git a/src/features/game_screen/mod.rs b/src/features/game_screen/mod.rs index 2a74417..2d865ce 100644 --- a/src/features/game_screen/mod.rs +++ b/src/features/game_screen/mod.rs @@ -1,5 +1,6 @@ use crate::prelude::*; +/// Plugin for the main game screen, managing the game loop and environment. pub struct GameScreenPlugin; impl Plugin for GameScreenPlugin { @@ -9,10 +10,12 @@ impl Plugin for GameScreenPlugin { } } +/// Sets up the game screen environment (e.g., background color). fn setup(mut clear_color: ResMut) { *clear_color = ClearColor(Color::srgb(0.294, 0.412, 0.184)); } +/// Cleans up resources when exiting the game screen. fn cleanup(mut clear_color: ResMut) { *clear_color = ClearColor(Color::srgb(0.2, 0.2, 0.2)); } diff --git a/src/features/grid/components.rs b/src/features/grid/components.rs index 6bbbb55..89c95a5 100644 --- a/src/features/grid/components.rs +++ b/src/features/grid/components.rs @@ -1,18 +1,22 @@ use super::errors::GridError; use crate::prelude::*; +/// Component representing a single tile on the grid. #[derive(Component)] pub struct Tile { pub x: u32, pub y: u32, } +/// Visual marker component for the crop on a tile. #[derive(Component)] pub struct CropVisual; +/// Visual marker component for the water on a tile. #[derive(Component)] pub struct WaterVisual; +/// The logical state of a tile. #[derive(Component, Default, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub enum TileState { #[default] @@ -38,6 +42,7 @@ impl TileState { } } +/// Resource containing grid dimensions and tile entities. #[derive(Resource)] pub struct Grid { pub width: u32, @@ -46,6 +51,7 @@ pub struct Grid { } impl Grid { + /// Returns the entity of the tile at the given position. pub fn get_tile(&self, pos: (u32, u32)) -> Result { if pos.0 >= self.width || pos.1 >= self.height { return Err(GridError::OutOfBounds { @@ -56,6 +62,7 @@ impl Grid { Ok(self.tiles[pos.0 as usize][pos.1 as usize]) } + /// Modifies the state of a tile using a mapping function. pub fn map_tile_state( &self, pos: (u32, u32), @@ -75,6 +82,7 @@ impl Grid { Ok(()) } + /// Counts the number of tiles that are not unclaimed. pub fn count_claimed_tiles(&self, tile_query: &Query<&TileState>) -> u32 { self.tiles .iter() diff --git a/src/features/grid/consts.rs b/src/features/grid/consts.rs index bc45548..d1f91b7 100644 --- a/src/features/grid/consts.rs +++ b/src/features/grid/consts.rs @@ -1 +1,2 @@ +/// The pixel size of a tile (width and height). pub const TILE_SIZE: f32 = 32.0; diff --git a/src/features/grid/errors.rs b/src/features/grid/errors.rs index fc77c3c..ee80a0f 100644 --- a/src/features/grid/errors.rs +++ b/src/features/grid/errors.rs @@ -1,5 +1,6 @@ use std::{error::Error, fmt}; +/// Errors related to grid operations. #[derive(Debug, Clone, PartialEq, Eq)] pub enum GridError { OutOfBounds { x: i32, y: i32 }, diff --git a/src/features/grid/mod.rs b/src/features/grid/mod.rs index 4aa951e..02e6eee 100644 --- a/src/features/grid/mod.rs +++ b/src/features/grid/mod.rs @@ -7,6 +7,7 @@ pub mod consts; pub mod errors; pub mod utils; +/// Manages the game grid, including tiles, visuals, and updates. pub struct GridPlugin; impl Plugin for GridPlugin { @@ -18,6 +19,7 @@ impl Plugin for GridPlugin { } } +/// Initializes the grid and spawns tile entities. fn setup(mut commands: Commands, asset_server: Res, config: Res) { let grid_width = config.grid_width; let grid_height = config.grid_height; @@ -96,6 +98,7 @@ fn setup(mut commands: Commands, asset_server: Res, config: Res>) { for tile_entity in tile_query.iter() { commands.entity(tile_entity).despawn(); @@ -103,6 +106,7 @@ fn cleanup(mut commands: Commands, tile_query: Query>) { commands.remove_resource::(); } +/// Updates tile visuals based on their state (e.g., crop growth, highlighting). fn update_tiles( mut query: Query< (&TileState, &mut AseSlice, &Children, &Tile), diff --git a/src/features/grid/utils.rs b/src/features/grid/utils.rs index 95c722e..fb816ef 100644 --- a/src/features/grid/utils.rs +++ b/src/features/grid/utils.rs @@ -1,14 +1,17 @@ use super::errors::GridError; use crate::prelude::*; +/// Calculates the starting X coordinate for centering the grid. pub fn grid_start_x(grid_width: u32) -> f32 { -(grid_width as f32 * TILE_SIZE) / 2.0 + TILE_SIZE / 2.0 } +/// Calculates the starting Y coordinate for centering the grid. pub fn grid_start_y(grid_height: u32) -> f32 { -(grid_height as f32 * TILE_SIZE) / 2.0 + TILE_SIZE / 2.0 } +/// Converts world coordinates to grid coordinates. pub fn world_to_grid_coords( world_pos: Vec3, grid_width: u32, @@ -30,6 +33,7 @@ pub fn world_to_grid_coords( Ok((x as u32, y as u32)) } +/// Converts grid coordinates to world coordinates. pub fn grid_to_world_coords( grid_x: u32, grid_y: u32, diff --git a/src/features/hud/components.rs b/src/features/hud/components.rs index be49eb9..ccd9a63 100644 --- a/src/features/hud/components.rs +++ b/src/features/hud/components.rs @@ -1,5 +1,6 @@ use crate::{features::phase::components::TimerSettings, prelude::*}; +/// Markers for root UI nodes. #[derive(Component)] pub enum RootMarker { Status, @@ -7,12 +8,14 @@ pub enum RootMarker { ShovelOverlay, } +/// Markers for text components in the HUD. #[derive(Component)] pub enum TextType { Phase, Timer, } +/// Markers for buttons in the HUD and settings. #[derive(Component)] pub enum ButtonType { SettingsOpen, @@ -24,6 +27,7 @@ pub enum ButtonType { }, } +/// Types of timers available in the game. #[derive(Clone)] pub enum TimerType { Focus, @@ -32,6 +36,7 @@ pub enum TimerType { } impl TimerSettings { + /// Changes the duration of a specific timer. pub fn change(&mut self, timer_type: &TimerType, amount: i32) { match timer_type { TimerType::Focus => { @@ -59,6 +64,7 @@ impl TimerSettings { } } +/// Input types for adjusting timer settings. #[derive(Component, Clone)] pub enum SettingsTimerInput { Minutes(TimerType), diff --git a/src/features/hud/mod.rs b/src/features/hud/mod.rs index 41937d0..3d50a06 100644 --- a/src/features/hud/mod.rs +++ b/src/features/hud/mod.rs @@ -8,6 +8,7 @@ use ui::*; pub mod components; pub mod ui; +/// Plugin for the Head-Up Display (HUD) containing status bars and buttons. pub struct HudPlugin; impl Plugin for HudPlugin { @@ -27,6 +28,7 @@ impl Plugin for HudPlugin { } } +/// Initializes the HUD UI. fn setup(mut commands: Commands, game_config: Res, asset_server: Res) { commands.spawn(( RootMarker::Status, @@ -126,6 +128,7 @@ fn setup(mut commands: Commands, game_config: Res, asset_server: Res )); } +/// Updates the status text (phase and timer). fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, &TextType)>) { if !phase_res.is_changed() { return; @@ -140,6 +143,7 @@ fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, } } +/// Handles HUD button interactions. fn buttons( mut commands: Commands, mut interaction_query: Query<(&Interaction, &ButtonType), (Changed, With