From 4ccbefd5580d250ce9105d94129613957cdb1c0d Mon Sep 17 00:00:00 2001 From: core Date: Thu, 10 Jul 2025 21:36:58 -0400 Subject: [PATCH] chore(fmt,lint): pass clippy --- crates/unified/src/attachment.rs | 5 +- crates/unified/src/client/key_input.rs | 13 ++- crates/unified/src/client/mod.rs | 5 +- crates/unified/src/client/parts.rs | 111 ++++++++++++++-------- crates/unified/src/ecs.rs | 7 +- crates/unified/src/lib.rs | 12 ++- crates/unified/src/particle_editor/ecs.rs | 1 + crates/unified/src/particle_editor/mod.rs | 72 ++++++++------ crates/unified/src/particles.rs | 28 +++--- crates/unified/src/server/gravity.rs | 2 +- crates/unified/src/server/mod.rs | 6 +- crates/unified/src/server/part.rs | 63 ++++++------ crates/unified/src/server/player.rs | 28 ++---- crates/unified/src/server/system_sets.rs | 2 +- crates/unified/src/server_plugins.rs | 4 +- crates/unified/src/shared_plugins.rs | 2 +- 16 files changed, 210 insertions(+), 151 deletions(-) diff --git a/crates/unified/src/attachment.rs b/crates/unified/src/attachment.rs index ab32e03fccbeb60a07f9b229e9f1022fa565aad6..2bd998c87a213fed8bae9fb7a3e046ee164ac879 100644 --- a/crates/unified/src/attachment.rs +++ b/crates/unified/src/attachment.rs @@ -1,7 +1,7 @@ -use std::ops::Deref; use bevy::ecs::entity::MapEntities; use bevy::prelude::*; use serde::{Deserialize, Serialize}; +use std::ops::Deref; #[derive(Component, Serialize, Deserialize)] /// The primary component for a ship structure @@ -47,7 +47,8 @@ impl Deref for Snaps { #[derive(Serialize, Deserialize)] pub struct JointId(pub String); impl JointId { - #[must_use] pub fn from_part_and_joint_id(part: String, joint: String) -> Self { + #[must_use] + pub fn from_part_and_joint_id(part: String, joint: String) -> Self { Self(format!("{part}:{joint}")) } } diff --git a/crates/unified/src/client/key_input.rs b/crates/unified/src/client/key_input.rs index ff67c3b6d5a105017930fba4e9d7844c3ec406a8..1f42ac5d30763757bc743a583ab479b332c7c3a4 100644 --- a/crates/unified/src/client/key_input.rs +++ b/crates/unified/src/client/key_input.rs @@ -1,5 +1,4 @@ -use std::ops::Deref; -use crate::attachment::{Joint, JointOf, SnapOf, SnapOfJoint}; +use crate::attachment::{JointOf, SnapOf}; use crate::ecs::{Part, ThrustEvent}; use bevy::color::palettes::css::{FUCHSIA, GREEN}; use bevy::dev_tools::picking_debug::DebugPickingMode; @@ -10,8 +9,8 @@ use bevy::{ ecs::{event::EventWriter, system::Res}, input::{ButtonInput, keyboard::KeyCode}, }; -use bevy::log::debug; use bevy_rapier2d::render::DebugRenderContext; +use std::ops::Deref; pub fn key_input_plugin(app: &mut App) { app.add_systems(Update, directional_keys) @@ -84,12 +83,16 @@ fn draw_attachment_debug( return; } for (offset, parent) in joints.iter() { - let Ok(parent_pos) = parts.get(parent.0) else { continue; }; + let Ok(parent_pos) = parts.get(parent.0) else { + continue; + }; let joint_target = parent_pos.transform_point(offset.translation); gizmos.cross_2d(joint_target.xy(), 4.0, FUCHSIA); } for (offset, parent) in snaps.iter() { - let Ok(parent_pos) = parts.get(parent.0) else { continue; }; + let Ok(parent_pos) = parts.get(parent.0) else { + continue; + }; let joint_snap = parent_pos.transform_point(offset.translation); gizmos.cross_2d(joint_snap.xy(), 4.0, GREEN); } diff --git a/crates/unified/src/client/mod.rs b/crates/unified/src/client/mod.rs index b0159f71414434f501d2c4fd5359c58400487daf..682e0e79a37cad52cb9c9e5257d9cd8827dcdb68 100644 --- a/crates/unified/src/client/mod.rs +++ b/crates/unified/src/client/mod.rs @@ -70,7 +70,10 @@ fn find_me( commands.entity(entity).insert(Me); let mut heart_sprite = Sprite::from_image(asset_server.load("sprites/hearty_heart.png")); - heart_sprite.custom_size = Some(Vec2::new(part.strong_config.physics.width, part.strong_config.physics.height)); + heart_sprite.custom_size = Some(Vec2::new( + part.strong_config.physics.width, + part.strong_config.physics.height, + )); heart_sprite.color = Color::srgb(20.0, 0.0, 0.0); commands.spawn(( diff --git a/crates/unified/src/client/parts.rs b/crates/unified/src/client/parts.rs index 904bc12dc3302fc45bbfa0351769b83505a47e62..c70ed0680461760251ea2c23b9ff0b23ad6c1981 100644 --- a/crates/unified/src/client/parts.rs +++ b/crates/unified/src/client/parts.rs @@ -1,18 +1,24 @@ -use bevy::color::palettes::css::{ORANGE, RED}; -use bevy::color::palettes::tailwind::{CYAN_400, CYAN_800}; +use crate::attachment::{JointOf, PartInShip, Peer, SnapOf, SnapOfJoint}; use crate::client::Me; +use crate::client::colors::GREEN; +use crate::client::key_input::AttachmentDebugRes; use crate::ecs::{CursorWorldCoordinates, DragRequestEvent, Part}; +use bevy::color::palettes::css::{ORANGE, RED}; use bevy::prelude::*; use bevy_rapier2d::dynamics::MassProperties; use bevy_rapier2d::prelude::AdditionalMassProperties; -use crate::attachment::{JointOf, PartInShip, Peer, SnapOf, SnapOfJoint}; -use crate::client::colors::GREEN; -use crate::client::key_input::AttachmentDebugRes; pub fn parts_plugin(app: &mut App) { app.insert_resource(DragResource(None)); app.insert_resource(SnapResource(None)); - app.add_systems(Update, (handle_incoming_parts, handle_updated_parts, update_drag_ghosts)); + app.add_systems( + Update, + ( + handle_incoming_parts, + handle_updated_parts, + update_drag_ghosts, + ), + ); app.add_observer(on_part_release); } @@ -22,8 +28,12 @@ fn handle_incoming_parts( asset_server: Res, ) { for (new_entity, new_part) in new_parts.iter() { - let mut sprite = Sprite::from_image(asset_server.load(&new_part.strong_config.part.sprite_disconnected)); - sprite.custom_size = Some(Vec2::new(new_part.strong_config.physics.width, new_part.strong_config.physics.height)); + let mut sprite = + Sprite::from_image(asset_server.load(&new_part.strong_config.part.sprite_disconnected)); + sprite.custom_size = Some(Vec2::new( + new_part.strong_config.physics.width, + new_part.strong_config.physics.height, + )); commands .entity(new_entity) @@ -43,8 +53,13 @@ fn handle_updated_parts( asset_server: Res, ) { for (updated_entity, updated_part) in updated_parts.iter() { - let mut sprite = Sprite::from_image(asset_server.load(&updated_part.strong_config.part.sprite_disconnected)); - sprite.custom_size = Some(Vec2::new(updated_part.strong_config.physics.width, updated_part.strong_config.physics.height)); + let mut sprite = Sprite::from_image( + asset_server.load(&updated_part.strong_config.part.sprite_disconnected), + ); + sprite.custom_size = Some(Vec2::new( + updated_part.strong_config.physics.width, + updated_part.strong_config.physics.height, + )); commands .entity(updated_entity) @@ -71,7 +86,7 @@ fn on_part_click( ev: Trigger>, sprites: Query<(&Sprite, &Transform), Without>, mut drag: ResMut, - mut commands: Commands + mut commands: Commands, ) { if ev.button != PointerButton::Primary { return; @@ -81,11 +96,7 @@ fn on_part_click( }; let mut s = sprite.0.clone(); s.color = Color::srgba(0.7, 0.7, 0.7, 1.0); - commands.spawn(( - DragGhost, - sprite.1.clone(), - s - )); + commands.spawn((DragGhost, *sprite.1, s)); drag.0 = Some(ev.target()); } @@ -97,14 +108,14 @@ fn on_part_release( cursor: Res, mut commands: Commands, ghost: Single<(Entity, &Transform), With>, - snap: Res + snap: Res, ) { if ev.button != PointerButton::Primary { return; } if let Some(e) = drag.0 { - let mut rotation = ghost.1.rotation; + let rotation = ghost.1.rotation; commands.entity(ghost.0).despawn(); if let Some(c) = cursor.0 { @@ -121,14 +132,21 @@ fn on_part_release( drag.0 = None; } - /// !IMPORTANT! /// This function forms the bulk of the attachment system. /// PLEASE DO NOT MODIFY OR MOVE /// /// This code is super cursed, and it will break at the lightest breeze fn update_drag_ghosts( - mut ghost: Single<&mut Transform, (With, Without, Without, Without)>, + mut ghost: Single< + &mut Transform, + ( + With, + Without, + Without, + Without, + ), + >, cursor: Res, snaps: Query<(&Transform, &SnapOfJoint, &SnapOf, Entity)>, joints: Query<(&Transform, &JointOf, Entity), Without>, @@ -141,46 +159,63 @@ fn update_drag_ghosts( keys: Res>, time: Res