From 07e79f3e9f4091fa838ee0b0243ed2ae5be279b2 Mon Sep 17 00:00:00 2001 From: Blazepaws <157802762+blazepaws@users.noreply.github.com> Date: Sun, 15 Sep 2024 19:10:53 +0200 Subject: [PATCH] Reflect derived traits on all components and resources: bevy_sprite (#15227) Solves https://github.com/bevyengine/bevy/issues/15187 for bevy_sprite --- crates/bevy_sprite/src/lib.rs | 2 +- crates/bevy_sprite/src/mesh2d/mesh.rs | 2 +- crates/bevy_sprite/src/mesh2d/wireframe2d.rs | 8 ++++---- crates/bevy_sprite/src/sprite.rs | 5 +++-- crates/bevy_sprite/src/texture_atlas.rs | 3 +++ 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/bevy_sprite/src/lib.rs b/crates/bevy_sprite/src/lib.rs index b638cd42a1..a907d85dd5 100644 --- a/crates/bevy_sprite/src/lib.rs +++ b/crates/bevy_sprite/src/lib.rs @@ -78,7 +78,7 @@ pub enum SpriteSystem { /// /// Right now, this is used for `Text`. #[derive(Component, Reflect, Clone, Copy, Debug, Default)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] pub struct SpriteSource; /// A convenient alias for `With>`, for use with diff --git a/crates/bevy_sprite/src/mesh2d/mesh.rs b/crates/bevy_sprite/src/mesh2d/mesh.rs index 24b4f4891f..7ef45ec298 100644 --- a/crates/bevy_sprite/src/mesh2d/mesh.rs +++ b/crates/bevy_sprite/src/mesh2d/mesh.rs @@ -52,7 +52,7 @@ use crate::Material2dBindGroupId; /// /// It wraps a [`Handle`] to differentiate from the 3d pipelines which use the handles directly as components #[derive(Default, Clone, Component, Debug, Reflect, PartialEq, Eq, Deref, DerefMut)] -#[reflect(Default, Component)] +#[reflect(Default, Component, Debug, PartialEq)] pub struct Mesh2dHandle(pub Handle); impl From> for Mesh2dHandle { diff --git a/crates/bevy_sprite/src/mesh2d/wireframe2d.rs b/crates/bevy_sprite/src/mesh2d/wireframe2d.rs index 43bd10c622..83af6c3ed9 100644 --- a/crates/bevy_sprite/src/mesh2d/wireframe2d.rs +++ b/crates/bevy_sprite/src/mesh2d/wireframe2d.rs @@ -56,7 +56,7 @@ impl Plugin for Wireframe2dPlugin { /// /// This requires the [`Wireframe2dPlugin`] to be enabled. #[derive(Component, Debug, Clone, Default, Reflect, Eq, PartialEq)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug, PartialEq)] pub struct Wireframe2d; /// Sets the color of the [`Wireframe2d`] of the entity it is attached to. @@ -65,7 +65,7 @@ pub struct Wireframe2d; /// /// This overrides the [`Wireframe2dConfig::default_color`]. #[derive(Component, Debug, Clone, Default, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] pub struct Wireframe2dColor { pub color: Color, } @@ -75,11 +75,11 @@ pub struct Wireframe2dColor { /// /// This requires the [`Wireframe2dPlugin`] to be enabled. #[derive(Component, Debug, Clone, Default, Reflect, Eq, PartialEq)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug, PartialEq)] pub struct NoWireframe2d; #[derive(Resource, Debug, Clone, Default, ExtractResource, Reflect)] -#[reflect(Resource)] +#[reflect(Resource, Debug, Default)] pub struct Wireframe2dConfig { /// Whether to show wireframes for all 2D meshes. /// Can be overridden for individual meshes by adding a [`Wireframe2d`] or [`NoWireframe2d`] component. diff --git a/crates/bevy_sprite/src/sprite.rs b/crates/bevy_sprite/src/sprite.rs index a0ce5071ec..dcab26622a 100644 --- a/crates/bevy_sprite/src/sprite.rs +++ b/crates/bevy_sprite/src/sprite.rs @@ -9,7 +9,7 @@ use crate::TextureSlicer; /// /// This is commonly used as a component within [`SpriteBundle`](crate::bundle::SpriteBundle). #[derive(Component, Debug, Default, Clone, Reflect)] -#[reflect(Component, Default)] +#[reflect(Component, Default, Debug)] #[repr(C)] pub struct Sprite { /// The sprite's color tint @@ -43,7 +43,7 @@ impl Sprite { /// Controls how the image is altered when scaled. #[derive(Component, Debug, Clone, Reflect)] -#[reflect(Component)] +#[reflect(Component, Debug)] pub enum ImageScaleMode { /// The texture will be cut in 9 slices, keeping the texture in proportions on resize Sliced(TextureSlicer), @@ -62,6 +62,7 @@ pub enum ImageScaleMode { /// How a sprite is positioned relative to its [`Transform`](bevy_transform::components::Transform). /// It defaults to `Anchor::Center`. #[derive(Component, Debug, Clone, Copy, PartialEq, Default, Reflect)] +#[reflect(Component, Default, Debug, PartialEq)] #[doc(alias = "pivot")] pub enum Anchor { #[default] diff --git a/crates/bevy_sprite/src/texture_atlas.rs b/crates/bevy_sprite/src/texture_atlas.rs index ea3c67b640..a4a752865d 100644 --- a/crates/bevy_sprite/src/texture_atlas.rs +++ b/crates/bevy_sprite/src/texture_atlas.rs @@ -1,6 +1,8 @@ use bevy_asset::{Asset, AssetId, Assets, Handle}; use bevy_ecs::component::Component; +use bevy_ecs::reflect::ReflectComponent; use bevy_math::{URect, UVec2}; +use bevy_reflect::std_traits::ReflectDefault; use bevy_reflect::Reflect; use bevy_render::texture::Image; use bevy_utils::HashMap; @@ -142,6 +144,7 @@ impl TextureAtlasLayout { /// - [`sprite animation event example`](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_animation.rs) /// - [`texture atlas example`](https://github.com/bevyengine/bevy/blob/latest/examples/2d/texture_atlas.rs) #[derive(Component, Default, Debug, Clone, Reflect)] +#[reflect(Component, Default, Debug)] pub struct TextureAtlas { /// Texture atlas layout handle pub layout: Handle,