docs: document grid system and game screen environment (#65)

This commit is contained in:
demenik
2025-12-10 18:12:27 +01:00
parent 49302948d2
commit 040b2742ca
6 changed files with 21 additions and 0 deletions

View File

@@ -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<Entity, GridError> {
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<F>(
&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()