diff --git a/src/display3d.rs b/src/display3d.rs index 25498e3..5850776 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -86,10 +86,10 @@ impl Plugin for Display3dPlugin { switch_sides .run_if(in_state(GameState::Play)) .run_if(state_changed::) - .run_if(in_state(ai::PlayState::Human)) .run_if(any_component_added::() .or_else(any_component_removed::()) - ), + ) + .run_if(should_switch_sides), // Camera moving up when first piece is selected in the game vantage_point .run_if(in_state(GameState::Play)) @@ -426,11 +426,14 @@ fn hydrate_camera( .get::("display3d_environment_map_light_intensity") .unwrap(); + let side = state.get().0; + debug!("Hydrating camera {:?}", entity); // Populate the components for the camera commands.entity(entity).insert(( DisplayState::Display3d, Display3d, + side, Camera3dBundle { camera: Camera { is_active: true, @@ -996,8 +999,23 @@ fn set_animation_player_speed( }) } +fn should_switch_sides( + query: Query<&Side, (With, With)>, + state: Res>, +) -> bool { + query.iter().all(|side| { + match state.get() { + ai::PlayState::AiBogo => match side { + Side::A => true, + Side::B => false, + } + ai::PlayState::Human => true, + } + }) +} + fn switch_sides( - mut players: Query<&mut AnimationPlayer, (With, With)>, + mut players: Query<(&mut AnimationPlayer, &mut Side), (With, With)>, gltfs: Res>, state: Res>, tweaks: Res>, @@ -1010,9 +1028,7 @@ fn switch_sides( .get_handle::("display3d_models_assets_file") .unwrap(); let gltf = gltfs.get(assets_handle).expect("Load GLTF content"); - players.iter_mut().for_each(|mut player| { - debug!("Switching sides"); - + players.iter_mut().for_each(|(mut player, mut side)| { let animation_key = match state.get() { game::TurnState(game::Side::A) => "display3d_models_animations_turn_a", game::TurnState(game::Side::B) => "display3d_models_animations_turn_b", @@ -1023,6 +1039,7 @@ fn switch_sides( animation.clone(), Duration::from_secs_f32(1.00), ); + *side = state.get().0; }); }