Skip to content

Commit

Permalink
Apply pedantic clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alepez committed Jun 6, 2023
1 parent 3f5b20f commit 85097e0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 19 deletions.
11 changes: 8 additions & 3 deletions src/collab.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#![allow(clippy::needless_pass_by_value)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::module_name_repetitions)]

use crate::drawing::{make_chalk, ClearEvent};
use crate::{Chalk, Stats};
use bevy::prelude::*;
Expand Down Expand Up @@ -115,15 +119,16 @@ impl From<&DrawEvent> for Chalk {
Self {
pressed: true,
updated: true,
x: event.x as i32,
y: event.y as i32,
x: event.x.into(),
y: event.y.into(),
color: color_from_u32(event.color),
line_width: event.line_width as u32,
line_width: event.line_width.into(),
just_released: false,
}
}
}

#[allow(clippy::many_single_char_names)]
fn color_from_u32(n: u32) -> Color {
let r = ((n) & 0xFF) as u8;
let g = ((n >> 8) & 0xFF) as u8;
Expand Down
13 changes: 7 additions & 6 deletions src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#![allow(clippy::needless_pass_by_value)]

use bevy::prelude::*;

use bevy::{
diagnostic::{Diagnostics, FrameTimeDiagnosticsPlugin},
diagnostic::{Diagnostic, Diagnostics, FrameTimeDiagnosticsPlugin},
time::Time,
};

Expand Down Expand Up @@ -54,16 +56,15 @@ fn update(

let fps = diagnostics
.get(FrameTimeDiagnosticsPlugin::FPS)
.and_then(|x| x.smoothed())
.map(|x| format!("{:.1} fps", x))
.unwrap_or("-- fps".to_owned());
.and_then(Diagnostic::smoothed)
.map_or("-- fps".to_owned(), |x| format!("{:.1} fps", x));

let frame_time = {
let t = diagnostics
.get(FrameTimeDiagnosticsPlugin::FRAME_TIME)
.and_then(|x| x.smoothed())
.and_then(Diagnostic::smoothed)
.unwrap_or_else(|| time.delta_seconds_f64());
format!("{:.3} ms/frame", t)
format!("{t:.3} ms/frame")
};

let chalk = {
Expand Down
8 changes: 6 additions & 2 deletions src/drawing.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![allow(clippy::needless_pass_by_value)]
#![allow(clippy::cast_precision_loss)]

use crate::Chalk;
use bevy::prelude::*;

Expand Down Expand Up @@ -43,9 +46,10 @@ fn add_point(polyline: &mut Polyline, chalk: &Chalk) {
}

fn z_from_time(time: &Time) -> f32 {
let t = time.elapsed_seconds();
const MAX_Z: f32 = 500.0;
const MAX_TIME: f32 = 10_000.0;

let t = time.elapsed_seconds();
let step = MAX_Z / MAX_TIME;
t * step
}
Expand Down Expand Up @@ -160,6 +164,6 @@ fn handle_clear_event(
) {
let clear = events.iter().count() > 0;
if clear {
despawn_all_completed_lines(&mut commands, &lines)
despawn_all_completed_lines(&mut commands, &lines);
}
}
2 changes: 2 additions & 0 deletions src/keybinding.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_pass_by_value)]

use crate::{
drawing::ClearEvent,
local_chalk::{ChangeColorEvent, GrowEvent, ShrinkEvent},
Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#![deny(unsafe_code)]
#![warn(clippy::all, clippy::pedantic)]

mod collab;
mod debug;
mod drawing;
Expand Down Expand Up @@ -74,7 +77,7 @@ pub fn run(opt: Opt) {
app.add_plugin(FramepacePlugin);
app.add_plugin(LocalChalkPlugin);
app.add_plugin(DrawingPlugin);
app.add_plugin(PanCamPlugin::default());
app.add_plugin(PanCamPlugin);

if opt.show_debug_pane {
app.add_plugin(DebugPlugin);
Expand Down Expand Up @@ -128,6 +131,7 @@ struct Chalk {
line_width: u32,
}

#[must_use]
pub fn options() -> Opt {
#[cfg(target_arch = "wasm32")]
{
Expand Down
11 changes: 6 additions & 5 deletions src/local_chalk.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::needless_pass_by_value)]

use std::cmp::max;
use std::cmp::min;

Expand Down Expand Up @@ -93,6 +95,7 @@ fn cursor_to_world_position(
Some(Vec2::new(world_position[0], world_position[1]))
}

#[allow(clippy::cast_possible_truncation)]
fn handle_user_input(
window_q: Query<&Window>,
camera_q: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
Expand Down Expand Up @@ -151,6 +154,7 @@ fn mouse_events(
chalk.just_released = was_pressed && !chalk.pressed;
}

#[allow(clippy::cast_possible_truncation)]
fn touch_events(
mut touch_evr: EventReader<TouchInput>,
mut chalk: ResMut<LocalChalk>,
Expand All @@ -176,11 +180,7 @@ fn touch_events(
press_changed = true;
}
TouchPhase::Moved => {}
TouchPhase::Ended => {
chalk.pressed = false;
press_changed = true;
}
TouchPhase::Cancelled => {
TouchPhase::Ended | TouchPhase::Cancelled => {
chalk.pressed = false;
press_changed = true;
}
Expand Down Expand Up @@ -209,6 +209,7 @@ fn is_updated(old_chalk: &Chalk, new_chalk: &Chalk) -> bool {
|| old_chalk.just_released != new_chalk.just_released
}

#[allow(clippy::cast_precision_loss)]
fn update_cursor(
mut chalk: ResMut<LocalChalk>,
mut cursor_q: Query<(&mut Fill, &mut Transform), With<LocalCursor>>,
Expand Down
5 changes: 3 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::type_complexity)]
#![allow(clippy::needless_pass_by_value)]

use bevy::prelude::*;

Expand Down Expand Up @@ -208,7 +209,7 @@ fn toggle_ui_system(
*visibility = match *visibility {
Visibility::Visible => Visibility::Hidden,
Visibility::Hidden => Visibility::Visible,
x => x,
x @ Visibility::Inherited => x,
};
}
}
Expand All @@ -221,7 +222,7 @@ fn update_collab_info(mut txt_query: Query<&mut Text, With<CollabText>>, stats:
format!("{}", stats.collab.peers)
}
} else {
"".to_string()
String::new()
};

txt_query.single_mut().sections[0].value = text;
Expand Down

0 comments on commit 85097e0

Please sign in to comment.