|
|
|
|
@ -1,9 +1,13 @@
|
|
|
|
|
// TODO: Unify the selection logic
|
|
|
|
|
// If you select in 2d, it should "be" selected in 3d.
|
|
|
|
|
// And if you select in 3d, 2d is selected.
|
|
|
|
|
use crate::{
|
|
|
|
|
game::{Board, BoardIndex, Piece, Side},
|
|
|
|
|
prelude::*,
|
|
|
|
|
};
|
|
|
|
|
use bevy::{
|
|
|
|
|
core_pipeline::Skybox,
|
|
|
|
|
ecs::removal_detection::RemovedComponentReader,
|
|
|
|
|
input::mouse::{MouseButtonInput, MouseMotion, MouseWheel},
|
|
|
|
|
render::render_resource::{TextureViewDescriptor, TextureViewDimension},
|
|
|
|
|
window::PrimaryWindow,
|
|
|
|
|
@ -29,6 +33,8 @@ impl Plugin for Display3dPlugin {
|
|
|
|
|
select_3d
|
|
|
|
|
.run_if(in_state(GameState::Display3d))
|
|
|
|
|
.run_if(on_event::<MouseButtonInput>()),
|
|
|
|
|
pick_up.run_if(any_component_added::<game::Selected>),
|
|
|
|
|
put_down.run_if(any_component_removed::<game::Selected>()),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
@ -379,7 +385,7 @@ fn select_3d(
|
|
|
|
|
mut events: EventReader<MouseButtonInput>,
|
|
|
|
|
query: Query<(Entity, &Handle<Mesh>, &GlobalTransform)>,
|
|
|
|
|
meshes: Res<Assets<Mesh>>,
|
|
|
|
|
cameras: Query<(&Camera, &GlobalTransform), With<Display3d>>,
|
|
|
|
|
cameras: Query<(&Camera, &GlobalTransform)>,
|
|
|
|
|
windows: Query<&Window, With<PrimaryWindow>>,
|
|
|
|
|
parents: Query<Entity, (With<game::Piece>, With<Display3d>)>,
|
|
|
|
|
children: Query<&Children>,
|
|
|
|
|
@ -440,6 +446,25 @@ fn selected_gizmo(
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn pick_up(
|
|
|
|
|
mut events: Query<&mut Transform, (With<game::Piece>, With<Display3d>, Added<game::Selected>)>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter_mut().for_each(|mut transform| {
|
|
|
|
|
transform.translation += Vec3::Y;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn put_down(
|
|
|
|
|
mut events: RemovedComponents<game::Selected>,
|
|
|
|
|
mut query: Query<&mut Transform, (With<game::Piece>, With<Display3d>)>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|entity| {
|
|
|
|
|
if let Ok(mut transform) = query.get_mut(entity) {
|
|
|
|
|
transform.translation -= Vec3::Y;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Animations
|
|
|
|
|
// * QueenPickup
|
|
|
|
|
// * QueenPutDown
|
|
|
|
|
|