From e1dacc56a2f556eee875e4c92b0890a531551a65 Mon Sep 17 00:00:00 2001 From: core Date: Sun, 6 Jul 2025 11:51:25 -0400 Subject: [PATCH] feat: particle effect description --- crates/unified/src/lib.rs | 1 + crates/unified/src/particle/mod.rs | 58 ++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 crates/unified/src/particle/mod.rs diff --git a/crates/unified/src/lib.rs b/crates/unified/src/lib.rs index adc27f0d3f542cdd80bcadb0f253c843eee079ab..8ec2f1af01d57a248eef08b2b007117046b4e07f 100644 --- a/crates/unified/src/lib.rs +++ b/crates/unified/src/lib.rs @@ -24,3 +24,4 @@ pub mod server; #[cfg(all(not(target_arch = "wasm32"), feature = "native"))] pub mod server_plugins; pub mod shared_plugins; +pub mod particle; diff --git a/crates/unified/src/particle/mod.rs b/crates/unified/src/particle/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..c4d3bdf613d8c34497a370c64eccf0e0ed71f578 --- /dev/null +++ b/crates/unified/src/particle/mod.rs @@ -0,0 +1,58 @@ +use bevy::color::{Color, ColorCurve}; +use bevy::math::cubic_splines::LinearSpline; +use bevy::math::Vec2; +use rand::Rng; +use serde::{Deserialize, Serialize}; + +#[derive(Deserialize, Serialize)] +pub struct ParticleEffect { + // -- lifetime / spawning -- // + + /// Particle lifetime in seconds + pub lifetime_seconds: RandF32, + /// Delay inbetween each batch of particles spawned + pub batch_spawn_delay_seconds: RandF32, + /// Number of distinct particles spawned per batch + pub particles_in_batch: RandF32, + + // -- velocity -- // + + /// Initial linear velocity added to the particle's velocity when it is spawned + pub initial_linear_velocity: RandVec2, + /// Initial angular velocity added to the particle's rotation when it is spawned + pub initial_angular_velocity: RandF32, + + // -- scale -- // + + /// Scale curve over the lifetime of the particle + pub scale: LinearSpline, + + // -- color -- // + + /// Color curve over the lifetime of the particle + pub color: LinearSpline, +} + +pub struct RandF32 { + pub value: f32, + pub randomness: f32 +} +impl RandF32 { + pub fn sample(&self, rng: &mut impl Rng) -> f32 { + rng.random_range(self.value-self.randomness .. self.value+self.randomness) + } +} + +pub struct RandVec2 { + pub x: RandF32, + pub y: RandF32, +} +impl RandVec2 { + pub fn sample(&self, rng: &mut impl Rng) -> Vec2 { + Vec2::new(self.x.sample(rng), self.y.sample(rng)) + } +} + +pub struct PColorCurve { + pub color: ColorCurve, +} \ No newline at end of file