From f678a8993d45425a5140750a4393672ccf4c8b2c Mon Sep 17 00:00:00 2001 From: core Date: Sun, 6 Jul 2025 19:37:40 -0400 Subject: [PATCH] chore: newtype linearsplines for particle system --- crates/unified/src/particles.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/crates/unified/src/particles.rs b/crates/unified/src/particles.rs index 363b7c726f192d8531d7de4e0d9616788b9a13f1..92977aef64dd7462d048422d634be94f29ee697f 100644 --- a/crates/unified/src/particles.rs +++ b/crates/unified/src/particles.rs @@ -1,8 +1,9 @@ use bevy::color::{Color, ColorCurve, LinearRgba}; use bevy::math::cubic_splines::LinearSpline; -use bevy::math::Vec2; +use bevy::math::{Vec2, VectorSpace}; use rand::Rng; use serde::{Deserialize, Serialize}; +use serde::de::DeserializeOwned; #[derive(Deserialize, Serialize)] pub struct ParticleEffect { @@ -25,14 +26,30 @@ pub struct ParticleEffect { // -- scale -- // // Scale curve over the lifetime of the particle - //pub scale: LinearSpline, + pub scale: ScaleSpline, // -- color -- // // Color curve over the lifetime of the particle - //pub color: LinearSpline, + pub color: ColorSpline, } +#[derive(Deserialize, Serialize)] +pub struct ScaleSpline(Vec); +impl From for LinearSpline { + fn from(value: ScaleSpline) -> Self { + Self::new(&value.0) + } +} +#[derive(Deserialize, Serialize)] +pub struct ColorSpline(Vec); +impl From for LinearSpline { + fn from(value: ColorSpline) -> Self { + Self::new(&value.0) + } +} + + #[derive(Deserialize, Serialize)] pub struct RandF32 { pub value: f32,