mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
FIX12527: Changes to make serde optional for bevy_color (#12666)
# Objective - Add serialize feature to bevy_color - "Fixes #12527". ## Solution - Added feature for serialization --- ## Changelog - Serde serialization is now optional, with flag 'serialize' ## Migration Guide - If user wants color data structures to be serializable, then application needs to be build with flag 'serialize'
This commit is contained in:
parent
944fc71eb1
commit
9e0970768a
15 changed files with 85 additions and 36 deletions
|
@ -14,11 +14,14 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", features = [
|
|||
"bevy",
|
||||
] }
|
||||
bytemuck = "1"
|
||||
serde = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"], optional = true }
|
||||
thiserror = "1.0"
|
||||
wgpu = { version = "0.19.3", default-features = false }
|
||||
encase = { version = "0.7", default-features = false }
|
||||
|
||||
[features]
|
||||
serialize = ["serde"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ use crate::{
|
|||
Alpha, Hsla, Hsva, Hwba, Laba, Lcha, LinearRgba, Oklaba, Oklcha, Srgba, StandardColor, Xyza,
|
||||
};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// An enumerated type that can represent any of the color types in this crate.
|
||||
///
|
||||
|
@ -12,8 +11,13 @@ use serde::{Deserialize, Serialize};
|
|||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub enum Color {
|
||||
/// A color in the sRGB color space with alpha.
|
||||
Srgba(Srgba),
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::{
|
|||
Xyza,
|
||||
};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Color in Hue-Saturation-Lightness (HSL) color space with alpha.
|
||||
/// Further information on this color model can be found on [Wikipedia](https://en.wikipedia.org/wiki/HSL_and_HSV).
|
||||
|
@ -11,8 +10,13 @@ use serde::{Deserialize, Serialize};
|
|||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Hsla {
|
||||
/// The hue channel. [0.0, 360.0]
|
||||
pub hue: f32,
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::{Alpha, ClampColor, Hue, Hwba, Lcha, LinearRgba, Mix, Srgba, StandardColor, Xyza};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Color in Hue-Saturation-Value (HSV) color space with alpha.
|
||||
/// Further information on this color model can be found on [Wikipedia](https://en.wikipedia.org/wiki/HSL_and_HSV).
|
||||
|
@ -8,8 +7,13 @@ use serde::{Deserialize, Serialize};
|
|||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Hsva {
|
||||
/// The hue channel. [0.0, 360.0]
|
||||
pub hue: f32,
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
//! [_HWB - A More Intuitive Hue-Based Color Model_]: https://web.archive.org/web/20240226005220/http://alvyray.com/Papers/CG/HWB_JGTv208.pdf
|
||||
use crate::{Alpha, ClampColor, Hue, Lcha, LinearRgba, Mix, Srgba, StandardColor, Xyza};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Color in Hue-Whiteness-Blackness (HWB) color space with alpha.
|
||||
/// Further information on this color model can be found on [Wikipedia](https://en.wikipedia.org/wiki/HWB_color_model).
|
||||
|
@ -12,8 +11,13 @@ use serde::{Deserialize, Serialize};
|
|||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Hwba {
|
||||
/// The hue channel. [0.0, 360.0]
|
||||
pub hue: f32,
|
||||
|
|
|
@ -3,15 +3,19 @@ use crate::{
|
|||
Oklaba, Srgba, StandardColor, Xyza,
|
||||
};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Color in LAB color space, with alpha
|
||||
#[doc = include_str!("../docs/conversion.md")]
|
||||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Laba {
|
||||
/// The lightness channel. [0.0, 1.5]
|
||||
pub lightness: f32,
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
use crate::{Alpha, ClampColor, Hue, Laba, LinearRgba, Luminance, Mix, Srgba, StandardColor, Xyza};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Color in LCH color space, with alpha
|
||||
#[doc = include_str!("../docs/conversion.md")]
|
||||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Lcha {
|
||||
/// The lightness channel. [0.0, 1.5]
|
||||
pub lightness: f32,
|
||||
|
|
|
@ -142,7 +142,6 @@ where
|
|||
Self: core::fmt::Debug,
|
||||
Self: Clone + Copy,
|
||||
Self: PartialEq,
|
||||
Self: serde::Serialize + for<'a> serde::Deserialize<'a>,
|
||||
Self: bevy_reflect::Reflect,
|
||||
Self: Default,
|
||||
Self: From<Color> + Into<Color>,
|
||||
|
|
|
@ -5,15 +5,19 @@ use crate::{
|
|||
use bevy_math::Vec4;
|
||||
use bevy_reflect::prelude::*;
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Linear RGB color with alpha.
|
||||
#[doc = include_str!("../docs/conversion.md")]
|
||||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
#[repr(C)]
|
||||
pub struct LinearRgba {
|
||||
/// The red channel. [0.0, 1.0]
|
||||
|
|
|
@ -3,15 +3,19 @@ use crate::{
|
|||
Hwba, Lcha, LinearRgba, Luminance, Mix, Srgba, StandardColor, Xyza,
|
||||
};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Color in Oklab color space, with alpha
|
||||
#[doc = include_str!("../docs/conversion.md")]
|
||||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Oklaba {
|
||||
/// The 'lightness' channel. [0.0, 1.0]
|
||||
pub lightness: f32,
|
||||
|
|
|
@ -3,15 +3,19 @@ use crate::{
|
|||
LinearRgba, Luminance, Mix, Oklaba, Srgba, StandardColor, Xyza,
|
||||
};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Color in Oklch color space, with alpha
|
||||
#[doc = include_str!("../docs/conversion.md")]
|
||||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Oklcha {
|
||||
/// The 'lightness' channel. [0.0, 1.0]
|
||||
pub lightness: f32,
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::{
|
|||
};
|
||||
use bevy_math::Vec4;
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use thiserror::Error;
|
||||
|
||||
/// Non-linear standard RGB with alpha.
|
||||
|
@ -12,8 +11,13 @@ use thiserror::Error;
|
|||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Srgba {
|
||||
/// The red channel. [0.0, 1.0]
|
||||
pub red: f32,
|
||||
|
|
|
@ -2,15 +2,19 @@ use crate::{
|
|||
impl_componentwise_point, Alpha, ClampColor, LinearRgba, Luminance, Mix, StandardColor,
|
||||
};
|
||||
use bevy_reflect::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// [CIE 1931](https://en.wikipedia.org/wiki/CIE_1931_color_space) color space, also known as XYZ, with an alpha channel.
|
||||
#[doc = include_str!("../docs/conversion.md")]
|
||||
/// <div>
|
||||
#[doc = include_str!("../docs/diagrams/model_graph.svg")]
|
||||
/// </div>
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize, Reflect)]
|
||||
#[reflect(PartialEq, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Reflect)]
|
||||
#[reflect(PartialEq, Default)]
|
||||
#[cfg_attr(
|
||||
feature = "serialize",
|
||||
derive(serde::Serialize, serde::Deserialize),
|
||||
reflect(Serialize, Deserialize)
|
||||
)]
|
||||
pub struct Xyza {
|
||||
/// The x-axis. [0.0, 1.0]
|
||||
pub x: f32,
|
||||
|
|
|
@ -73,6 +73,7 @@ serialize = [
|
|||
"bevy_math/serialize",
|
||||
"bevy_scene?/serialize",
|
||||
"bevy_ui?/serialize",
|
||||
"bevy_color?/serialize",
|
||||
]
|
||||
multi-threaded = [
|
||||
"bevy_asset?/multi-threaded",
|
||||
|
|
|
@ -39,7 +39,9 @@ ios_simulator = []
|
|||
# bevy
|
||||
bevy_app = { path = "../bevy_app", version = "0.14.0-dev" }
|
||||
bevy_asset = { path = "../bevy_asset", version = "0.14.0-dev" }
|
||||
bevy_color = { path = "../bevy_color", version = "0.14.0-dev" }
|
||||
bevy_color = { path = "../bevy_color", version = "0.14.0-dev", features = [
|
||||
"serialize",
|
||||
] }
|
||||
bevy_core = { path = "../bevy_core", version = "0.14.0-dev" }
|
||||
bevy_derive = { path = "../bevy_derive", version = "0.14.0-dev" }
|
||||
bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.14.0-dev" }
|
||||
|
|
Loading…
Reference in a new issue