Skip to content

Commit

Permalink
chore: API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-bon committed Jan 6, 2025
1 parent f922336 commit b59190b
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This module contains an implementation for [tiled::ResourceCache]
use bevy::prelude::*;
use std::sync::{Arc, RwLock};
use tiled::{DefaultResourceCache, ResourceCache};
Expand Down
2 changes: 1 addition & 1 deletion src/map/asset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This module contains all [Asset]s definition.
//! This module contains all map [Asset]s definition.
use std::io::ErrorKind;
#[cfg(feature = "user_properties")]
Expand Down
4 changes: 2 additions & 2 deletions src/map/components.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! This module contains all [Component]s definition.
//! This module contains all map [Component]s definition.
use crate::prelude::*;
use bevy::{prelude::*, utils::HashMap};
use tiled::TileId;

/// [Component] holding Tiled related settings.
/// [Component] holding Tiled map related settings.
///
/// Controls various settings related to the way we handle the Tiled map.
/// Must be added to the [Entity] holding the map.
Expand Down
2 changes: 2 additions & 0 deletions src/map/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This module handles all the logic related to loading and spawning Tiled maps
pub mod asset;
pub mod components;
pub mod events;
Expand Down
2 changes: 2 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This module contains an implementation for [tiled::ResourceReader]
use bevy::asset::LoadContext;
use std::{
io::{Cursor, Error as IoError, ErrorKind, Read},
Expand Down
7 changes: 5 additions & 2 deletions src/world/asset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This module contains all world [Asset]s definition.
use bevy::{
asset::{io::Reader, AssetLoader, AssetPath, LoadContext},
prelude::*,
Expand All @@ -11,10 +13,11 @@ use crate::{cache::TiledResourceCache, reader::BytesResourceReader, TiledMap};
/// `Asset` holding Tiled world informations.
#[derive(TypePath, Asset)]
pub struct TiledWorld {
/// The raw Tiled world data
pub world: tiled::World,

/// The [Rect] boundary of our worlds ie. the sum of all the maps boundary it contains
pub world_rect: Rect,

/// List of all the maps contained in this world and their associated [Rect] boundary
pub maps: Vec<(Rect, Handle<TiledMap>)>,
}

Expand Down
17 changes: 17 additions & 0 deletions src/world/components.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
//! This module contains all map [Component]s definition.
use bevy::{prelude::*, utils::HashMap};

/// [Component] holding Tiled world related settings.
///
/// Controls various settings related to the way we handle the Tiled world.
/// Must be added to the [Entity] holding the world.
#[derive(Component, Default)]
pub struct TiledWorldSettings {
/// World chunking configuration
///
/// If this value is None, we won't perform chunking: all maps from this world will just be loaded
/// If this value is set, defines the area (in pixel) around each [Camera] where we should spawn a
/// map if it overlaps with its associated [Rect].
pub chunking: Option<(u32, u32)>,
}

/// Marker [Component] for a Tiled world.
#[derive(Component)]
pub struct TiledWorldMarker;

/// Marker [Component] to trigger a world respawn.
///
/// Must be added to the [Entity] holding the map.
#[derive(Component)]
pub struct RespawnTiledWorld;

/// [Component] storing informations about which maps are actually spawned
#[derive(Component, Default)]
pub struct TiledWorldStorage {
/// Map using the map index from [super::asset::TiledWorld] maps list as key.
/// It contains the map entity.
pub spawned_maps: HashMap<usize, Entity>,
}
9 changes: 8 additions & 1 deletion src/world/events.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
//! Events related to Tiled world loading
//!
//! These events will be fired after the whole map has loaded.
use crate::prelude::*;
use bevy::prelude::*;

/// Event sent when a Tiled world has finished loading
/// Event sent when a Tiled world has finished loading.
#[derive(Event, Clone, Debug)]
pub struct TiledWorldCreated {
/// Spawned world [Entity].
pub world: Entity,
/// [AssetId] of the corresponding [super::asset::TiledWorld] asset.
pub world_asset_id: AssetId<TiledWorld>,
}

impl<'a> TiledWorldCreated {
/// Retrieve the [TiledWorld] associated to this [TiledWorldCreated] event.
pub fn get_world(&self, world_asset: &'a Res<Assets<TiledWorld>>) -> Option<&'a TiledWorld> {
world_asset.get(self.world_asset_id)
}
Expand Down
2 changes: 2 additions & 0 deletions src/world/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This module handles all the logic related to loading and spawning Tiled worlds.
pub mod asset;
pub mod components;
pub mod events;
Expand Down

0 comments on commit b59190b

Please sign in to comment.