About to make a big refactor to selection

bevy0.12
Elijah Voigt 2 years ago
parent 0d4a800456
commit 12bf2ea96d

30
TODO

@ -1,10 +1,22 @@
Camera handling: Selecting one entity at a time...
* Set all new cameras as "is_active = false" automatically. * Affects both 2d and 3d modes seemingly equally
* Set loading camera as "is_active = true" upon entering loading. * We seem to not be de-selecting something...
* Set menu camera as "is_active = true" upon entering menu, etc. * Does it happen when you play the game fast/slow?
* Maybe this has to do with loading entry/de-entry? It goes away after entering main menu... * Yes
* It only seems to happen when we capture a piece.
OK new idea: New architecture:
* Have one enum with all states (no split states) * Instead of inserting a "Selected" marker, emit a "Selected" event.
* Assign a state to each camera. * Contextually this acts differently based on:
* On state change, assign the camera with that state. * If no entities are selected, insert the selected marker on that entity.
* If an entity is already marked selected, we emit a move event and de-select all entities.
* Q: Should we "Select Event" a BoardIndex?
* Pros:
* Display agnostic.
* Easy to keep in sync between displays.
* Cons:
* Possibly umm... actually I can't think of any.
* Emit "Selected" event which includes the BoardIndex selected.
* If a piece exists at that index:
* If a piece is already selected, emit a "Move" event and de-select the selected piece.
* Else mark it as selected in 2d and 3d.

@ -284,6 +284,7 @@ fn select(
cameras: Query<(&Camera, &GlobalTransform), With<Display2d>>, cameras: Query<(&Camera, &GlobalTransform), With<Display2d>>,
atlases: Res<Assets<TextureAtlas>>, atlases: Res<Assets<TextureAtlas>>,
mut commands: Commands, mut commands: Commands,
selected: Query<Entity, (With<game::Selected>, With<game::Piece>, With<Display2d>)>,
) { ) {
// For each window (there is only one) // For each window (there is only one)
windows windows
@ -322,7 +323,8 @@ fn select(
}) })
.iter() .iter()
.for_each(|(entity, _)| { .for_each(|(entity, _)| {
info!("Selected entity {:?}", entity); info!("Selected pieces: {:?}", selected.iter().len());
assert!(selected.iter().len() <= 2, "Selected too many pieces!");
commands.entity(*entity).insert(game::Selected); commands.entity(*entity).insert(game::Selected);
}); });
}); });

@ -358,11 +358,11 @@ fn set_piece_texture(
mut models: Query<(&Name, &mut Handle<StandardMaterial>)>, mut models: Query<(&Name, &mut Handle<StandardMaterial>)>,
) { ) {
events.iter().for_each(|(entity, piece, side)| { events.iter().for_each(|(entity, piece, side)| {
info!("Checking piece texture for {:?}", entity); debug!("Checking piece texture for {:?}", entity);
if let Some(gltf) = gltfs.get(&assets_map.models) { if let Some(gltf) = gltfs.get(&assets_map.models) {
children.iter_descendants(entity).for_each(|child| { children.iter_descendants(entity).for_each(|child| {
if let Ok((n, mut m)) = models.get_mut(child) { if let Ok((n, mut m)) = models.get_mut(child) {
info!("Setting piece texture for {:?}", child); debug!("Setting piece texture for {:?}", child);
match (*piece, side, n.as_str()) { match (*piece, side, n.as_str()) {
(Piece::Queen, Side::A, "Queen.0") => { (Piece::Queen, Side::A, "Queen.0") => {
*m = gltf *m = gltf
@ -468,14 +468,7 @@ fn select(
selectable: Query<Entity, (With<game::Selectable>, With<Display3d>)>, selectable: Query<Entity, (With<game::Selectable>, With<Display3d>)>,
children: Query<&Children>, children: Query<&Children>,
mut commands: Commands, mut commands: Commands,
_selected: Query< selected: Query<Entity, (With<game::Selected>, With<game::Piece>, With<Display3d>)>,
Entity,
(
With<game::Selected>,
With<game::Selectable>,
With<Display3d>,
),
>,
) { ) {
events events
.iter() .iter()
@ -506,6 +499,14 @@ fn select(
}) })
.iter() .iter()
.for_each(|&e| { .for_each(|&e| {
info!(
"Selected pieces: {:?}",
selected.iter().len()
);
assert!(
selected.iter().len() <= 2,
"Selected too many pieces selected!"
);
commands.entity(e).insert(game::Selected); commands.entity(e).insert(game::Selected);
}); });
Some(()) Some(())

@ -503,9 +503,16 @@ fn capture_piece(mut events: Query<&mut Visibility, Added<Captured>>) {
fn asserts<T: Component>( fn asserts<T: Component>(
selected_pieces: Query<Entity, (With<Piece>, With<T>, With<Selected>)>, selected_pieces: Query<Entity, (With<Piece>, With<T>, With<Selected>)>,
selected_tiles: Query<Entity, (With<Tile>, With<T>, With<Selected>)>, selected_tiles: Query<Entity, (With<Tile>, With<T>, With<Selected>)>,
mut commands: Commands,
) { ) {
if selected_pieces.iter().len() > 2 { if selected_pieces.iter().len() > 2 {
panic!("More than two pieces selected"); selected_pieces.iter().for_each(|e| {
info!("Too many pieces selected, one of which is: {:?}", e);
});
panic!(
"More than two pieces selected {:?}",
selected_pieces.iter().len()
);
} }
if selected_tiles.iter().len() > 2 { if selected_tiles.iter().len() > 2 {
panic!( panic!(

Loading…
Cancel
Save