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:
* Set all new cameras as "is_active = false" automatically.
* Set loading camera as "is_active = true" upon entering loading.
* Set menu camera as "is_active = true" upon entering menu, etc.
* Maybe this has to do with loading entry/de-entry? It goes away after entering main menu...
Selecting one entity at a time...
* Affects both 2d and 3d modes seemingly equally
* We seem to not be de-selecting something...
* Does it happen when you play the game fast/slow?
* Yes
* It only seems to happen when we capture a piece.
OK new idea:
* Have one enum with all states (no split states)
* Assign a state to each camera.
* On state change, assign the camera with that state.
New architecture:
* Instead of inserting a "Selected" marker, emit a "Selected" event.
* Contextually this acts differently based on:
* 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>>,
atlases: Res<Assets<TextureAtlas>>,
mut commands: Commands,
selected: Query<Entity, (With<game::Selected>, With<game::Piece>, With<Display2d>)>,
) {
// For each window (there is only one)
windows
@ -322,7 +323,8 @@ fn select(
})
.iter()
.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);
});
});

@ -358,11 +358,11 @@ fn set_piece_texture(
mut models: Query<(&Name, &mut Handle<StandardMaterial>)>,
) {
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) {
children.iter_descendants(entity).for_each(|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()) {
(Piece::Queen, Side::A, "Queen.0") => {
*m = gltf
@ -468,14 +468,7 @@ fn select(
selectable: Query<Entity, (With<game::Selectable>, With<Display3d>)>,
children: Query<&Children>,
mut commands: Commands,
_selected: Query<
Entity,
(
With<game::Selected>,
With<game::Selectable>,
With<Display3d>,
),
>,
selected: Query<Entity, (With<game::Selected>, With<game::Piece>, With<Display3d>)>,
) {
events
.iter()
@ -506,6 +499,14 @@ fn select(
})
.iter()
.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);
});
Some(())

@ -503,9 +503,16 @@ fn capture_piece(mut events: Query<&mut Visibility, Added<Captured>>) {
fn asserts<T: Component>(
selected_pieces: Query<Entity, (With<Piece>, With<T>, With<Selected>)>,
selected_tiles: Query<Entity, (With<Tile>, With<T>, With<Selected>)>,
mut commands: Commands,
) {
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 {
panic!(

Loading…
Cancel
Save