Skip to content

Commit

Permalink
Feature gate bevy_reflect in bevy_image. (#17313)
Browse files Browse the repository at this point in the history
Fixes #17294.
  • Loading branch information
AlephCubed authored Jan 12, 2025
1 parent 5c0e13f commit 6063887
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
12 changes: 7 additions & 5 deletions crates/bevy_image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
default = ["bevy_reflect"]

bevy_reflect = ["dep:bevy_reflect", "bevy_math/bevy_reflect"]

# Image formats
basis-universal = ["dep:basis-universal"]
bmp = ["image/bmp"]
Expand All @@ -26,7 +30,7 @@ qoi = ["image/qoi"]
tga = ["image/tga"]
tiff = ["image/tiff"]
webp = ["image/webp"]
serialize = []
serialize = ["bevy_reflect"]

# For ktx2 supercompression
zlib = ["flate2"]
Expand All @@ -40,12 +44,10 @@ bevy_color = { path = "../bevy_color", version = "0.16.0-dev", features = [
"serialize",
"wgpu-types",
] }
bevy_math = { path = "../bevy_math", version = "0.16.0-dev", features = [
"bevy_reflect",
] }
bevy_math = { path = "../bevy_math", version = "0.16.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.16.0-dev", features = [
"bevy",
] }
], optional = true }
bevy_utils = { path = "../bevy_utils", version = "0.16.0-dev" }

# rendering
Expand Down
13 changes: 8 additions & 5 deletions crates/bevy_image/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use super::basis::*;
use super::dds::*;
#[cfg(feature = "ktx2")]
use super::ktx2::*;
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::{std_traits::ReflectDefault, Reflect};

use bevy_asset::{Asset, RenderAssetUsages};
use bevy_color::{Color, ColorToComponents, Gray, LinearRgba, Srgba, Xyza};
use bevy_math::{AspectRatio, UVec2, UVec3, Vec2};
use bevy_reflect::std_traits::ReflectDefault;
use bevy_reflect::Reflect;
use core::hash::Hash;
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -331,9 +331,12 @@ impl ImageFormat {
}
}

#[derive(Asset, Reflect, Debug, Clone)]
#[reflect(opaque)]
#[reflect(Default, Debug)]
#[derive(Asset, Debug, Clone)]
#[cfg_attr(
feature = "bevy_reflect",
derive(Reflect),
reflect(opaque, Default, Debug)
)]
pub struct Image {
pub data: Vec<u8>,
// TODO: this nesting makes accessing Image metadata verbose. Either flatten out descriptor or add accessors
Expand Down
22 changes: 14 additions & 8 deletions crates/bevy_image/src/texture_atlas.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use bevy_app::prelude::*;
use bevy_asset::{Asset, AssetApp as _, AssetId, Assets, Handle};
use bevy_math::{URect, UVec2};
#[cfg(feature = "bevy_reflect")]
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
#[cfg(feature = "serialize")]
use bevy_reflect::{ReflectDeserialize, ReflectSerialize};
Expand All @@ -13,8 +14,10 @@ pub struct TextureAtlasPlugin;

impl Plugin for TextureAtlasPlugin {
fn build(&self, app: &mut App) {
app.init_asset::<TextureAtlasLayout>()
.register_asset_reflect::<TextureAtlasLayout>()
app.init_asset::<TextureAtlasLayout>();

#[cfg(feature = "bevy_reflect")]
app.register_asset_reflect::<TextureAtlasLayout>()
.register_type::<TextureAtlas>();
}
}
Expand Down Expand Up @@ -69,10 +72,13 @@ impl TextureAtlasSources {
/// [Example usage loading sprite sheet.](https://github.com/bevyengine/bevy/blob/latest/examples/2d/texture_atlas.rs)
///
/// [`TextureAtlasBuilder`]: crate::TextureAtlasBuilder
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
#[derive(Asset, Reflect, PartialEq, Eq, Debug, Clone)]
#[reflect(Debug, PartialEq)]
#[cfg_attr(feature = "serialize", reflect(Serialize, Deserialize))]
#[derive(Asset, PartialEq, Eq, Debug, Clone)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Debug, PartialEq))]
#[cfg_attr(
feature = "serialize",
derive(serde::Serialize, serde::Deserialize),
reflect(Serialize, Deserialize)
)]
pub struct TextureAtlasLayout {
/// Total size of texture atlas.
pub size: UVec2,
Expand Down Expand Up @@ -176,8 +182,8 @@ impl TextureAtlasLayout {
/// - [`animated sprite sheet example`](https://github.com/bevyengine/bevy/blob/latest/examples/2d/sprite_sheet.rs)
/// - [`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(Default, Debug, Clone, Reflect)]
#[reflect(Default, Debug)]
#[derive(Default, Debug, Clone)]
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Default, Debug))]
pub struct TextureAtlas {
/// Texture atlas layout handle
pub layout: Handle<TextureAtlasLayout>,
Expand Down

0 comments on commit 6063887

Please sign in to comment.