Skip to content

Commit

Permalink
fix: cleanup lint
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAlcibiades committed Dec 28, 2024
1 parent fc61171 commit 2da636e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
11 changes: 1 addition & 10 deletions src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct MusicPlugin;
///
/// The state persists across game state changes to maintain user preferences
/// for music playback.
#[derive(Resource)]
#[derive(Resource, Default)]
struct MusicState {
/// Indicates if music should be playing (true) or muted (false)
playing: bool,
Expand All @@ -31,15 +31,6 @@ struct MusicState {
handle: Option<Handle<AudioInstance>>,
}

impl Default for MusicState {
fn default() -> Self {
Self {
playing: false, // Start with music enabled by default
handle: None, // No audio instance at initialization
}
}
}

impl Plugin for MusicPlugin {
fn build(&self, app: &mut App) {
app.add_plugins(AudioPlugin)
Expand Down
6 changes: 0 additions & 6 deletions src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@ use std::time::Duration;
pub struct PaddleConfig {
/// Movement speed in world units per second
pub speed: f32,
/// Maximum angle the ball can bounce (in radians)
pub max_bounce_angle: f32,
/// X-coordinate for left paddle position
pub left_x: f32,
/// X-coordinate for right paddle position
pub right_x: f32,
/// Base width of the paddle
pub width: f32,
/// Total height of the paddle
pub height: f32,
/// Depth of the paddle's curve
Expand All @@ -44,10 +40,8 @@ impl Default for PaddleConfig {
fn default() -> Self {
Self {
speed: 20.0,
max_bounce_angle: 1.0,
left_x: -7.65,
right_x: 7.65,
width: 0.5,
height: 2.0,
curve_depth: 0.3,
segments: 100,
Expand Down
52 changes: 35 additions & 17 deletions src/score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,17 @@ fn setup_score_ui(mut commands: Commands, score: Res<Score>) {
flex_direction: FlexDirection::Row,
..default()
},
ScoreText { kind: ScoreKind::Root },
ScoreText {
kind: ScoreKind::Root,
},
))
.with_children(|parent| {
spawn_player_score(parent, score.p1, ScoreKind::P1, UiRect::right(Val::Px(20.0)));
spawn_player_score(
parent,
score.p1,
ScoreKind::P1,
UiRect::right(Val::Px(20.0)),
);
spawn_player_score(parent, score.p2, ScoreKind::P2, UiRect::left(Val::Px(20.0)));
});
}
Expand All @@ -168,20 +175,18 @@ fn setup_score_ui(mut commands: Commands, score: Res<Score>) {
/// * `score` - Initial score value to display
/// * `kind` - Which player's score this represents
/// * `margin` - Margin settings for positioning
fn spawn_player_score(
parent: &mut ChildBuilder,
score: u32,
kind: ScoreKind,
margin: UiRect,
) {
fn spawn_player_score(parent: &mut ChildBuilder, score: u32, kind: ScoreKind, margin: UiRect) {
parent.spawn((
Text::new(score.to_string()),
TextFont {
font_size: 48.0,
..default()
},
TextColor(Color::WHITE),
Node { margin, ..default() },
Node {
margin,
..default()
},
ScoreText { kind },
));
}
Expand Down Expand Up @@ -235,7 +240,12 @@ fn on_resume(
ball_query: Query<Entity, With<Ball>>,
) {
if ball_query.is_empty() && !score.should_serve {
create_ball(&mut commands, &mut meshes, &mut materials, score.server_is_p1);
create_ball(
&mut commands,
&mut meshes,
&mut materials,
score.server_is_p1,
);
}
}

Expand All @@ -256,7 +266,12 @@ fn handle_serve_delay(
score.serve_timer.tick(time.delta());

if score.serve_timer.just_finished() {
create_ball(&mut commands, &mut meshes, &mut materials, score.server_is_p1);
create_ball(
&mut commands,
&mut meshes,
&mut materials,
score.server_is_p1,
);
score.should_serve = false;
score.serve_timer.reset();
}
Expand Down Expand Up @@ -333,20 +348,23 @@ impl Plugin for ScorePlugin {
app
// Resource initialization
.add_systems(Startup, init_score)

// UI management
.add_systems(OnEnter(GameState::Playing), (setup_score_ui, update_score_display))
.add_systems(
OnEnter(GameState::Playing),
(setup_score_ui, update_score_display),
)
.add_systems(OnExit(GameState::Playing), cleanup_score_ui)
.add_systems(OnEnter(GameState::Playing), on_resume)

// Score display updates
.add_systems(Update, update_score_display.run_if(in_state(GameState::Playing)))

.add_systems(
Update,
update_score_display.run_if(in_state(GameState::Playing)),
)
// Gameplay systems
.add_systems(
Update,
(handle_scoring, handle_serve_delay, check_victory)
.run_if(in_state(GameState::Playing)),
);
}
}
}

0 comments on commit 2da636e

Please sign in to comment.