~starkingdoms/starkingdoms

25992c7667d87eb71655c121f52287dce434d955 — ghostly_zsh 5 months ago a428f5f
changed file structure a bit
2 files changed, 56 insertions(+), 56 deletions(-)

D crates/unified/src/particle/mod.rs
M crates/unified/src/particles.rs
D crates/unified/src/particle/mod.rs => crates/unified/src/particle/mod.rs +0 -56
@@ 1,56 0,0 @@
use bevy::color::{Color, ColorCurve, LinearRgba};
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<f32>,

    // -- color -- //

    // Color curve over the lifetime of the particle
    //pub color: LinearSpline<LinearRgba>,
}

#[derive(Deserialize, Serialize)]
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)
    }
}

#[derive(Deserialize, Serialize)]
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))
    }
}
\ No newline at end of file

M crates/unified/src/particles.rs => crates/unified/src/particles.rs +56 -0
@@ 0,0 1,56 @@
use bevy::color::{Color, ColorCurve, LinearRgba};
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<f32>,

    // -- color -- //

    // Color curve over the lifetime of the particle
    //pub color: LinearSpline<LinearRgba>,
}

#[derive(Deserialize, Serialize)]
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)
    }
}

#[derive(Deserialize, Serialize)]
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))
    }
}