Skip to content

Commit 83069a5

Browse files
committed
Rustfmt the whole thing
1 parent 94f6606 commit 83069a5

File tree

9 files changed

+128
-109
lines changed

9 files changed

+128
-109
lines changed

.github/workflows/rust.yml

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,84 @@
11
name: CI
22

33
on:
4-
push:
5-
branches: [main]
6-
pull_request:
7-
branches: [main]
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
88

99
env:
10-
CARGO_TERM_COLOR: always
10+
CARGO_TERM_COLOR: always
1111

1212
jobs:
13-
# Run cargo test
14-
test:
15-
name: Test Suite
16-
runs-on: ubuntu-latest
17-
steps:
18-
- name: Checkout sources
19-
uses: actions/checkout@v3
20-
- name: Cache
21-
uses: actions/cache@v3
22-
with:
23-
path: |
24-
~/.cargo/bin/
25-
~/.cargo/registry/index/
26-
~/.cargo/registry/cache/
27-
~/.cargo/git/db/
28-
target/
29-
key:
30-
${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.toml')
31-
}}
32-
- name: Install stable toolchain
33-
uses: dtolnay/rust-toolchain@stable
34-
- name: Install Dependencies
35-
run:
36-
sudo apt-get update; sudo apt-get install pkg-config
37-
libx11-dev libasound2-dev libudev-dev libxcb-render0-dev
38-
libxcb-shape0-dev libxcb-xfixes0-dev
39-
- name: Run cargo test
40-
run: cargo test
41-
42-
# Run cargo clippy -- -D warnings
43-
clippy_check:
44-
name: Clippy
45-
runs-on: ubuntu-latest
46-
steps:
47-
- name: Checkout sources
48-
uses: actions/checkout@v3
49-
- name: Cache
50-
uses: actions/cache@v3
51-
with:
52-
path: |
53-
~/.cargo/bin/
54-
~/.cargo/registry/index/
55-
~/.cargo/registry/cache/
56-
~/.cargo/git/db/
57-
target/
58-
key:
59-
${{ runner.os }}-cargo-clippy-${{
60-
hashFiles('**/Cargo.toml') }}
61-
- name: Install stable toolchain
62-
uses: dtolnay/rust-toolchain@stable
63-
with:
64-
components: clippy
65-
- name: Install Dependencies
66-
run:
67-
sudo apt-get update; sudo apt-get install pkg-config
68-
libx11-dev libasound2-dev libudev-dev
69-
- name: Run clippy
70-
run: cargo clippy -- -D warnings
71-
72-
# Run cargo fmt --all -- --check
73-
format:
74-
name: Format
75-
runs-on: ubuntu-latest
76-
steps:
77-
- name: Checkout sources
78-
uses: actions/checkout@v3
79-
- name: Install stable toolchain
80-
uses: dtolnay/rust-toolchain@stable
81-
with:
82-
components: rustfmt
83-
- name: Run cargo fmt
84-
run: cargo fmt --all -- --check
13+
# Run cargo test
14+
test:
15+
name: Test Suite
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout sources
19+
uses: actions/checkout@v3
20+
- name: Cache
21+
uses: actions/cache@v3
22+
with:
23+
path: |
24+
~/.cargo/bin/
25+
~/.cargo/registry/index/
26+
~/.cargo/registry/cache/
27+
~/.cargo/git/db/
28+
target/
29+
key:
30+
${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.toml')
31+
}}
32+
- name: Install stable toolchain
33+
uses: dtolnay/rust-toolchain@stable
34+
- name: Install Dependencies
35+
run:
36+
sudo apt-get update; sudo apt-get install pkg-config
37+
libx11-dev libasound2-dev libudev-dev libxcb-render0-dev
38+
libxcb-shape0-dev libxcb-xfixes0-dev
39+
- name: Run cargo test
40+
run: cargo test
41+
42+
# Run cargo clippy -- -D warnings
43+
clippy_check:
44+
name: Clippy
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Checkout sources
48+
uses: actions/checkout@v3
49+
- name: Cache
50+
uses: actions/cache@v3
51+
with:
52+
path: |
53+
~/.cargo/bin/
54+
~/.cargo/registry/index/
55+
~/.cargo/registry/cache/
56+
~/.cargo/git/db/
57+
target/
58+
key:
59+
${{ runner.os }}-cargo-clippy-${{
60+
hashFiles('**/Cargo.toml') }}
61+
- name: Install stable toolchain
62+
uses: dtolnay/rust-toolchain@stable
63+
with:
64+
components: clippy
65+
- name: Install Dependencies
66+
run:
67+
sudo apt-get update; sudo apt-get install pkg-config
68+
libx11-dev libasound2-dev libudev-dev
69+
- name: Run clippy
70+
run: cargo clippy -- -D warnings
71+
72+
# Run cargo fmt --all -- --check
73+
format:
74+
name: Format
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Checkout sources
78+
uses: actions/checkout@v3
79+
- name: Install stable toolchain
80+
uses: dtolnay/rust-toolchain@stable
81+
with:
82+
components: rustfmt
83+
- name: Run cargo fmt
84+
run: cargo fmt --all -- --check

