@ -12,7 +12,6 @@ impl Plugin for Display3dPlugin {
TemporalAntiAliasPlugin ,
MaterialPlugin ::< DissolveMaterial > ::default ( ) ,
) )
. init_state ::< DissolvingAnimation > ( )
. init_resource ::< PiecePointer > ( )
. init_resource ::< AnimationSpeed > ( )
. insert_resource ( Msaa ::Off )
@ -122,18 +121,9 @@ impl Plugin for Display3dPlugin {
. run_if ( in_state ( GameState ::Play ) )
. run_if ( in_state ( DisplayState ::Display3d ) ) ,
)
. add_systems (
Update ,
(
animate_title_light_in . run_if ( in_state ( DissolvingAnimation ::In ) ) ,
animate_title_light_out . run_if ( in_state ( DissolvingAnimation ::Out ) ) ,
) ,
)
. add_systems (
OnEnter ( GameState ::Intro ) ,
(
// Toggle hidden/visible 3d entities
manage_state_entities ::< DisplayState > ( ) ,
color_grading_tweak . run_if ( resource_exists ::< tweak ::GameTweaks > ) ,
fog_tweak . run_if ( resource_exists ::< tweak ::GameTweaks > ) ,
bloom_tweak . run_if ( resource_exists ::< tweak ::GameTweaks > ) ,
@ -191,20 +181,11 @@ pub(crate) enum Dissolving {
Out ( f32 ) ,
}
#[ derive(Debug, States, Hash, Default, PartialEq, Eq, Clone, Component) ]
enum DissolvingAnimation {
#[ default ]
None ,
In ,
Out ,
}
#[ derive(Debug, Resource) ]
pub ( crate ) struct AnimationSpeed {
pub movement : f32 ,
pub text : f32 ,
pub dissolve : f32 ,
pub light : f32 ,
}
impl Default for AnimationSpeed {
@ -213,7 +194,6 @@ impl Default for AnimationSpeed {
movement : 1.0 ,
text : 1.0 ,
dissolve : 1.0 ,
light : 1.0 ,
}
}
}
@ -252,7 +232,6 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
commands
. spawn ( (
SpatialBundle {
visibility : Visibility ::Hidden ,
.. default ( )
} ,
Display3d ,
@ -260,12 +239,37 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
) )
. with_children ( | parent | {
debug ! ( "Intializing 3D Board!" ) ;
// Title
parent . spawn ( (
DisplayState ::Display3d ,
Display3d ,
// GameState::Title,
SceneBundle {
visibility : Visibility ::Hidden ,
.. default ( )
} ,
TitleText ,
Dissolvable {
start : 0.0 ,
duration : 6.0 ,
} , // Marks title text as dissolving
) ) ;
// Board
parent
. spawn ( (
Display3d ,
DisplayState ::Display3d ,
game ::BoardComponent ,
SceneBundle { .. default ( ) } ,
SceneBundle {
visibility : Visibility ::Hidden ,
.. default ( )
} ,
Dissolvable {
start : 0.0 ,
duration : 6.0 ,
} , // Marks pieces as dissolving
) )
. with_children ( | parent | {
// Hitboxes
@ -323,6 +327,7 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
* piece ,
* index ,
SceneBundle {
visibility : Visibility ::Hidden ,
transform ,
.. default ( )
} ,
@ -333,19 +338,6 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
} , // Marks pieces as dissolving
) ) ;
} ) ;
// Title
parent . spawn ( (
DisplayState ::Display3d ,
Display3d ,
// GameState::Title,
SceneBundle { .. default ( ) } ,
TitleText ,
Dissolvable {
start : 0.0 ,
duration : 6.0 ,
} , // Marks title text as dissolving
) ) ;
} ) ;
} ) ;
}
@ -1010,14 +1002,20 @@ fn set_tile_hitbox(
} ) ;
}
fn opening_animation ( mut players : Query < & mut AnimationPlayer , ( With < Camera > , With < Display3d > ) > ) {
fn opening_animation (
mut players : Query < & mut AnimationPlayer , ( With < Camera > , With < Display3d > ) > ,
mut query : Query < ( Entity , & Dissolvable ) , Or < ( With < BoardComponent > , With < Piece > ) > > ,
mut commands : Commands ,
) {
players . iter_mut ( ) . for_each ( | mut player | {
debug ! ( "Playing intro camera animation" ) ;
player . resume ( )
} ) ;
query . iter_mut ( ) . for_each ( | ( e , d ) | {
commands . entity ( e ) . insert ( Dissolving ::In ( d . duration ) ) ;
} ) ;
}
fn set_animation_speed (
mut animation_speed : ResMut < AnimationSpeed > ,
tweaks : Res < Assets < Tweaks > > ,
@ -1032,8 +1030,7 @@ fn set_animation_speed(
let movement = tweak . get ::< f32 > ( "animation_fast_movement_speed" ) . unwrap ( ) ;
let text = tweak . get ::< f32 > ( "animation_fast_text_speed" ) . unwrap ( ) ;
let dissolve = tweak . get ::< f32 > ( "animation_fast_dissolve_speed" ) . unwrap ( ) ;
let light = tweak . get ::< f32 > ( "animation_fast_light_speed" ) . unwrap ( ) ;
AnimationSpeed { movement , text , dissolve , light }
AnimationSpeed { movement , text , dissolve }
} else {
AnimationSpeed ::default ( )
} ;
@ -1253,26 +1250,22 @@ fn monitor_animations(
fn intro_title_dissolve (
mut query : Query < ( Entity , & Dissolvable ) , With < TitleText > > ,
mut commands : Commands ,
mut next : ResMut < NextState < DissolvingAnimation > > ,
) {
query . iter_mut ( ) . for_each ( | ( entity , dissolving ) | {
commands
. entity ( entity )
. insert ( Dissolving ::In ( dissolving . duration ) ) ;
next . set ( DissolvingAnimation ::In ) ;
} ) ;
}
fn outro_title_dissolve (
mut query : Query < ( Entity , & Dissolvable ) , With < TitleText > > ,
mut commands : Commands ,
mut next : ResMut < NextState < DissolvingAnimation > > ,
) {
query . iter_mut ( ) . for_each ( | ( entity , dissolving ) | {
commands
. entity ( entity )
. insert ( Dissolving ::Out ( dissolving . duration ) ) ;
next . set ( DissolvingAnimation ::Out ) ;
} ) ;
}
@ -1285,19 +1278,18 @@ 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 , & Dissolvable , & mut Dissolving )> ,
mut query : Query < ( Entity , & Dissolvable , & mut Dissolving , & mut Visibility )> ,
children : Query < & Children > ,
// Used to create Handle<DissolveMaterial>
mut dissolve_materials : ResMut < Assets < DissolveMaterial > > ,
object_materials : Query < ( Entity , & Handle < DissolveMaterial > ) > ,
mut commands : Commands ,
time : Res < Time > ,
mut next : ResMut < NextState < DissolvingAnimation > > ,
animation_speed : Res < AnimationSpeed > ,
) {
query
. iter_mut ( )
. for_each ( | ( entity , dissolvable , mut dissolving )| {
. for_each ( | ( entity , dissolvable , mut dissolving , mut visibility )| {
debug ! ( "Entity {:?} has Dissolving {:?}" , entity , dissolving ) ;
let percentage = match * dissolving {
@ -1307,6 +1299,10 @@ fn dissolve_animation(
* dissolving = Dissolving ::In ( sec ) ;
if * visibility ! = Visibility ::Inherited {
* visibility = Visibility ::Inherited
}
// Calculate the target percentage value
1.0 - ( sec / dissolvable . duration )
}
@ -1316,6 +1312,10 @@ fn dissolve_animation(
* dissolving = Dissolving ::Out ( sec ) ;
if sec < = 0.0 {
* visibility = Visibility ::Hidden ;
}
// Calculate the target percentage value
sec / dissolvable . duration
}
@ -1338,8 +1338,9 @@ fn dissolve_animation(
"Removing dissolving from {:?} with percentage {:?}" ,
entity , percentage
) ;
// info!("Removing dissolving marker from {:?}", entity);
commands . entity ( entity ) . remove ::< Dissolving > ( ) ;
next . set ( DissolvingAnimation ::None ) ;
}
} ) ;
}
@ -1415,68 +1416,3 @@ fn bloom_tweak(
bloom . intensity = tweak . get ::< f32 > ( "color_bloom_intensity" ) . unwrap ( ) ;
} )
}
fn animate_title_light_in (
mut query : Query < ( Entity , & mut Visibility ) , With < TitleText > > ,
children : Query < & Children > ,
mut lights : Query < & mut SpotLight > ,
mut t : Local < Timer > ,
mut started : Local < bool > ,
time : Res < Time > ,
animation_speed : Res < AnimationSpeed > ,
) {
// Over 6 seconds, fade in to 600 intensity
if ! ( * started ) {
* t = Timer ::from_seconds ( 6.0 , TimerMode ::Once ) ;
* started = true
} else {
t . tick ( Duration ::from_secs_f32 ( time . delta_seconds ( ) * animation_speed . light ) ) ;
}
let intensity = t . fraction ( ) * 409800.0 ;
query . iter_mut ( ) . for_each ( | ( e , mut v ) | {
if * v = = Visibility ::Hidden {
* v = Visibility ::Inherited ;
}
children . iter_descendants ( e ) . for_each ( | c | {
if let Ok ( mut spot_light ) = lights . get_mut ( c ) {
spot_light . intensity = intensity ;
}
} )
} ) ;
}
fn animate_title_light_out (
mut query : Query < ( Entity , & mut Visibility ) , With < TitleText > > ,
children : Query < & Children > ,
mut lights : Query < & mut SpotLight > ,
mut t : Local < Timer > ,
mut started : Local < bool > ,
time : Res < Time > ,
animation_speed : Res < AnimationSpeed > ,
) {
// Over 6 seconds, fade in to 600 intensity
if ! ( * started ) {
* t = Timer ::from_seconds ( 3.0 , TimerMode ::Once ) ;
* started = true
} else {
t . tick ( Duration ::from_secs_f32 ( time . delta_seconds ( ) * animation_speed . light ) ) ;
}
let intensity = ( 1.0 - t . fraction ( ) ) * 409800.0 ;
query . iter_mut ( ) . for_each ( | ( e , mut v ) | {
if * v = = Visibility ::Hidden {
* v = Visibility ::Inherited ;
}
children . iter_descendants ( e ) . for_each ( | c | {
if let Ok ( mut spot_light ) = lights . get_mut ( c ) {
spot_light . intensity = intensity ;
}
} )
} ) ;
}