-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
218 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,9 @@ | ||
use crate::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
mod entity; | ||
pub use entity::{ContentId, ContentType}; | ||
mod id; | ||
pub use id::{ContentId, ContentType}; | ||
|
||
pub mod sprite; | ||
|
||
mod state; | ||
pub use state::{transition_to_ready, RyotContentState}; | ||
|
||
mod visual_element; | ||
pub use visual_element::{VisualElement, VisualElements}; | ||
|
||
/// Ryot expects the sprite sheets to be cataloged in a JSON file. This file contains a list of | ||
/// elements of type `SpriteSheet` that represents the sprite sheet information. | ||
/// This struct is a default representation of this catalog file and ignores the other fields | ||
/// that your JSON might have. | ||
/// | ||
/// You can use your own json struct to represent the catalog file, as long as it implements | ||
/// the Into<Option<SpriteSheet>> + Clone. | ||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
#[cfg_attr(feature = "bevy", derive(bevy_reflect::TypePath))] | ||
#[serde(tag = "type")] | ||
pub enum ContentRecord { | ||
#[serde(rename = "sprite")] | ||
SpriteSheet(SpriteSheet), | ||
#[serde(other, rename = "unknown")] | ||
Unknown, | ||
} | ||
|
||
impl From<ContentRecord> for Option<SpriteSheet> { | ||
fn from(content: ContentRecord) -> Self { | ||
match content { | ||
ContentRecord::SpriteSheet(sprite_sheet) => Some(sprite_sheet), | ||
_ => None, | ||
} | ||
} | ||
} | ||
pub mod record; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
pub enum Category { | ||
Bottom, | ||
Containers, | ||
Corpses, | ||
Decor, | ||
Edges, | ||
Ground, | ||
#[default] | ||
Miscellaneous, | ||
Top, | ||
Wearable, | ||
Custom(i32), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::prelude::Navigable; | ||
|
||
/// Standard implementation of `Navigable` used within the Ryot framework. | ||
/// | ||
/// `Flags` struct serves as the default data structure for encoding walkability and sight-blocking | ||
/// attributes of game elements, particularly those defined in the content catalog. It is used as | ||
/// a component in ECS to assign physical properties to visual elements like tiles and objects, | ||
/// supporting straightforward integration with pathfinding and visibility checks. | ||
/// | ||
/// # Attributes | ||
/// * `is_walkable` - Indicates whether the element permits movement over it. | ||
/// * `blocks_sight` - Determines if the element impedes vision. | ||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
#[cfg_attr(feature = "bevy", derive(bevy_ecs::prelude::Component))] | ||
pub struct Flags { | ||
pub is_walkable: bool, | ||
pub blocks_sight: bool, | ||
} | ||
|
||
impl Default for Flags { | ||
fn default() -> Self { | ||
Flags { | ||
is_walkable: true, | ||
blocks_sight: false, | ||
} | ||
} | ||
} | ||
|
||
impl Flags { | ||
pub fn new(is_walkable: bool, blocks_sight: bool) -> Self { | ||
Flags { | ||
is_walkable, | ||
blocks_sight, | ||
} | ||
} | ||
|
||
pub fn with_walkable(self, is_walkable: bool) -> Self { | ||
Flags { | ||
is_walkable, | ||
..self | ||
} | ||
} | ||
|
||
pub fn with_blocks_sight(self, blocks_sight: bool) -> Self { | ||
Flags { | ||
blocks_sight, | ||
..self | ||
} | ||
} | ||
} | ||
|
||
impl Navigable for Flags { | ||
fn is_walkable(&self) -> bool { | ||
self.is_walkable | ||
} | ||
|
||
fn blocks_sight(&self) -> bool { | ||
self.blocks_sight | ||
} | ||
|
||
fn append(mut self, navigable: &impl Navigable) -> Self { | ||
self.is_walkable &= navigable.is_walkable(); | ||
self.blocks_sight |= navigable.blocks_sight(); | ||
self | ||
} | ||
|
||
fn is_default(&self) -> bool { | ||
*self == Flags::default() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::prelude::*; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
mod category; | ||
pub use category::Category; | ||
|
||
mod flags; | ||
pub use flags::Flags; | ||
|
||
mod visual_element; | ||
pub use visual_element::{VisualElement, VisualElements}; | ||
|
||
/// Ryot expects the sprite sheets to be cataloged in a JSON file. This file contains a list of | ||
/// elements of type `SpriteSheet` that represents the sprite sheet information. | ||
/// This struct is a default representation of this catalog file and ignores the other fields | ||
/// that your JSON might have. | ||
/// | ||
/// You can use your own json struct to represent the catalog file, as long as it implements | ||
/// the Into<Option<SpriteSheet>> + Clone. | ||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
#[cfg_attr(feature = "bevy", derive(bevy_reflect::TypePath))] | ||
#[serde(tag = "type")] | ||
pub enum ContentRecord { | ||
#[serde(rename = "sprite")] | ||
SpriteSheet(SpriteSheet), | ||
#[serde(other, rename = "unknown")] | ||
Unknown, | ||
} | ||
|
||
impl From<ContentRecord> for Option<SpriteSheet> { | ||
fn from(content: ContentRecord) -> Self { | ||
match content { | ||
ContentRecord::SpriteSheet(sprite_sheet) => Some(sprite_sheet), | ||
_ => None, | ||
} | ||
} | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,5 @@ | ||
mod properties; | ||
pub use properties::{Elevation, Properties}; | ||
|
||
mod flags; | ||
pub use flags::Flags; | ||
|
||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
pub enum Category { | ||
Bottom, | ||
Containers, | ||
Corpses, | ||
Decor, | ||
Edges, | ||
Ground, | ||
#[default] | ||
Miscellaneous, | ||
Top, | ||
Wearable, | ||
Custom(i32), | ||
} | ||
mod navigable; | ||
pub use navigable::Navigable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// Defines behavior for tiles or entities in terms of navigation and visibility within the Ryot framework. | ||
/// | ||
/// This trait abstracts the walkability and sight-blocking properties to ensure compatibility with | ||
/// generic systems such as pathfinding and ray-casting, facilitating their application across | ||
/// different types of game environments and scenarios. | ||
/// | ||
/// Implementing this trait allows for consistent behavior across various game elements, making | ||
/// it integral to developing flexible and reusable game mechanics. | ||
/// | ||
/// # Examples | ||
/// | ||
/// Implementing `Navigable` for a custom tile type might look like this: | ||
/// | ||
/// ``` | ||
/// use ryot_core::prelude::Navigable; | ||
/// | ||
/// #[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
/// struct CustomTile { | ||
/// walkable: bool, | ||
/// sight_blocking: bool, | ||
/// } | ||
/// | ||
/// impl Navigable for CustomTile { | ||
/// fn is_walkable(&self) -> bool { | ||
/// self.walkable | ||
/// } | ||
/// | ||
/// fn blocks_sight(&self) -> bool { | ||
/// self.sight_blocking | ||
/// } | ||
/// | ||
/// fn append(self, navigable: &impl Navigable) -> Self{ | ||
/// self | ||
/// } | ||
/// | ||
/// fn is_default(&self) -> bool { | ||
/// true | ||
/// } | ||
/// } | ||
/// ``` | ||
pub trait Navigable: Sync + Send + 'static { | ||
fn is_walkable(&self) -> bool; | ||
fn blocks_sight(&self) -> bool; | ||
fn append(self, navigable: &impl Navigable) -> Self; | ||
fn is_default(&self) -> bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.