src/cell.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@ impl CellCoordinates {
145145
radial_direction: RadialDirection,
146146
cube_side_length: u32,
147147
) -> Option<(CellCoordinates, bool)> {
148-
if radial_direction.rotation_axis().is_parallel_to(self.normal_direction()) {
148+
if radial_direction
149+
.rotation_axis()
150+
.is_parallel_to(self.normal_direction())
151+
{
149152
// The direction is not possible to go in on this side
150153
return None;
151154
}
@@ -164,7 +167,9 @@ impl CellCoordinates {
164167
cube_side_length: u32,
165168
) -> Option<(CellCoordinates, bool)> {
166169
let cell1 = self.get_cell_in_direction(diagonal.0, cube_side_length)?;
167-
let cell2 = cell1.0.get_cell_in_direction(diagonal.1, cube_side_length)?;
170+
let cell2 = cell1
171+
.0
172+
.get_cell_in_direction(diagonal.1, cube_side_length)?;
168173
if cell1.1 && cell2.1 {
169174
// The second element tells us if the transformation went over a cube edge, in this
170175
// case we are in a corner, which means we have a true neighbor in cell2

src/cube_rotation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::time::{Duration, Instant};
44
use bevy::prelude::*;
55
use derivative::Derivative;
66

7-
use crate::MainCamera;
87
use crate::utils::{CartesianDirection, SeeDirection};
8+
use crate::MainCamera;
99

1010
#[derive(Debug, Default, Clone)]
1111
pub(crate) struct RotationData {

src/gamemanager.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::ai::AICache;
2-
use crate::movement::GameMove;
3-
use crate::{ai, movement, units::*};
1+
use bevy::prelude::*;
2+
use bevy_mod_picking::prelude::*;
43

4+
use crate::ai::AICache;
55
use crate::cell::*;
6+
use crate::movement::GameMove;
67
use crate::scene::{self, MainCube, SceneChild};
7-
use bevy::prelude::*;
8-
use bevy_mod_picking::prelude::*;
8+
use crate::{ai, movement, units::*};
99

1010
#[derive(Resource, Debug)]
1111
pub(crate) struct Game {
@@ -19,6 +19,7 @@ pub(crate) struct Game {
1919
pub(crate) palette: Palette,
2020
pub(crate) ai_playing: Option<Team>,
2121
}
22+
2223
impl Game {
2324
pub(crate) fn new(cube_side_length: u32) -> Self {
2425
Game {
@@ -68,6 +69,7 @@ pub(crate) enum Team {
6869
Black,
6970
White,
7071
}
72+
7173
impl Team {
7274
pub(crate) fn color(&self) -> Color {
7375
match self {
@@ -182,7 +184,9 @@ fn on_cell_clicked_play_phase(
182184

183185
// Mark cells
184186
reset_cells_new_selection(game);
185-
let Some(unit) = game.units.get_unit(clicked_coords) else { return;};
187+
let Some(unit) = game.units.get_unit(clicked_coords) else {
188+
return;
189+
};
186190
if unit.team != game.turn {
187191
return;
188192
}
@@ -200,7 +204,7 @@ fn on_cell_clicked_play_phase(
200204
if (unit.unit_type.can_capture_over_edge()
201205
|| unit_at_destination.is_none()
202206
|| unit.coords.normal_direction() == unit_move.normal_direction())
203-
// Prevent taking units on same team
207+
// Prevent taking units on same team
204208
&& unit_at_destination.map_or(true, |unit_at_d| unit.team != unit_at_d.team)
205209
{
206210
cell.selected_unit_can_move_to = true;
@@ -223,13 +227,18 @@ pub(crate) fn make_move(game_move: GameMove, game: &mut Game, commands: &mut Com
223227
game.units.remove_dead_units();
224228
}
225229

226-
let Some(unit) = game.units.get_unit_mut(game_move.from) else {return false};
230+
let Some(unit) = game.units.get_unit_mut(game_move.from) else {
231+
return false;
232+
};
227233
if unit.team != game.turn {
228234
return false;
229235
}
230236

231237
unit.move_unit_to(game_move.to);
232-
let Some(entity) = unit.entity else {warn!("Unit entity was None");return false;};
238+
let Some(entity) = unit.entity else {
239+
warn!("Unit entity was None");
240+
return false;
241+
};
233242
game.entities_to_move.push((entity, game_move.to));
234243
if let UnitType::Pawn(_, ref mut has_moved) = unit.unit_type {
235244
*has_moved = true;

src/main.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use bevy::log::*;
2+
use bevy::prelude::*;
3+
use bevy_mod_picking::prelude::*;
4+
15
mod ai;
26
mod cell;
37
mod cube_rotation;
@@ -8,10 +12,6 @@ mod scene;
812
mod units;
913
mod utils;
1014

11-
use bevy::log::*;
12-
use bevy::prelude::*;
13-
use bevy_mod_picking::prelude::*;
14-
1515
fn main() {
1616
App::new()
1717
.add_plugins(
@@ -39,8 +39,7 @@ fn main() {
3939
}
4040

4141
#[derive(Component)]
42-
struct MainCamera {
43-
}
42+
struct MainCamera {}
4443

4544
fn setup(
4645
mut commands: Commands,
@@ -73,8 +72,7 @@ fn setup(
7372
transform: Transform::from_xyz(8., 8., 8.),
7473
..default()
7574
},
76-
MainCamera {
77-
},
75+
MainCamera {},
7876
));
7977

8078
commands.spawn((
@@ -83,7 +81,6 @@ fn setup(
8381
..default()
8482
},
8583
RaycastPickCamera::default(), // Enable picking with this camera
86-
MainCamera {
87-
},
84+
MainCamera {},
8885
));
8986
}

src/materials.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
use bevy::prelude::*;
2+
13
use crate::cell::CellColor;
24
use crate::gamemanager::Palette;
3-
use bevy::prelude::*;
45

56
pub(crate) fn select_cell_material(
67
material: &mut StandardMaterial,

src/movement.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use bevy::prelude::error;
22

33
use crate::cell::{Board, CellCoordinates};
4-
54
use crate::units::*;
65
use crate::utils::{CartesianDirection, RadialDirection};
76

@@ -134,7 +133,8 @@ fn pawn_movement(
134133
.iter()
135134
.filter(|diag| diag.0 == forward || diag.1 == forward)
136135
{
137-
let Some(diagonal_coords) = unit_coords.get_diagonal(diagonal, board.cube_side_length) else {
136+
let Some(diagonal_coords) = unit_coords.get_diagonal(diagonal, board.cube_side_length)
137+
else {
138138
continue;
139139
};
140140

@@ -236,7 +236,9 @@ mod parts {
236236
let mut dist = 0;
237237
let mut edge_crossings = 0;
238238
loop {
239-
let Some(next_cell) = latest_cell.get_diagonal(diagonal, cube_side_length) else {break;};
239+
let Some(next_cell) = latest_cell.get_diagonal(diagonal, cube_side_length) else {
240+
break;
241+
};
240242

241243
if output.iter().any(|cell| *cell == next_cell.0) {
242244
break;
@@ -270,7 +272,11 @@ mod parts {
270272
) -> Vec<CellCoordinates> {
271273
let mut output = Vec::new();
272274
for radial_direction in RadialDirection::directions() {
273-
let Some(mut forward_two) = coords.get_cell_in_radial_direction(radial_direction, cube_side_length) else {continue;};
275+
let Some(mut forward_two) =
276+
coords.get_cell_in_radial_direction(radial_direction, cube_side_length)
277+
else {
278+
continue;
279+
};
274280
let mut edge_crossings = 0;
275281

276282
if forward_two.1 {

src/scene.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use bevy::prelude::*;
2-
use bevy::scene::SceneInstance;
3-
use bevy_mod_picking::prelude::*;
41
use std::f32::consts::PI;
52

63
use bevy::prelude::Vec3;
4+
use bevy::prelude::*;
5+
use bevy::scene::SceneInstance;
6+
use bevy_mod_picking::prelude::*;
77

88
use crate::cell::{Cell, CellColor, CellCoordinates};
99
use crate::gamemanager::{self, spawn_unit_entity, Game};

0 commit comments

Comments
 (0)