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