Skip to content

Commit a944e47

Browse files
Merge pull request #2 from remilauzier/master
Fix some clippy warnings
2 parents 9913584 + 4fecf57 commit a944e47

File tree

10 files changed

+43
-71
lines changed

10 files changed

+43
-71
lines changed

src/main.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,8 @@ impl EventHandler for Game {
181181
}
182182

183183
fn key_up_event(&mut self, _ctx: &mut Context, keycode: KeyCode, _keymods: KeyMods) {
184-
match self.screen {
185-
Screen::Play => self.game_screen.lock().unwrap().key_up_event(keycode),
186-
_ => (),
184+
if let Screen::Play = self.screen {
185+
self.game_screen.lock().unwrap().key_up_event(keycode)
187186
}
188187
}
189188

@@ -206,14 +205,9 @@ impl EventHandler for Game {
206205
let change = self.game_screen.lock().unwrap().key_press(keycode);
207206

208207
if let Some(s) = change {
209-
match s {
210-
Screen::Menu => {
211-
self.game_screen = game::Game::create(ctx, self.asset_manager.clone());
212-
}
213-
214-
_ => (),
208+
if let Screen::Menu = s {
209+
self.game_screen = game::Game::create(ctx, self.asset_manager.clone());
215210
}
216-
217211
self.screen = s;
218212
}
219213
}

src/screens/game/components/bullet.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Grappling {
116116
) -> Option<Self> {
117117
let ray_cast = physics.ray_cast(na::Point2::new(pos_x, pos_y), na::Vector2::new(1.0, 1.0));
118118

119-
if ray_cast.len() > 0 {
119+
if !ray_cast.is_empty() {
120120
for object in ray_cast {
121121
if object.0 == ObjectData::Barrel {
122122
let body = object.1.body();

src/screens/game/components/enemy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Enemy {
126126
// TODO: The enemy shoots the player as soon as it see's the player.
127127
}
128128

129-
return false;
129+
false
130130
}
131131

132132
pub fn position(&self, physics: &mut Physics) -> na::Point2<f32> {

src/screens/game/components/player.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,7 @@ impl Player {
192192
self.handle(),
193193
);
194194

195-
if let Some(grapple) = gun {
196-
Some(PlayerWeapon::Grappling(grapple))
197-
} else {
198-
None
199-
}
195+
gun.map(PlayerWeapon::Grappling)
200196
}
201197
}
202198
} else {

src/screens/game/components/tile.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use crate::{
1010
};
1111

1212
pub enum TileType {
13-
LEFT,
14-
CENTER,
15-
RIGHT,
13+
Left,
14+
Center,
15+
Right,
1616
}
1717

1818
pub struct Tile {
@@ -39,19 +39,19 @@ impl Tile {
3939
let pos_y = height / 2.0 - 64.0;
4040

4141
match tile_type {
42-
TileType::LEFT => {
42+
TileType::Left => {
4343
let ground_left = asset_manager.get_image("ground_left.png");
4444

4545
tile_width = ground_left.width();
4646
tile_height = ground_left.height();
4747
}
48-
TileType::CENTER => {
48+
TileType::Center => {
4949
let ground_centre = asset_manager.get_image("ground_centre.png");
5050

5151
tile_width = ground_centre.width();
5252
tile_height = ground_centre.height();
5353
}
54-
TileType::RIGHT => {
54+
TileType::Right => {
5555
let ground_right = asset_manager.get_image("ground_right.png");
5656

5757
tile_width = ground_right.width();
@@ -86,7 +86,7 @@ impl Tile {
8686
camera.calculate_dest_point(Vec2::new(ground_position.x, ground_position.y));
8787

8888
match self.tile_type {
89-
TileType::LEFT => {
89+
TileType::Left => {
9090
graphics::draw(
9191
ctx,
9292
&ground_left,
@@ -96,7 +96,7 @@ impl Tile {
9696
)?;
9797
}
9898

99-
TileType::CENTER => {
99+
TileType::Center => {
100100
graphics::draw(
101101
ctx,
102102
&ground_centre,
@@ -105,7 +105,7 @@ impl Tile {
105105
.offset(Point2::new(0.5, 0.5)),
106106
)?;
107107
}
108-
TileType::RIGHT => {
108+
TileType::Right => {
109109
graphics::draw(
110110
ctx,
111111
&ground_right,

src/screens/game/game.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,9 @@ impl Game {
441441

442442
pub fn update(&mut self, ctx: &mut Context) -> GameResult<Option<crate::Screen>> {
443443
if let Some(t) = self.tics {
444-
if let Some(_) = self.tics {
445-
if self.dim_constant.rate != 0.5 {
446-
self.dim_constant.rate = lerp(self.dim_constant.rate, 0.5, 0.1);
447-
self.dim_shader.send(ctx, self.dim_constant)?;
448-
}
444+
if self.tics.is_some() && self.dim_constant.rate != 0.5 {
445+
self.dim_constant.rate = lerp(self.dim_constant.rate, 0.5, 0.1);
446+
self.dim_shader.send(ctx, self.dim_constant)?;
449447
}
450448

451449
if timer::ticks(ctx) % t as usize == 0 {
@@ -476,7 +474,7 @@ impl Game {
476474
cloud.update(ctx);
477475
}
478476

479-
if self.map.enemies.len() == 0 {
477+
if self.map.enemies.is_empty() {
480478
self.draw_end_text.3 = true;
481479
self.can_die = false;
482480

@@ -634,15 +632,10 @@ impl Game {
634632
}
635633

636634
pub fn key_up_event(&mut self, keycode: KeyCode) {
637-
match keycode {
638-
KeyCode::Up => {
639-
self.tics = None;
640-
self.dim_constant.rate = 1.0;
641-
}
642-
643-
_ => (),
635+
if keycode == KeyCode::Up {
636+
self.tics = None;
637+
self.dim_constant.rate = 1.0;
644638
}
645-
646639
self.map.player.set_direction(Direction::None);
647640
}
648641

src/screens/game/map.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ impl Map {
6868

6969
let mut weapon = WeaponType::Turbofish;
7070

71-
for line in map.split("\n").collect::<Vec<_>>() {
72-
let exp = line.split(" ").collect::<Vec<_>>();
71+
for line in map.split('\n').collect::<Vec<_>>() {
72+
let exp = line.split(' ').collect::<Vec<_>>();
7373

7474
if exp[0].starts_with(".end") {
7575
end = Some(exp[1..].join(" "));
@@ -90,7 +90,7 @@ impl Map {
9090
match id {
9191
'[' => {
9292
let tile =
93-
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::LEFT);
93+
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::Left);
9494

9595
draw_inc = (tile.dimensions().x / 2.0) + 32.0;
9696
draw_pos += draw_inc;
@@ -100,7 +100,7 @@ impl Map {
100100

101101
'-' => {
102102
let tile =
103-
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::CENTER);
103+
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::Center);
104104

105105
draw_inc = (tile.dimensions().x / 2.0) + 32.0;
106106
draw_pos += draw_inc;
@@ -114,7 +114,7 @@ impl Map {
114114
(draw_pos - 32.0) + 20.0,
115115
physics,
116116
asset_manager,
117-
TileType::RIGHT,
117+
TileType::Right,
118118
);
119119

120120
draw_inc = (tile.dimensions().x / 2.0) + 32.0;
@@ -130,7 +130,7 @@ impl Map {
130130

131131
'8' => {
132132
let tile =
133-
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::CENTER);
133+
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::Center);
134134

135135
draw_inc = (tile.dimensions().x / 2.0) + 32.0;
136136

@@ -143,7 +143,7 @@ impl Map {
143143

144144
'4' => {
145145
let tile =
146-
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::CENTER);
146+
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::Center);
147147

148148
player = Some(Player::new(ctx, draw_pos, physics, asset_manager));
149149

@@ -155,7 +155,7 @@ impl Map {
155155

156156
'*' => {
157157
let tile =
158-
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::CENTER);
158+
Tile::new(ctx, draw_pos, physics, asset_manager, TileType::Center);
159159

160160
draw_inc = tile.dimensions().x;
161161

@@ -176,14 +176,11 @@ impl Map {
176176
Self {
177177
ground,
178178
enemies,
179-
total_enemies,
180179
barrels,
181-
182180
player,
183-
181+
total_enemies,
184182
end,
185183
using,
186-
187184
weapon,
188185
}
189186
}

src/screens/game/physics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ impl Physics {
8181
let force_generator_set = nphysics2d::force_generator::DefaultForceGeneratorSet::new();
8282

8383
Self {
84-
geometrical_world,
8584
mechanical_world,
85+
geometrical_world,
8686
body_set,
8787
collider_set,
8888
joint_constraint_set,
@@ -367,9 +367,9 @@ impl Physics {
367367
let pos_2 = self.collider_set.get(object2).unwrap();
368368

369369
ncollide2d::query::distance(
370-
&pos_1.position(),
370+
pos_1.position(),
371371
pos_1.shape(),
372-
&pos_2.position(),
372+
pos_2.position(),
373373
pos_2.shape(),
374374
)
375375
}

src/screens/menu/menu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,6 @@ impl Menu {
145145
exit(0);
146146
}
147147

148-
return None;
148+
None
149149
}
150150
}

src/utils.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl AssetManager {
6565
filename.to_string(),
6666
Asset::Image(
6767
Image::new(ctx, format!("/images/{}", filename))
68-
.expect(format!("Cannot load {}", filename).as_str()),
68+
.unwrap_or_else(|_| panic!("Cannot load {}", filename)),
6969
),
7070
);
7171
}
@@ -75,7 +75,7 @@ impl AssetManager {
7575
filename.to_string(),
7676
Asset::Font(
7777
Font::new(ctx, format!("/fonts/{}", filename))
78-
.expect(format!("Cannot load {}", filename).as_str()),
78+
.unwrap_or_else(|_| panic!("Cannot load {}", filename)),
7979
),
8080
);
8181
}
@@ -85,7 +85,7 @@ impl AssetManager {
8585
filename.to_string(),
8686
Asset::Audio(Mutex::new(
8787
Source::new(ctx, format!("/audio/{}", filename))
88-
.expect(format!("Cannot load {}", filename).as_str()),
88+
.unwrap_or_else(|_| panic!("Cannot load {}", filename)),
8989
)),
9090
);
9191
}
@@ -103,36 +103,28 @@ impl AssetManager {
103103

104104
pub fn get_image(&self, filename: &str) -> Image {
105105
match self.assets.get(&filename.to_string()).unwrap() {
106-
Asset::Image(image) => {
107-
return image.to_owned();
108-
}
106+
Asset::Image(image) => image.to_owned(),
109107
_ => panic!(),
110108
}
111109
}
112110

113111
pub fn get_font(&self, filename: &str) -> Font {
114112
match self.assets.get(&filename.to_string()).unwrap() {
115-
Asset::Font(font) => {
116-
return font.to_owned();
117-
}
113+
Asset::Font(font) => font.to_owned(),
118114
_ => panic!(),
119115
}
120116
}
121117

122118
pub fn get_sound(&self, filename: &str) -> &Mutex<Source> {
123119
match self.assets.get(&filename.to_string()).unwrap() {
124-
Asset::Audio(audio) => {
125-
return audio;
126-
}
120+
Asset::Audio(audio) => audio,
127121
_ => panic!(),
128122
}
129123
}
130124

131125
pub fn get_file(&self, filename: &str) -> String {
132126
match self.assets.get(&filename.to_string()).unwrap() {
133-
Asset::File(file) => {
134-
return file.to_owned();
135-
}
127+
Asset::File(file) => file.to_owned(),
136128
_ => panic!(),
137129
}
138130
}

0 commit comments

Comments
 (0)