Skip to content

Commit

Permalink
feat: highlight selected crate
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenMian committed Jan 25, 2024
1 parent b36ee29 commit d0ed6f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ fn main() {
setup_hud,
setup_level,
),
)
.add_systems(PostStartup, spawn_board);
);

app.add_systems(
Update,
Expand Down
14 changes: 14 additions & 0 deletions src/systems/auto_crate_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub fn spawn_crate_pushable_marks(
mut commands: Commands,
mut auto_crate_push_state: ResMut<AutoCratePushState>,
board: Query<&Board>,
mut crates: Query<(&GridPosition, &mut TextureAtlasSprite), With<Crate>>,
mut next_state: ResMut<NextState<AppState>>,
) {
let crate_position = &auto_crate_push_state.selected_crate;
Expand Down Expand Up @@ -41,12 +42,25 @@ pub fn spawn_crate_pushable_marks(
return;
}

// highlight selected crate
crates
.iter_mut()
.filter(|(grid_position, _)| ***grid_position == *crate_position)
.for_each(|(_, mut sprite)| sprite.color = Color::GREEN);

auto_crate_push_state.paths = paths;
}

pub fn despawn_crate_pushable_marks(
mut commands: Commands,
mut crates: Query<(&GridPosition, &mut TextureAtlasSprite), With<Crate>>,
marks: Query<Entity, With<CratePushableMark>>,
auto_crate_push_state: Res<AutoCratePushState>,
) {
crates
.iter_mut()
.filter(|(grid_position, _)| ***grid_position == auto_crate_push_state.selected_crate)
.for_each(|(_, mut sprite)| sprite.color = Color::WHITE);

marks.for_each(|entity| commands.entity(entity).despawn());
}

0 comments on commit d0ed6f1

Please sign in to comment.