@ -22,9 +22,8 @@ impl Plugin for Display3dPlugin {
. add_systems (
. add_systems (
OnExit ( GameState ::Loading ) ,
OnExit ( GameState ::Loading ) ,
(
(
fix_skybox . before ( initialize ) ,
fix_skybox ,
initialize ,
initialize . after ( fix_skybox ) ,
update_tweaks . run_if ( resource_exists ::< tweak ::GameTweaks > ) ,
) ,
) ,
)
)
// Systems related to color and camera
// Systems related to color and camera
@ -84,6 +83,7 @@ impl Plugin for Display3dPlugin {
select
select
. run_if ( in_state ( GameState ::Play ) )
. run_if ( in_state ( GameState ::Play ) )
. run_if ( in_state ( DisplayState ::Display3d ) )
. run_if ( in_state ( DisplayState ::Display3d ) )
. run_if ( not ( in_state ( MenuState ::On ) ) )
. run_if ( just_pressed ( MouseButton ::Left ) ) ,
. run_if ( just_pressed ( MouseButton ::Left ) ) ,
pick_up . run_if ( any_component_added ::< game ::Selected > ( ) ) ,
pick_up . run_if ( any_component_added ::< game ::Selected > ( ) ) ,
put_down . run_if ( any_component_removed ::< game ::Selected > ( ) ) ,
put_down . run_if ( any_component_removed ::< game ::Selected > ( ) ) ,
@ -221,7 +221,7 @@ fn load_assets(
/// Initialize the board and pieces
/// Initialize the board and pieces
fn initialize ( mut commands : Commands , board : Res < game ::Board > , assets : Res < AssetsMap > ) {
fn initialize ( mut commands : Commands , board : Res < game ::Board > , assets : Res < AssetsMap > ) {
info ! ( "Initializing root" ) ;
debug ! ( "Initializing root" ) ;
commands
commands
. spawn ( (
. spawn ( (
SpatialBundle {
SpatialBundle {
@ -232,7 +232,7 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
DisplayState ::Display3d ,
DisplayState ::Display3d ,
) )
) )
. with_children ( | parent | {
. with_children ( | parent | {
info ! ( "Intializing 3D Board!" ) ;
debug ! ( "Intializing 3D Board!" ) ;
parent
parent
. spawn ( (
. spawn ( (
Display3d ,
Display3d ,
@ -330,7 +330,7 @@ fn hydrate_camera(
. iter ( )
. iter ( )
. filter ( | ( name , _ ) | name . as_str ( ) = = "GameCam" )
. filter ( | ( name , _ ) | name . as_str ( ) = = "GameCam" )
. for_each ( | ( _ , entity ) | {
. for_each ( | ( _ , entity ) | {
info ! ( "Initialize 3d camera" ) ;
debug ! ( "Initialize 3d camera" ) ;
let skybox_handle = tweak
let skybox_handle = tweak
. get_handle ::< Image > ( "display3d_models_skybox_file" )
. get_handle ::< Image > ( "display3d_models_skybox_file" )
. unwrap ( ) ;
. unwrap ( ) ;
@ -339,7 +339,7 @@ fn hydrate_camera(
. get ::< f32 > ( "display3d_environment_map_light_intensity" )
. get ::< f32 > ( "display3d_environment_map_light_intensity" )
. unwrap ( ) ;
. unwrap ( ) ;
info ! ( "Hydrating camera {:?}" , entity ) ;
debug ! ( "Hydrating camera {:?}" , entity ) ;
// Populate the components for the camera
// Populate the components for the camera
commands . entity ( entity ) . insert ( (
commands . entity ( entity ) . insert ( (
DisplayState ::Display3d ,
DisplayState ::Display3d ,
@ -446,7 +446,7 @@ fn fix_skybox(
. unwrap ( ) ;
. unwrap ( ) ;
let image = images . get_mut ( handle ) . unwrap ( ) ;
let image = images . get_mut ( handle ) . unwrap ( ) ;
info ! ( "Loaded skybox image" ) ;
debug ! ( "Loaded skybox image" ) ;
// NOTE: PNGs do not have any metadata that could indicate they contain a cubemap texture,
// NOTE: PNGs do not have any metadata that could indicate they contain a cubemap texture,
// so they appear as one texture. The following code reconfigures the texture as necessary.
// so they appear as one texture. The following code reconfigures the texture as necessary.
if image . texture_descriptor . array_layer_count ( ) = = 1 {
if image . texture_descriptor . array_layer_count ( ) = = 1 {
@ -470,7 +470,7 @@ fn set_board_model(
. get ( tweaks_file . handle . clone ( ) )
. get ( tweaks_file . handle . clone ( ) )
. expect ( "Load tweakfile" ) ;
. expect ( "Load tweakfile" ) ;
boards . iter_mut ( ) . for_each ( | mut handle | {
boards . iter_mut ( ) . for_each ( | mut handle | {
info ! ( "Setting board model" ) ;
debug ! ( "Setting board model" ) ;
let assets_handle = tweak
let assets_handle = tweak
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. unwrap ( ) ;
. unwrap ( ) ;
@ -503,7 +503,7 @@ fn set_title_model(
titles
titles
. iter_mut ( )
. iter_mut ( )
. for_each ( | ( mut handle , mut transform , mut visibility ) | {
. for_each ( | ( mut handle , mut transform , mut visibility ) | {
info ! ( "Setting title model" ) ;
debug ! ( "Setting title model" ) ;
let assets_handle = tweak
let assets_handle = tweak
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. unwrap ( ) ;
. unwrap ( ) ;
@ -546,7 +546,7 @@ fn board_translation(&BoardIndex { x, y }: &BoardIndex) -> Vec3 {
}
}
fn capture_translation ( side : & Side , num : usize ) -> Vec3 {
fn capture_translation ( side : & Side , num : usize ) -> Vec3 {
info ! ( "Side: {:?} Num: {:?}" , side , num ) ;
debug ! ( "Side: {:?} Num: {:?}" , side , num ) ;
let x = 5.0 - ( ( num % 4 ) as f32 * 1.3 ) ;
let x = 5.0 - ( ( num % 4 ) as f32 * 1.3 ) ;
let y = - 1.3 ;
let y = - 1.3 ;
let z = 4.0 + ( ( num / 4 ) as f32 * 1.3 ) ;
let z = 4.0 + ( ( num / 4 ) as f32 * 1.3 ) ;
@ -634,7 +634,7 @@ fn update_pieces(
// Set position of piece
// Set position of piece
let new_translation = board_translation ( board_index ) ;
let new_translation = board_translation ( board_index ) ;
if transform . translation ! = new_translation {
if transform . translation ! = new_translation {
info ! ( "Updating piece transform" ) ;
debug ! ( "Updating piece transform" ) ;
transform . translation = new_translation ;
transform . translation = new_translation ;
}
}
@ -644,7 +644,7 @@ fn update_pieces(
. count ( ) ;
. count ( ) ;
if animating > 0 {
if animating > 0 {
info ! ( "Piece {:?} is animating. Skipping..." , entity ) ;
debug ! ( "Piece {:?} is animating. Skipping..." , entity ) ;
} else {
} else {
debug ! ( "Checking piece object scene for {:?}" , entity ) ;
debug ! ( "Checking piece object scene for {:?}" , entity ) ;
@ -679,7 +679,6 @@ fn select(
selected : Query < Entity , With < game ::Selected > > ,
selected : Query < Entity , With < game ::Selected > > ,
state : Res < State < game ::TurnState > > ,
state : Res < State < game ::TurnState > > ,
) {
) {
// info!("Board index selected: {:?}", board_index);
match * piece {
match * piece {
PiecePointer ( Some ( e ) ) = > {
PiecePointer ( Some ( e ) ) = > {
query . get ( e ) . iter ( ) . for_each ( | ( board_index , side ) | {
query . get ( e ) . iter ( ) . for_each ( | ( board_index , side ) | {
@ -799,7 +798,7 @@ fn set_valid_move_model(
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. unwrap ( ) ;
. unwrap ( ) ;
if let Some ( gltf ) = gltfs . get ( assets_handle ) {
if let Some ( gltf ) = gltfs . get ( assets_handle ) {
info ! ( "Setting valid move model" ) ;
debug ! ( "Setting valid move model" ) ;
events . iter_mut ( ) . for_each ( | ( mut handle , mut visibility ) | {
events . iter_mut ( ) . for_each ( | ( mut handle , mut visibility ) | {
* handle = gltf
* handle = gltf
@ -834,19 +833,19 @@ fn pick_up(
. get ( tweaks_file . handle . clone ( ) )
. get ( tweaks_file . handle . clone ( ) )
. expect ( "Load tweakfile" ) ;
. expect ( "Load tweakfile" ) ;
events . iter_mut ( ) . for_each ( | ( entity , piece ) | {
events . iter_mut ( ) . for_each ( | ( entity , piece ) | {
info ! ( "Picking up piece" ) ;
debug ! ( "Picking up piece" ) ;
let assets_handle = tweak
let assets_handle = tweak
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. unwrap ( ) ;
. unwrap ( ) ;
let gltf = gltfs . get ( assets_handle ) . expect ( "Load GLTF content" ) ;
let gltf = gltfs . get ( assets_handle ) . expect ( "Load GLTF content" ) ;
info ! ( "Pickup animation for {:?}" , entity ) ;
debug ! ( "Pickup animation for {:?}" , entity ) ;
children . iter_descendants ( entity ) . for_each ( | child | {
children . iter_descendants ( entity ) . for_each ( | child | {
info ! ( " Child: {:?}" , child ) ;
debug ! ( " Child: {:?}" , child ) ;
if let Ok ( ( name , mut player ) ) = players . get_mut ( child ) {
if let Ok ( ( name , mut player ) ) = players . get_mut ( child ) {
let pickup_animation =
let pickup_animation =
format! ( "display3d_models_animations_pick_up_{}" , name . as_str ( ) , ) ;
format! ( "display3d_models_animations_pick_up_{}" , name . as_str ( ) , ) ;
info ! (
debug ! (
"Picking up {:?} ({:?}) {:?} {:?}" ,
"Picking up {:?} ({:?}) {:?} {:?}" ,
name , entity , piece , pickup_animation
name , entity , piece , pickup_animation
) ;
) ;
@ -905,7 +904,7 @@ fn put_down(
. expect ( "Load tweakfile" ) ;
. expect ( "Load tweakfile" ) ;
events . read ( ) . for_each ( | entity | {
events . read ( ) . for_each ( | entity | {
if let Ok ( _ ) = query . get_mut ( entity ) {
if let Ok ( _ ) = query . get_mut ( entity ) {
info ! ( "Putting down piece" ) ;
debug ! ( "Putting down piece" ) ;
let assets_handle = tweak
let assets_handle = tweak
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
. get_handle ::< Gltf > ( "display3d_models_assets_file" )
@ -913,7 +912,7 @@ fn put_down(
let gltf = gltfs . get ( assets_handle ) . expect ( "Load GLTF content" ) ;
let gltf = gltfs . get ( assets_handle ) . expect ( "Load GLTF content" ) ;
children . iter_descendants ( entity ) . for_each ( | child | {
children . iter_descendants ( entity ) . for_each ( | child | {
if let Ok ( ( name , mut player ) ) = players . get_mut ( child ) {
if let Ok ( ( name , mut player ) ) = players . get_mut ( child ) {
info ! ( "Putting down {:?}" , entity ) ;
debug ! ( "Putting down {:?}" , entity ) ;
let putdown_animation =
let putdown_animation =
format! ( "display3d_models_animations_put_down_{}" , name . as_str ( ) ) ;
format! ( "display3d_models_animations_put_down_{}" , name . as_str ( ) ) ;
let putdown_handle = gltf
let putdown_handle = gltf
@ -927,7 +926,7 @@ fn put_down(
. expect ( "PutDown Animation" ) ;
. expect ( "PutDown Animation" ) ;
if let Some ( putdown_clip ) = clips . get ( putdown_handle ) {
if let Some ( putdown_clip ) = clips . get ( putdown_handle ) {
if putdown_clip . compatible_with ( name ) {
if putdown_clip . compatible_with ( name ) {
info ! ( "Compatible with put-down clip!" ) ;
debug ! ( "Compatible with put-down clip!" ) ;
player
player
. start_with_transition (
. start_with_transition (
putdown_handle . clone ( ) ,
putdown_handle . clone ( ) ,
@ -935,20 +934,20 @@ fn put_down(
)
)
. set_repeat ( RepeatAnimation ::Never ) ;
. set_repeat ( RepeatAnimation ::Never ) ;
} else {
} else {
info ! (
debug ! (
"Clip {:?}({:?}) not compatible with {:?}" ,
"Clip {:?}({:?}) not compatible with {:?}" ,
putdown_animation , putdown_clip , name
putdown_animation , putdown_clip , name
) ;
) ;
}
}
} else {
} else {
info ! ( "Clip not found" ) ;
debug ! ( "Clip not found" ) ;
}
}
} else {
} else {
info ! ( "Player not found" ) ;
debug ! ( "Player not found" ) ;
}
}
} )
} )
} else {
} else {
info ! ( "Piece+Side not found for entity" ) ;
debug ! ( "Piece+Side not found for entity" ) ;
}
}
} )
} )
}
}
@ -957,7 +956,7 @@ fn set_tile_hitbox(
mut events : Query < ( & mut Transform , & BoardIndex ) , ( With < Display3d > , Added < game ::Tile > ) > ,
mut events : Query < ( & mut Transform , & BoardIndex ) , ( With < Display3d > , Added < game ::Tile > ) > ,
) {
) {
events . iter_mut ( ) . for_each ( | ( mut transform , index ) | {
events . iter_mut ( ) . for_each ( | ( mut transform , index ) | {
info ! ( "Setting tile hitbox" ) ;
debug ! ( "Setting tile hitbox" ) ;
* transform = Transform ::from_translation ( board_translation ( index ) ) ;
* transform = Transform ::from_translation ( board_translation ( index ) ) ;
} ) ;
} ) ;
@ -965,7 +964,7 @@ 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 > ) > ) {
players . iter_mut ( ) . for_each ( | mut player | {
players . iter_mut ( ) . for_each ( | mut player | {
info ! ( "Playing intro camera animation" ) ;
debug ! ( "Playing intro camera animation" ) ;
player . resume ( )
player . resume ( )
} ) ;
} ) ;
}
}
@ -1009,7 +1008,7 @@ fn switch_sides(
. unwrap ( ) ;
. unwrap ( ) ;
let gltf = gltfs . get ( assets_handle ) . expect ( "Load GLTF content" ) ;
let gltf = gltfs . get ( assets_handle ) . expect ( "Load GLTF content" ) ;
players . iter_mut ( ) . for_each ( | mut player | {
players . iter_mut ( ) . for_each ( | mut player | {
info ! ( "Switching sides" ) ;
debug ! ( "Switching sides" ) ;
let animation = match state . get ( ) {
let animation = match state . get ( ) {
game ::TurnState ( game ::Side ::A ) = > gltf . named_animations . get (
game ::TurnState ( game ::Side ::A ) = > gltf . named_animations . get (
@ -1072,7 +1071,7 @@ fn setup_dissolve_materials(
. filter ( | ( child , _ , _ ) | query . iter_many ( parents . iter_ancestors ( * child ) ) . count ( ) > 0 )
. filter ( | ( child , _ , _ ) | query . iter_many ( parents . iter_ancestors ( * child ) ) . count ( ) > 0 )
// Handle this entity (mesh)
// Handle this entity (mesh)
. for_each ( | ( child , std_handle , name ) | {
. for_each ( | ( child , std_handle , name ) | {
info ! ( "Setting up dissolve material for {:?} {:?}" , name , child ) ;
debug ! ( "Setting up dissolve material for {:?} {:?}" , name , child ) ;
// Get dissolvable data for percentage start
// Get dissolvable data for percentage start
let dissolvable = query
let dissolvable = query
@ -1138,7 +1137,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!" ) ;
debug ! ( "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
@ -1150,7 +1149,7 @@ fn capture_piece(
. expect ( "Visibility and Transform of captured piece" ) ;
. expect ( "Visibility and Transform of captured piece" ) ;
// HACK: This is dirty. Why side, but score.captures(!side)?
// HACK: This is dirty. Why side, but score.captures(!side)?
info ! (
debug ! (
"Capture translation: ({:?}, {:?}) {:?}" ,
"Capture translation: ({:?}, {:?}) {:?}" ,
side ,
side ,
score . captures ( ! * side ) . saturating_sub ( 1 ) ,
score . captures ( ! * side ) . saturating_sub ( 1 ) ,
@ -1168,7 +1167,7 @@ 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!" ) ;
debug ! ( "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 ( ) ;
@ -1215,14 +1214,14 @@ fn monitor_animations(
// Remove Animating component from players that are done
// Remove Animating component from players that are done
active . iter ( ) . for_each ( | ( entity , player ) | {
active . iter ( ) . for_each ( | ( entity , player ) | {
if player . is_finished ( ) {
if player . is_finished ( ) {
info ! ( "Entity {:?} is done, removing animating marker" , entity ) ;
debug ! ( "Entity {:?} is done, removing animating marker" , entity ) ;
commands . entity ( entity ) . remove ::< Animating > ( ) ;
commands . entity ( entity ) . remove ::< Animating > ( ) ;
}
}
} ) ;
} ) ;
// Set inactive entities to active
// Set inactive entities to active
inactive . iter_mut ( ) . for_each ( | ( entity , mut player ) | {
inactive . iter_mut ( ) . for_each ( | ( entity , mut player ) | {
if ! player . is_finished ( ) & & * player . animation_clip ( ) ! = Handle ::< AnimationClip > ::default ( ) {
if ! player . is_finished ( ) & & * player . animation_clip ( ) ! = Handle ::< AnimationClip > ::default ( ) {
info ! (
debug ! (
"Entity {:?} is playing {:?}, adding animating marker" ,
"Entity {:?} is playing {:?}, adding animating marker" ,
entity ,
entity ,
player . animation_clip ( )
player . animation_clip ( )
@ -1328,7 +1327,7 @@ fn dissolve_animation(
// 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 ! (
debug ! (
"Removing dissolving from {:?} with percentage {:?}" ,
"Removing dissolving from {:?} with percentage {:?}" ,
entity , percentage
entity , percentage
) ;
) ;
@ -1485,3 +1484,4 @@ fn animate_title_light_out(
} )
} )
} ) ;
} ) ;
}
}