Dissolve refactor: It ain't perfect, it ain't done, but it's progress!

Yay incremental progress toward the old effect!

The function that plays the animation for dissolving when pieces are
tagged is roughly working.

The only downsides now are that multiple pieces are sharing the same
material, and more importantly the piece should be moving to the side of
the board but it is not!
main
Elijah C. Voigt 2 years ago
parent 7b4682bc21
commit 37a7488852

@ -54,6 +54,7 @@ impl Plugin for Display3dPlugin {
any_component_added::<Handle<StandardMaterial>>()
.or_else(any_component_changed::<Handle<StandardMaterial>>()),
),
dissolve_animation.run_if(any_with_component::<Dissolving>),
capture_piece.run_if(any_with_component::<game::Captured>),
skip_animation
.run_if(just_pressed(KeyCode::Enter).or_else(just_pressed(MouseButton::Left)))
@ -99,8 +100,7 @@ impl Plugin for Display3dPlugin {
just_pressed(KeyCode::Enter).or_else(just_pressed(MouseButton::Left)),
),
),
)
.add_systems(Update, dissolve_animation.run_if(any_with_component::<Dissolving>));
);
}
}
@ -1265,6 +1265,7 @@ fn capture_piece(
// Wait for fade-out animation
// If all pieces are done dissolving
if dissolving.is_empty() {
info!("Nothing dissolving, moving on to next step!");
// Move to next state now that animation is done
*state = s.next();
// This takes effect after updating all children
@ -1295,6 +1296,8 @@ fn capture_piece(
game::CaptureFlow::FadeIn(_entity) => {
// If we have completed the dissolve-in animation
if dissolving.is_empty() {
info!("Nothing dissolving, moving on to next step!");
// Move to next state now that animation is done
*state = s.next();
}
@ -1359,7 +1362,7 @@ fn continue_title(mut next_state: ResMut<NextState<GameState>>) {
/// Calculating how far along the animation it should be update the material's percentage
/// Materials are on the children of the tagged entity
fn dissolve_animation(
mut query: Query<(Entity, &mut Dissolvable, &mut Dissolving)>,
mut query: Query<(Entity, &Dissolvable, &mut Dissolving)>,
children: Query<&Children>,
// Used to create Handle<DissolveMaterial>
mut dissolve_materials: ResMut<Assets<DissolveMaterial>>,
@ -1371,33 +1374,26 @@ fn dissolve_animation(
time: Res<Time>,
) {
query.iter_mut().for_each(|(entity, dissolvable, mut dissolving)| {
// Calculate how much of the animation has passed
let delta = time.delta_seconds() / dissolvable.duration;
info!("Entity {:?} has Dissolving {:?}", entity, dissolving);
let percentage = match *dissolving {
Dissolving::In(mut sec) => {
// Decrease the amount of time left on this animation
sec -= time.delta_seconds();
// Check if seconds is below 0.0
if sec < 0.0 {
sec = 0.0;
}
sec = (sec - time.delta_seconds()).max(0.0);
*dissolving = Dissolving::In(sec);
// Calculate the target percentage value
sec / dissolvable.duration
1.0 - (sec / dissolvable.duration)
}
Dissolving::Out(mut sec) => {
// Decrease the amount of time left on this animation
sec -= time.delta_seconds();
// Check if seconds is below 0.0
if sec < 0.0 {
sec = 0.0;
}
sec = (sec - time.delta_seconds()).max(0.0);
*dissolving = Dissolving::Out(sec);
// Calculate the target percentage value
(dissolvable.duration - sec) / dissolvable.duration
sec / dissolvable.duration
}
};
@ -1409,16 +1405,12 @@ fn dissolve_animation(
// Change the material's value to create animation
dissolve_material.extension.percentage = percentage;
debug!(
"Play fade out animation {:?} {:?}",
delta, dissolve_material.extension.percentage
);
},
);
// If animation is done, remove dissolving component
if percentage <= 0.0 || percentage >= 1.0 {
info!("Removing dissolving from {:?} with percentage {:?}", entity, percentage);
commands.entity(entity).remove::<Dissolving>();
}
});

Loading…
Cancel
Save