|
|
|
@ -1,5 +1,5 @@
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
game::{Board, BoardIndex, Piece, Side},
|
|
|
|
game::{Board, BoardIndex, Piece, Side, BoardComponent},
|
|
|
|
prelude::*,
|
|
|
|
prelude::*,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use bevy::{
|
|
|
|
use bevy::{
|
|
|
|
@ -40,6 +40,9 @@ impl Plugin for Display3dPlugin {
|
|
|
|
switch_sides
|
|
|
|
switch_sides
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
.run_if(in_state(GameState::Play))
|
|
|
|
.run_if(state_changed::<game::TurnState>()),
|
|
|
|
.run_if(state_changed::<game::TurnState>()),
|
|
|
|
|
|
|
|
create_valid_move_entity.run_if(any_component_added::<game::Selected>),
|
|
|
|
|
|
|
|
remove_valid_move_entity.run_if(any_component_removed::<game::Selected>()),
|
|
|
|
|
|
|
|
set_valid_move_model.run_if(any_component_added::<game::ValidMove>),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
@ -562,6 +565,59 @@ fn moves_gizmo(
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Spawn 3d "Valid move" indicators when a piece is selected
|
|
|
|
|
|
|
|
/// Another system registers these new entities and associates the correct models and plays animations.
|
|
|
|
|
|
|
|
fn create_valid_move_entity(
|
|
|
|
|
|
|
|
events: Query<&BoardIndex, (With<game::Piece>, Added<game::Selected>, With<Display3d>)>,
|
|
|
|
|
|
|
|
board: Res<Board>,
|
|
|
|
|
|
|
|
root: Query<Entity, With<game::BoardComponent>>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events.iter().for_each(|idx| {
|
|
|
|
|
|
|
|
if let Ok(board_entity) = root.get_single() {
|
|
|
|
|
|
|
|
board
|
|
|
|
|
|
|
|
.valid_moves(*idx)
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.map(|i| Transform::from_translation(board_translation(i)))
|
|
|
|
|
|
|
|
.for_each(|t| {
|
|
|
|
|
|
|
|
commands.entity(board_entity).with_children(|parent| {
|
|
|
|
|
|
|
|
parent.spawn((Display3d, game::ValidMove, SceneBundle { ..default() })).insert(t);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn set_valid_move_model(
|
|
|
|
|
|
|
|
mut events: Query<&mut Handle<Scene>, (With<Display3d>, Added<game::ValidMove>)>,
|
|
|
|
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
|
|
|
|
assets_map: Res<AssetsMap>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if let Some(gltf) = gltfs.get(&assets_map.models) {
|
|
|
|
|
|
|
|
events.iter_mut().for_each(|mut handle| *handle = gltf.named_scenes.get("Valid Move Spot").unwrap().clone())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn play_valid_move_animation(
|
|
|
|
|
|
|
|
players: Query<&AnimationPlayer>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
todo!();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Move this to game.rs
|
|
|
|
|
|
|
|
/// Remove "Valid Move" indicators when a piece is de-selected
|
|
|
|
|
|
|
|
fn remove_valid_move_entity(
|
|
|
|
|
|
|
|
mut events: RemovedComponents<game::Selected>,
|
|
|
|
|
|
|
|
valid_moves: Query<Entity, With<game::ValidMove>>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events.iter().for_each(|_| {
|
|
|
|
|
|
|
|
valid_moves.iter().for_each(|entity| {
|
|
|
|
|
|
|
|
commands.entity(entity).despawn_recursive();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn pick_up(
|
|
|
|
fn pick_up(
|
|
|
|
mut events: Query<
|
|
|
|
mut events: Query<
|
|
|
|
(Entity, &game::Piece),
|
|
|
|
(Entity, &game::Piece),
|
|
|
|
|