Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Debug for most bevy_landmass structs and PartialEq/Eq for AgentTarget. #90

Merged
merged 4 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions crates/bevy_landmass/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub type Agent2dBundle = AgentBundle<TwoD>;
pub type Agent3dBundle = AgentBundle<ThreeD>;

/// An agent. See [`crate::AgentBundle`] for required related components.
#[derive(Component)]
#[derive(Component, Debug)]
pub struct Agent {
/// The radius of the agent.
pub radius: f32,
Expand All @@ -49,7 +49,7 @@ pub struct Agent {
pub max_speed: f32,
}

#[derive(Component, Default, Deref)]
#[derive(Component, Default, Deref, Debug)]
pub struct AgentNodeTypeCostOverrides(HashMap<NodeType, f32>);

impl AgentNodeTypeCostOverrides {
Expand Down Expand Up @@ -99,6 +99,32 @@ impl<CS: CoordinateSystem> Default for AgentTarget<CS> {
}
}

impl<CS: CoordinateSystem<Coordinate: std::fmt::Debug>> std::fmt::Debug
for AgentTarget<CS>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::None => write!(f, "None"),
Self::Point(arg0) => f.debug_tuple("Point").field(arg0).finish(),
Self::Entity(arg0) => f.debug_tuple("Entity").field(arg0).finish(),
}
}
}

impl<CS: CoordinateSystem<Coordinate: PartialEq>> PartialEq
for AgentTarget<CS>
{
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Point(l0), Self::Point(r0)) => l0 == r0,
(Self::Entity(l0), Self::Entity(r0)) => l0 == r0,
_ => core::mem::discriminant(self) == core::mem::discriminant(other),
}
}
}

impl<CS: CoordinateSystem<Coordinate: Eq>> Eq for AgentTarget<CS> {}

impl<CS: CoordinateSystem> AgentTarget<CS> {
/// Converts an agent target to a concrete world position.
fn to_point(
Expand Down Expand Up @@ -130,6 +156,14 @@ impl<CS: CoordinateSystem> Default for AgentDesiredVelocity<CS> {
}
}

impl<CS: CoordinateSystem<Coordinate: std::fmt::Debug>> std::fmt::Debug
for AgentDesiredVelocity<CS>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("AgentDesiredVelocity").field(&self.0).finish()
}
}

impl<CS: CoordinateSystem> AgentDesiredVelocity<CS> {
/// The desired velocity of the agent.
pub fn velocity(&self) -> CS::Coordinate {
Expand Down
10 changes: 9 additions & 1 deletion crates/bevy_landmass/src/character.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub type Character2dBundle = CharacterBundle<TwoD>;
pub type Character3dBundle = CharacterBundle<ThreeD>;

/// A character. See [`crate::CharacterBundle`] for required related components.
#[derive(Component)]
#[derive(Component, Debug)]
pub struct Character {
/// The radius of the character.
pub radius: f32,
Expand All @@ -49,6 +49,14 @@ impl<CS: CoordinateSystem> Default for Velocity<CS> {
}
}

impl<CS: CoordinateSystem<Coordinate: std::fmt::Debug>> std::fmt::Debug
for Velocity<CS>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Velocity").field("velocity", &self.velocity).finish()
}
}

/// Ensures every Bevy character has a corresponding `landmass` character.
pub(crate) fn add_characters_to_archipelago<CS: CoordinateSystem>(
mut archipelagos: Query<(Entity, &mut Archipelago<CS>)>,
Expand Down
11 changes: 11 additions & 0 deletions crates/bevy_landmass/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,17 @@ pub struct ArchipelagoRef<CS: CoordinateSystem> {
pub type ArchipelagoRef2d = ArchipelagoRef<TwoD>;
pub type ArchipelagoRef3d = ArchipelagoRef<ThreeD>;

impl<CS: CoordinateSystem<Coordinate: std::fmt::Debug>> std::fmt::Debug
for ArchipelagoRef<CS>
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ArchipelagoRef")
.field("entity", &self.entity)
.field("marker", &self.marker)
.finish()
}
}

impl<CS: CoordinateSystem> ArchipelagoRef<CS> {
pub fn new(entity: Entity) -> Self {
Self { entity, marker: Default::default() }
Expand Down
Loading