|
|
|
|
@ -36,7 +36,8 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
any_component_changed::<Piece>()
|
|
|
|
|
.or_else(any_component_changed::<Side>())
|
|
|
|
|
.or_else(any_component_changed::<BoardIndex>())
|
|
|
|
|
)
|
|
|
|
|
.or_else(any_component_removed::<Animating>()),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
set_board_model.run_if(any_component_added::<game::BoardComponent>()),
|
|
|
|
|
set_valid_move_model.run_if(any_component_added::<game::ValidMove>()),
|
|
|
|
|
@ -52,6 +53,7 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
skip_animation
|
|
|
|
|
.run_if(just_pressed(KeyCode::Enter).or_else(just_pressed(MouseButton::Left)))
|
|
|
|
|
.run_if(in_state(GameState::Play)),
|
|
|
|
|
monitor_animations.run_if(in_state(GameState::Play)),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
@ -369,15 +371,8 @@ fn fix_skybox(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn set_board_model(
|
|
|
|
|
mut boards: Query<
|
|
|
|
|
&mut Handle<Scene>,
|
|
|
|
|
(
|
|
|
|
|
Added<game::BoardComponent>,
|
|
|
|
|
With<Display3d>,
|
|
|
|
|
),
|
|
|
|
|
>,
|
|
|
|
|
mut boards: Query<&mut Handle<Scene>, (Added<game::BoardComponent>, With<Display3d>)>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
tweaks: Res<Assets<Tweaks>>,
|
|
|
|
|
tweaks_file: Res<tweak::GameTweaks>,
|
|
|
|
|
@ -484,7 +479,16 @@ fn mouse_zoom(
|
|
|
|
|
// The dumbest way to achieve this goal
|
|
|
|
|
// Essentially we iterate over every piece and set the appropriate model and texture
|
|
|
|
|
fn update_pieces(
|
|
|
|
|
mut query: Query<(Entity, &Piece, &Side, &BoardIndex, &mut Transform, &mut Handle<Scene>, &AnimationPlayer)>,
|
|
|
|
|
mut query: Query<(
|
|
|
|
|
Entity,
|
|
|
|
|
&Piece,
|
|
|
|
|
&Side,
|
|
|
|
|
&BoardIndex,
|
|
|
|
|
&mut Transform,
|
|
|
|
|
&mut Handle<Scene>,
|
|
|
|
|
)>,
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
active_animation_players: Query<&AnimationPlayer, With<Animating>>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
tweaks: Res<Assets<Tweaks>>,
|
|
|
|
|
tweaks_file: Res<tweak::GameTweaks>,
|
|
|
|
|
@ -497,8 +501,8 @@ fn update_pieces(
|
|
|
|
|
.unwrap();
|
|
|
|
|
let models = gltfs.get(assets_handle).unwrap();
|
|
|
|
|
|
|
|
|
|
query.iter_mut().for_each(|(entity, piece, side, board_index, mut transform, mut scene, animation_player)| {
|
|
|
|
|
|
|
|
|
|
query.iter_mut().for_each(
|
|
|
|
|
|(entity, piece, side, board_index, mut transform, mut scene)| {
|
|
|
|
|
// Set position of piece
|
|
|
|
|
let new_translation = board_translation(board_index);
|
|
|
|
|
if transform.translation != new_translation {
|
|
|
|
|
@ -506,29 +510,24 @@ fn update_pieces(
|
|
|
|
|
transform.translation = new_translation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if animation_player.is_finished() {
|
|
|
|
|
info!("Updating piece object scene");
|
|
|
|
|
// Check if any children are animating
|
|
|
|
|
let animating = active_animation_players
|
|
|
|
|
.iter_many(children.iter_descendants(entity))
|
|
|
|
|
.count();
|
|
|
|
|
|
|
|
|
|
if animating > 0 {
|
|
|
|
|
debug!("Piece {:?} is animating. Skipping...", entity);
|
|
|
|
|
} else {
|
|
|
|
|
debug!("Checking piece object scene for {:?}", entity);
|
|
|
|
|
|
|
|
|
|
// Find name of this piece's model scene
|
|
|
|
|
let scene_tweak_name: Option<String> = match (piece, side) {
|
|
|
|
|
(Piece::Pawn, Side::A) => {
|
|
|
|
|
tweak.get("display3d_models_scenes_pawn_red")
|
|
|
|
|
},
|
|
|
|
|
(Piece::Pawn, Side::B) => {
|
|
|
|
|
tweak.get("display3d_models_scenes_pawn_blue")
|
|
|
|
|
}
|
|
|
|
|
(Piece::Drone, Side::A) => {
|
|
|
|
|
tweak.get("display3d_models_scenes_drone_red")
|
|
|
|
|
},
|
|
|
|
|
(Piece::Drone, Side::B) => {
|
|
|
|
|
tweak.get("display3d_models_scenes_drone_blue")
|
|
|
|
|
}
|
|
|
|
|
(Piece::Queen, Side::A) => {
|
|
|
|
|
tweak.get("display3d_models_scenes_queen_red")
|
|
|
|
|
},
|
|
|
|
|
(Piece::Queen, Side::B) => {
|
|
|
|
|
tweak.get("display3d_models_scenes_queen_blue")
|
|
|
|
|
}
|
|
|
|
|
(Piece::Pawn, Side::A) => tweak.get("display3d_models_scenes_pawn_red"),
|
|
|
|
|
(Piece::Pawn, Side::B) => tweak.get("display3d_models_scenes_pawn_blue"),
|
|
|
|
|
(Piece::Drone, Side::A) => tweak.get("display3d_models_scenes_drone_red"),
|
|
|
|
|
(Piece::Drone, Side::B) => tweak.get("display3d_models_scenes_drone_blue"),
|
|
|
|
|
(Piece::Queen, Side::A) => tweak.get("display3d_models_scenes_queen_red"),
|
|
|
|
|
(Piece::Queen, Side::B) => tweak.get("display3d_models_scenes_queen_blue"),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Get model scene for this piece
|
|
|
|
|
@ -540,7 +539,8 @@ fn update_pieces(
|
|
|
|
|
*scene = scene_handle.clone();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Select tiles and pieces in 3d
|
|
|
|
|
@ -694,8 +694,12 @@ fn pick_up(
|
|
|
|
|
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();
|
|
|
|
|
let pickup_animation = format!(
|
|
|
|
|
"display3d_models_animations_pick_up_{:?}_{}",
|
|
|
|
|
piece,
|
|
|
|
|
side.color_str()
|
|
|
|
|
)
|
|
|
|
|
.to_ascii_lowercase();
|
|
|
|
|
let pickup_handle = gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(
|
|
|
|
|
@ -705,8 +709,12 @@ fn pick_up(
|
|
|
|
|
.as_str(),
|
|
|
|
|
)
|
|
|
|
|
.expect("Pickup Animation");
|
|
|
|
|
let idle_animation =
|
|
|
|
|
format!("display3d_models_animations_idle_{:?}_{}", piece, side.color_str()).to_ascii_lowercase();
|
|
|
|
|
let idle_animation = format!(
|
|
|
|
|
"display3d_models_animations_idle_{:?}_{}",
|
|
|
|
|
piece,
|
|
|
|
|
side.color_str()
|
|
|
|
|
)
|
|
|
|
|
.to_ascii_lowercase();
|
|
|
|
|
let idle_handle = gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
.get(
|
|
|
|
|
@ -739,7 +747,10 @@ fn pick_up(
|
|
|
|
|
|
|
|
|
|
fn put_down(
|
|
|
|
|
mut events: RemovedComponents<game::Selected>,
|
|
|
|
|
mut query: Query<(&game::Piece, &game::Side), (With<game::Piece>, With<game::Selectable>, With<Display3d>)>,
|
|
|
|
|
mut query: Query<
|
|
|
|
|
(&game::Piece, &game::Side),
|
|
|
|
|
(With<game::Piece>, With<game::Selectable>, With<Display3d>),
|
|
|
|
|
>,
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
mut players: Query<(&Name, &mut AnimationPlayer)>,
|
|
|
|
|
@ -761,8 +772,11 @@ 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())
|
|
|
|
|
let putdown_animation = format!(
|
|
|
|
|
"display3d_models_animations_put_down_{:?}_{}",
|
|
|
|
|
piece,
|
|
|
|
|
side.color_str()
|
|
|
|
|
)
|
|
|
|
|
.to_ascii_lowercase();
|
|
|
|
|
let putdown_handle = gltf
|
|
|
|
|
.named_animations
|
|
|
|
|
@ -775,7 +789,7 @@ fn put_down(
|
|
|
|
|
.expect("PutDown Animation");
|
|
|
|
|
if let Some(putdown_clip) = clips.get(putdown_handle) {
|
|
|
|
|
if putdown_clip.compatible_with(name) {
|
|
|
|
|
info!("Compatible with both clips!");
|
|
|
|
|
info!("Compatible with put-down clip!");
|
|
|
|
|
player
|
|
|
|
|
.start_with_transition(
|
|
|
|
|
putdown_handle.clone(),
|
|
|
|
|
@ -814,9 +828,8 @@ fn skip_animation(
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
) {
|
|
|
|
|
players.iter_mut().for_each(|mut p| {
|
|
|
|
|
info!("Skipping animation");
|
|
|
|
|
|
|
|
|
|
if let Some(c) = clips.get(p.animation_clip()) {
|
|
|
|
|
info!("Skipping animation");
|
|
|
|
|
// HACK: We should be able to skip to the end of an animation
|
|
|
|
|
// But implementation details means this is as close as we can get...
|
|
|
|
|
p.seek_to(c.duration() - (2.0 * time.delta_seconds()));
|
|
|
|
|
@ -1295,10 +1308,33 @@ fn debug_selected(
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn debug_textures(
|
|
|
|
|
mut events: EventReader<AssetEvent<StandardMaterial>>,
|
|
|
|
|
) {
|
|
|
|
|
fn debug_textures(mut events: EventReader<AssetEvent<StandardMaterial>>) {
|
|
|
|
|
events.read().for_each(|event| {
|
|
|
|
|
info!("New material: {:?}", event);
|
|
|
|
|
debug!("Material Event: {:?}", event);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Marker for entities which are currently animating
|
|
|
|
|
#[derive(Component, Debug)]
|
|
|
|
|
struct Animating;
|
|
|
|
|
|
|
|
|
|
fn monitor_animations(
|
|
|
|
|
active: Query<(Entity, &AnimationPlayer), (Changed<AnimationPlayer>, With<Animating>)>,
|
|
|
|
|
inactive: Query<(Entity, &AnimationPlayer), (Changed<AnimationPlayer>, Without<Animating>)>,
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
) {
|
|
|
|
|
// Remove Animating component from players that are done
|
|
|
|
|
active.iter().for_each(|(entity, player)| {
|
|
|
|
|
if player.is_finished() {
|
|
|
|
|
info!("Entity {:?} is done, removing animating marker", entity);
|
|
|
|
|
commands.entity(entity).remove::<Animating>();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
// Set inactive entities to active
|
|
|
|
|
inactive.iter().for_each(|(entity, player)| {
|
|
|
|
|
if !player.is_finished() {
|
|
|
|
|
info!("Entity {:?} is playing, adding animating marker", entity);
|
|
|
|
|
commands.entity(entity).insert(Animating);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|