From df1a2a3bf77680ba0231dc8611799f0a6db37a24 Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Mon, 29 Apr 2024 22:05:49 -0700 Subject: [PATCH] put-down animation works! Thank christ --- assets/martian.tweak.toml | 36 ++++++++++++------------ src/debug.rs | 59 ++++++++++++++++++++++++++++++++++++++- src/display3d.rs | 49 ++++++++++++++++---------------- 3 files changed, 100 insertions(+), 44 deletions(-) diff --git a/assets/martian.tweak.toml b/assets/martian.tweak.toml index b005af7..c92d8f4 100644 --- a/assets/martian.tweak.toml +++ b/assets/martian.tweak.toml @@ -199,28 +199,28 @@ turn_b = "GameCamSide2>1" turn_a = "GameCamSide1>2" [display3d.models.animations.pick_up] -pawn_blue = "PawnBluePiecePickup" -pawn_red = "PawnRedPiecePickup" -drone_blue = "DroneBluePiecePickup" -drone_red = "DroneRedPiecePickup" -queen_blue = "QueenBluePiecePickup" -queen_red = "QueenRedPiecePickup" +PawnBlue = "PawnBluePiecePickup" +PawnRed = "PawnRedPiecePickup" +DroneBlue = "DroneBluePiecePickup" +DroneRed = "DroneRedPiecePickup" +QueenBlue = "QueenBluePiecePickup" +QueenRed = "QueenRedPiecePickup" [display3d.models.animations.put_down] -pawn_blue = "PawnBluePiecePutDown" -pawn_red = "PawnRedPiecePutDown" -drone_blue = "DroneBluePiecePutDown" -drone_red = "DroneRedPiecePutDown" -queen_blue = "QueenBluePiecePutDown" -queen_red = "QueenRedPiecePutDown" +PawnBlue = "PawnBluePiecePutDown" +PawnRed = "PawnRedPiecePutDown" +DroneBlue = "DroneBluePiecePutDown" +DroneRed = "DroneRedPiecePutDown" +QueenBlue = "QueenBluePiecePutDown" +QueenRed = "QueenRedPiecePutDown" [display3d.models.animations.idle] -pawn_blue = "PawnBluePieceIdle" -pawn_red = "PawnRedPieceIdle" -drone_blue = "DroneBluePieceIdle" -drone_red = "DroneRedPieceIdle" -queen_blue = "QueenBluePieceIdle" -queen_red = "QueenRedPieceIdle" +PawnBlue = "PawnBluePieceIdle" +PawnRed = "PawnRedPieceIdle" +DroneBlue = "DroneBluePieceIdle" +DroneRed = "DroneRedPieceIdle" +QueenBlue = "QueenBluePieceIdle" +QueenRed = "QueenRedPieceIdle" ###################### diff --git a/src/debug.rs b/src/debug.rs index 2d3cb2d..1588806 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -18,6 +18,7 @@ impl Plugin for DebugPlugin { ( selected_gizmo.run_if(any_with_component::), selected_position.run_if(any_with_component::), + debug_piece.run_if(resource_changed::), ) .run_if(in_state(DebugState::Enabled)), ) @@ -65,6 +66,9 @@ pub(crate) enum DebugState { #[derive(Debug, Component)] struct DebugRoot; +#[derive(Debug, Component)] +struct DebugPiece; + fn toggle_debug_mode( mut events: EventReader, current_state: Res>, @@ -84,7 +88,7 @@ fn toggle_debug_mode( } fn toggle_debug_ui( - mut visibility: Query<&mut Visibility, With>, + mut visibility: Query<&mut Visibility, Or<(With, With)>>, current_state: Res>, ) { visibility.iter_mut().for_each(|mut vis| { @@ -118,6 +122,32 @@ fn init_debug_ui(mut commands: Commands) { DebugRoot, )); }); + + commands + .spawn(( + NodeBundle { + style: Style { + padding: UiRect::all(Val::Px(10.0)), + position_type: PositionType::Absolute, + bottom: Val::Px(0.0), + right: Val::Px(0.0), + ..default() + }, + background_color: Color::BLACK.into(), + visibility: Visibility::Hidden, + ..default() + }, + DebugPiece, + )) + .with_children(|parent| { + parent.spawn(( + TextBundle { + style: Style { ..default() }, + ..default() + }, + DebugPiece, + )); + }); } fn display_diagnostics( @@ -190,3 +220,30 @@ fn selected_position( .join(""); debug_info.set("Position".into(), val); } + +fn debug_piece( + query: Query<(Entity, Option<&Side>, Option<&Piece>, Option<&BoardIndex>, Option<&display3d::Animating>, Option<&Selected>), With>, + pointer: Res, + mut root: Query<(&mut Text, &mut Visibility), With>, + // mut commands: Commands, +) { + // query.iter().nth(1).iter().for_each(|e| { + // commands.entity(*e).log_components(); + // }); + match *pointer { + display3d::PiecePointer(Some(e)) => { + if let Ok((e, si, p, bi, a, sel)) = query.get(e) { + root.iter_mut().for_each(|(mut text, mut vis)| { + let value = format!("Entity: {:?}\nSide: {:?}\nPiece: {:?}\nBoard Index: {:?}\nAnimating: {:?}\nSelected: {:?}", e, si, p, bi, a, sel); + *text = Text::from_section(value, TextStyle { ..default() }); + *vis = Visibility::Inherited; + }); + } + }, + _ => { + root.iter_mut().for_each(|(_, mut vis)| { + *vis = Visibility::Hidden; + }); + } + } +} \ No newline at end of file diff --git a/src/display3d.rs b/src/display3d.rs index 898bac9..6388803 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -79,7 +79,7 @@ impl Plugin for Display3dPlugin { in_state(debug::DebugState::Enabled) .and_then(on_event::()) .or_else(just_pressed(MouseButton::Left)) - ), + ).before(select), select .run_if(in_state(GameState::Play)) .run_if(in_state(DisplayState::Display3d)) @@ -639,7 +639,7 @@ fn update_pieces( if animating > 0 { info!("Piece {:?} is animating. Skipping...", entity); } else { - info!("Checking piece object scene for {:?}", entity); + debug!("Checking piece object scene for {:?}", entity); // Find name of this piece's model scene let scene_tweak_name: Option = match (piece, side) { @@ -655,10 +655,10 @@ fn update_pieces( let scene_handle = models.named_scenes.get(&scene_tweak_name.unwrap()).unwrap(); // Set scene model for this piece - // if *scene != *scene_handle { - warn!("Updating scene for piece {:?}", entity); - *scene = scene_handle.clone(); - // } + if *scene != *scene_handle { + warn!("Updating scene for piece {:?}", entity); + *scene = scene_handle.clone(); + } } }, ); @@ -688,7 +688,7 @@ fn select( } #[derive(Debug, Default, Resource)] -struct PiecePointer(Option); +pub(crate) struct PiecePointer(pub Option); /// Select tiles and pieces in 3d /// There is a bug where we are selecting multiple entities... @@ -840,13 +840,11 @@ fn pick_up( children.iter_descendants(entity).for_each(|child| { info!(" Child: {:?}", child); if let Ok((name, mut player)) = players.get_mut(child) { - info!("Picking up {:?} ({:?}) {:?}", name, entity, piece); let pickup_animation = format!( - "display3d_models_animations_pick_up_{:?}_{}", - piece, - side.color_str() - ) - .to_ascii_lowercase(); + "display3d_models_animations_pick_up_{}", + name.as_str(), + ); + info!("Picking up {:?} ({:?}) {:?} {:?}", name, entity, piece, pickup_animation); let pickup_handle = gltf .named_animations .get( @@ -857,11 +855,9 @@ fn pick_up( ) .expect("Pickup Animation"); let idle_animation = format!( - "display3d_models_animations_idle_{:?}_{}", - piece, - side.color_str() - ) - .to_ascii_lowercase(); + "display3d_models_animations_idle_{}", + name.as_str() + ); let idle_handle = gltf .named_animations .get( @@ -919,12 +915,7 @@ fn put_down( children.iter_descendants(entity).for_each(|child| { if let Ok((name, mut player)) = players.get_mut(child) { info!("Putting down {:?}", entity); - let putdown_animation = format!( - "display3d_models_animations_put_down_{:?}_{}", - piece, - side.color_str() - ) - .to_ascii_lowercase(); + let putdown_animation = format!("display3d_models_animations_put_down_{}", name.as_str()); let putdown_handle = gltf .named_animations .get( @@ -943,10 +934,18 @@ fn put_down( Duration::from_secs_f32(0.75), ) .set_repeat(RepeatAnimation::Never); + } else { + info!("Clip {:?}({:?}) not compatible with {:?}", putdown_animation, putdown_clip, name); } + } else { + info!("Clip not found"); } + } else { + info!("Player not found"); } }) + } else { + info!("Piece+Side not found for entity"); } }) } @@ -1200,7 +1199,7 @@ fn debug_textures(mut events: EventReader>) { // Marker for entities which are currently animating #[derive(Component, Debug)] -struct Animating; +pub(crate) struct Animating; fn monitor_animations( active: Query<(Entity, &AnimationPlayer), (Changed, With)>,