|
|
|
@ -56,8 +56,6 @@ 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>),
|
|
|
|
set_valid_move_model.run_if(any_component_added::<game::ValidMove>),
|
|
|
|
update_tweaks.run_if(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
update_tweaks.run_if(on_event::<AssetEvent<Tweaks>>()),
|
|
|
|
scale_lighting.run_if(
|
|
|
|
scale_lighting.run_if(
|
|
|
|
@ -176,6 +174,20 @@ fn initialize(mut commands: Commands, board: Res<game::Board>, assets: Res<Asset
|
|
|
|
));
|
|
|
|
));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Valid move indicators
|
|
|
|
|
|
|
|
game::tiles().for_each(|(index, _)| {
|
|
|
|
|
|
|
|
parent.spawn((
|
|
|
|
|
|
|
|
Display3d,
|
|
|
|
|
|
|
|
index,
|
|
|
|
|
|
|
|
SceneBundle {
|
|
|
|
|
|
|
|
visibility: Visibility::Hidden,
|
|
|
|
|
|
|
|
transform: Transform::from_translation(board_translation(&index)),
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
game::ValidMove,
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Pieces
|
|
|
|
// Pieces
|
|
|
|
board.pieces().iter().for_each(|(index, piece)| {
|
|
|
|
board.pieces().iter().for_each(|(index, piece)| {
|
|
|
|
let side = Board::side(*index).expect("Spawn valid side");
|
|
|
|
let side = Board::side(*index).expect("Spawn valid side");
|
|
|
|
@ -808,32 +820,6 @@ 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.
|
|
|
|
|
|
|
|
/// TODO: Do not create/delete entities at runtime
|
|
|
|
|
|
|
|
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(
|
|
|
|
fn set_valid_move_model(
|
|
|
|
mut events: Query<&mut Handle<Scene>, (With<Display3d>, Added<game::ValidMove>)>,
|
|
|
|
mut events: Query<&mut Handle<Scene>, (With<Display3d>, Added<game::ValidMove>)>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
gltfs: Res<Assets<Gltf>>,
|
|
|
|
@ -866,20 +852,6 @@ fn _play_valid_move_animation(_players: Query<&AnimationPlayer>) {
|
|
|
|
todo!();
|
|
|
|
todo!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Do not create/delete entities at runtime
|
|
|
|
|
|
|
|
/// 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.read().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),
|
|
|
|
@ -1378,7 +1350,7 @@ fn capture_piece(
|
|
|
|
commands.entity(entity).insert(orig.clone());
|
|
|
|
commands.entity(entity).insert(orig.clone());
|
|
|
|
commands.entity(entity).remove::<Backup<Handle<StandardMaterial>>>();
|
|
|
|
commands.entity(entity).remove::<Backup<Handle<StandardMaterial>>>();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
warn!("Entity {} does not have original material")
|
|
|
|
warn!("Entity {:?} does not have original material", entity)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|