49 lines
1.1 KiB
Rust
49 lines
1.1 KiB
Rust
use bevy::prelude::*;
|
|
use bevy_rapier2d::prelude::*;
|
|
|
|
#[derive(Component)]
|
|
pub enum PassThroughFilter {
|
|
/// Absorbs this color (ignoring alpha)
|
|
Absorbing(Color),
|
|
/// Rotates hue by this angle (in degrees)
|
|
Rotating(f32),
|
|
}
|
|
|
|
impl PassThroughFilter {
|
|
pub fn apply(&self, color: Color) -> Color {
|
|
match self {
|
|
PassThroughFilter::Absorbing(filter_color) => Vec4::from(color)
|
|
.mul_add(
|
|
-Vec4::from(*filter_color) * Vec4::from([1., 1., 1., 0.]),
|
|
Vec4::from(color),
|
|
)
|
|
.into(),
|
|
PassThroughFilter::Rotating(filter_angle) => {
|
|
let mut hsla = color.as_hsla_f32();
|
|
hsla[0] = (hsla[0] + filter_angle) % 360.;
|
|
Color::hsla(hsla[0], hsla[1], hsla[2], hsla[3])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Bundle)]
|
|
pub struct AbsorbingFilter {
|
|
#[bundle]
|
|
pub mesh: ColorMesh2dBundle,
|
|
pub collider: Collider,
|
|
pub sensor: Sensor,
|
|
pub filter: PassThroughFilter,
|
|
}
|
|
|
|
#[derive(Bundle)]
|
|
pub struct RotatingFilter {
|
|
#[bundle]
|
|
pub sprite: SpriteBundle,
|
|
pub collider: Collider,
|
|
pub sensor: Sensor,
|
|
pub filter: PassThroughFilter,
|
|
pub velocity: Velocity,
|
|
pub rigid_body: RigidBody,
|
|
}
|