From f40390bb88c38a109bada4da9236af5bedfc7e39 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sat, 17 Aug 2024 16:34:10 -0700 Subject: [PATCH 1/4] Make AgentTarget impl Debug, PartialEq, and Eq. --- crates/bevy_landmass/src/agent.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/bevy_landmass/src/agent.rs b/crates/bevy_landmass/src/agent.rs index 682be77..16d0b5e 100644 --- a/crates/bevy_landmass/src/agent.rs +++ b/crates/bevy_landmass/src/agent.rs @@ -99,6 +99,32 @@ impl Default for AgentTarget { } } +impl> std::fmt::Debug + for AgentTarget +{ + 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> PartialEq + for AgentTarget +{ + 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> Eq for AgentTarget {} + impl AgentTarget { /// Converts an agent target to a concrete world position. fn to_point( From 48c75c1f87f8281b964cff4bdf28ea898c89f519 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sat, 17 Aug 2024 16:37:24 -0700 Subject: [PATCH 2/4] Make most agent structs impl Debug. --- crates/bevy_landmass/src/agent.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/bevy_landmass/src/agent.rs b/crates/bevy_landmass/src/agent.rs index 16d0b5e..8ea2054 100644 --- a/crates/bevy_landmass/src/agent.rs +++ b/crates/bevy_landmass/src/agent.rs @@ -37,7 +37,7 @@ pub type Agent2dBundle = AgentBundle; pub type Agent3dBundle = AgentBundle; /// 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, @@ -49,7 +49,7 @@ pub struct Agent { pub max_speed: f32, } -#[derive(Component, Default, Deref)] +#[derive(Component, Default, Deref, Debug)] pub struct AgentNodeTypeCostOverrides(HashMap); impl AgentNodeTypeCostOverrides { @@ -156,6 +156,14 @@ impl Default for AgentDesiredVelocity { } } +impl> std::fmt::Debug + for AgentDesiredVelocity +{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("AgentDesiredVelocity").field(&self.0).finish() + } +} + impl AgentDesiredVelocity { /// The desired velocity of the agent. pub fn velocity(&self) -> CS::Coordinate { From 40c53ebd84755ff27464f217889144082737003a Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sat, 17 Aug 2024 16:38:08 -0700 Subject: [PATCH 3/4] Make the character structs impl Debug. --- crates/bevy_landmass/src/character.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/bevy_landmass/src/character.rs b/crates/bevy_landmass/src/character.rs index 611306a..4c16cdb 100644 --- a/crates/bevy_landmass/src/character.rs +++ b/crates/bevy_landmass/src/character.rs @@ -26,7 +26,7 @@ pub type Character2dBundle = CharacterBundle; pub type Character3dBundle = CharacterBundle; /// 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, @@ -49,6 +49,14 @@ impl Default for Velocity { } } +impl> std::fmt::Debug + for Velocity +{ + 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( mut archipelagos: Query<(Entity, &mut Archipelago)>, From c40b990f25843438fbc10fe4ec0a4296c951d9a0 Mon Sep 17 00:00:00 2001 From: andriyDev Date: Sat, 17 Aug 2024 16:40:30 -0700 Subject: [PATCH 4/4] Make the ArchipelagoRef impl Debug. --- crates/bevy_landmass/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/bevy_landmass/src/lib.rs b/crates/bevy_landmass/src/lib.rs index e4b3db6..749fe67 100644 --- a/crates/bevy_landmass/src/lib.rs +++ b/crates/bevy_landmass/src/lib.rs @@ -344,6 +344,17 @@ pub struct ArchipelagoRef { pub type ArchipelagoRef2d = ArchipelagoRef; pub type ArchipelagoRef3d = ArchipelagoRef; +impl> std::fmt::Debug + for ArchipelagoRef +{ + 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 ArchipelagoRef { pub fn new(entity: Entity) -> Self { Self { entity, marker: Default::default() }