diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-03-21 19:36:32 +0100 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-03-21 19:36:32 +0100 |
commit | 9a57ab99eb0162cbc55064639db69a1d9ff26d76 (patch) | |
tree | 720adfa791cb21bf2499ff332ca22a371247af9a /src | |
parent | 585d82473ccf566965ded0e50eea1669c3e1cdf3 (diff) |
s/cell_query/q
Diffstat (limited to 'src')
-rw-r--r-- | src/cell.rs | 27 | ||||
-rw-r--r-- | src/main.rs | 20 |
2 files changed, 22 insertions, 25 deletions
diff --git a/src/cell.rs b/src/cell.rs index fc5d77d..48bc387 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -67,8 +67,8 @@ impl Cell { } } -pub fn insert(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { - for (mut cell, mut sprite) in cell_query.iter_mut() { +pub fn insert(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { + for (mut cell, mut sprite) in q.iter_mut() { if cell.occupant == Occupant::None && cell.y == constants::GRID_SIZE - 1 { cell.occupant = rand::random(); sprite.index = cell.occupant.to_index(); @@ -76,20 +76,17 @@ pub fn insert(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { } } -pub fn start_explosion( - commands: &mut Commands, - mut cell_query: Query<(Entity, &Cell), Without<Timer>>, -) { - for (entity, cell) in cell_query.iter_mut() { +pub fn start_explosion(commands: &mut Commands, mut q: Query<(Entity, &Cell), Without<Timer>>) { + for (entity, cell) in q.iter_mut() { if cell.occupant == Occupant::Explosion { commands.insert(entity, (Timer::from_seconds(0.1, true),)); } } } -pub fn check(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { +pub fn check(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { let mut cells = [[Cell::default(); constants::GRID_SIZE]; constants::GRID_SIZE]; - for (cell, _) in cell_query.iter_mut() { + for (cell, _) in q.iter_mut() { cells[cell.x][cell.y] = *cell; } @@ -115,7 +112,7 @@ pub fn check(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { for c in connected.iter() { if c.len() > 4 { for (i, j) in c.iter() { - for (mut cell, mut sprite) in cell_query.iter_mut() { + for (mut cell, mut sprite) in q.iter_mut() { if &cell.x == i && &cell.y == j && cell.occupant != Occupant::Explosion { cell.occupant = Occupant::Explosion; sprite.index = cell.occupant.to_index(); @@ -146,7 +143,7 @@ pub fn check(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { for c in connected.iter() { if c.len() > 4 { for (i, j) in c.iter() { - for (mut cell, mut sprite) in cell_query.iter_mut() { + for (mut cell, mut sprite) in q.iter_mut() { if &cell.x == i && &cell.y == j && cell.occupant != Occupant::Explosion { cell.occupant = Occupant::Explosion; sprite.index = cell.occupant.to_index(); @@ -157,16 +154,16 @@ pub fn check(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { } } -pub fn falling(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { +pub fn falling(mut q: Query<(&mut Cell, &mut TextureAtlasSprite)>) { let mut have_gems = Vec::new(); - for (cell, _sprite) in cell_query.iter_mut() { + for (cell, _sprite) in q.iter_mut() { if cell.occupant != Occupant::None { have_gems.push(*cell); } } let mut moved_gems = Vec::new(); - for (mut cell, mut sprite) in cell_query.iter_mut() { + for (mut cell, mut sprite) in q.iter_mut() { if cell.occupant == Occupant::None { if let Some(c) = have_gems .iter() @@ -179,7 +176,7 @@ pub fn falling(mut cell_query: Query<(&mut Cell, &mut TextureAtlasSprite)>) { } } - for (mut cell, mut sprite) in cell_query.iter_mut() { + for (mut cell, mut sprite) in q.iter_mut() { if moved_gems.iter().any(|c| (c.x, c.y) == (cell.x, cell.y)) { cell.occupant = Occupant::None; sprite.index = cell.occupant.to_index(); diff --git a/src/main.rs b/src/main.rs index 624aa5b..79c0f2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,14 +118,14 @@ pub fn setup( fn animation_system( commands: &mut Commands, time: Res<Time>, - mut cell_query: Query<( + mut q: Query<( Entity, Option<&mut Cell>, &mut Timer, &mut TextureAtlasSprite, )>, ) { - for (entity, cell, mut timer, mut sprite) in cell_query.iter_mut() { + for (entity, cell, mut timer, mut sprite) in q.iter_mut() { timer.tick(time.delta_seconds()); if timer.finished() { let index = match sprite.index { @@ -160,7 +160,7 @@ fn animation_system( fn cosmonaut_detect_system( commands: &mut Commands, windows: Res<Windows>, - mut cell_query: Query<(&Transform, &TextureAtlasSprite)>, + mut q: Query<(&Transform, &TextureAtlasSprite)>, ) { if let Some(mut cursor_position) = windows .get_primary() @@ -170,7 +170,7 @@ fn cosmonaut_detect_system( (constants::WINDOW_WIDTH / 2.0) - constants::TILE_SIZE * constants::TILE_SCALE * 0.5; cursor_position.y -= (constants::WINDOW_HEIGHT / 2.0) - constants::TILE_SIZE * constants::TILE_SCALE * 0.5; - for (transform, sprite) in cell_query.iter_mut() { + for (transform, sprite) in q.iter_mut() { if transform.translation.x < cursor_position.x && transform.translation.x + constants::TILE_SIZE * constants::TILE_SCALE > cursor_position.x @@ -193,7 +193,7 @@ fn cosmonaut_detect_system( fn mouse_system( windows: Res<Windows>, - mut cell_query: Query<(&mut Cell, &mut Transform, &mut TextureAtlasSprite)>, + mut q: Query<(&mut Cell, &mut Transform, &mut TextureAtlasSprite)>, mouse_button_input: Res<Input<MouseButton>>, ) { if let Some(mut cursor_position) = windows @@ -205,7 +205,7 @@ fn mouse_system( cursor_position.y -= (constants::WINDOW_HEIGHT / 2.0) - constants::TILE_SIZE * constants::TILE_SCALE * 0.5; - for (cell, _, mut sprite) in cell_query.iter_mut() { + for (cell, _, mut sprite) in q.iter_mut() { if cell.selected { sprite.color.set_a(0.2); } else if cell.hovered { @@ -215,7 +215,7 @@ fn mouse_system( } } - for (mut cell, transform, _) in cell_query.iter_mut() { + for (mut cell, transform, _) in q.iter_mut() { if transform.translation.x < cursor_position.x && transform.translation.x + constants::TILE_SIZE * constants::TILE_SCALE > cursor_position.x @@ -234,7 +234,7 @@ fn mouse_system( if mouse_button_input.just_released(MouseButton::Left) { let mut cells: Vec<Cell> = Vec::new(); - for (cell, _, _) in cell_query.iter_mut() { + for (cell, _, _) in q.iter_mut() { cells.push(*cell); } if let Some(mut selected) = cells.clone().iter_mut().find(|c| c.selected) { @@ -247,7 +247,7 @@ fn mouse_system( let tmp = selected.occupant; selected.occupant = hovered.occupant; hovered.occupant = tmp; - for (mut cell, _, mut sprite) in cell_query.iter_mut() { + for (mut cell, _, mut sprite) in q.iter_mut() { if cell.x == selected.x && cell.y == selected.y { cell.occupant = selected.occupant; sprite.index = cell.occupant.to_index(); @@ -259,7 +259,7 @@ fn mouse_system( } } } - for (mut cell, _, _) in cell_query.iter_mut() { + for (mut cell, _, _) in q.iter_mut() { cell.selected = false; } } |