Skip to content

Commit

Permalink
chore(clippy): apply auto fix and manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kai-patel committed May 30, 2023
1 parent cb8fd4c commit 66118bc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 51 deletions.
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use egui_extras::TableBuilder;
use heron::prelude::*;
use leafwing_input_manager::prelude::*;
mod universe;
use universe::universe::{debug_universe, Galaxy};
use universe::{debug_universe, Galaxy};

#[derive(Default, Debug)]
struct UiState {
Expand Down Expand Up @@ -356,6 +356,7 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
});
}

#[allow(clippy::type_complexity)]
fn handle_ui_click(
mut query: Query<&Interaction, (Changed<Interaction>, With<Button>, With<DisplayCargo>)>,
mut ui_state: ResMut<UiState>,
Expand Down Expand Up @@ -392,8 +393,7 @@ fn ship_cargo_ui(
) {
let (mut cargo_hold, _) = query
.iter_mut()
.filter(|(_, ship)| ship.primary)
.nth(0)
.find(|(_, ship)| ship.primary)
.expect("Expected one and only one primary ship to exist");

egui::Window::new("Ship Cargo")
Expand Down Expand Up @@ -450,6 +450,7 @@ fn ship_cargo_ui(
ui_state.set_changed();
}

#[allow(clippy::type_complexity)]
fn handle_actions(
mut commands: Commands,
query: Query<&ActionState<Action>, With<Ship>>,
Expand Down
92 changes: 44 additions & 48 deletions src/universe.rs
Original file line number Diff line number Diff line change
@@ -1,66 +1,62 @@
pub mod universe {
use bevy::prelude::{debug, Res};
use petgraph::prelude::*;
use bevy::prelude::{debug, Res};
use petgraph::prelude::*;

#[derive(Debug, Default)]
pub struct Galaxy(Vec<u32>);
#[derive(Debug, Default)]
pub struct Galaxy(Vec<u32>);

impl Galaxy {
pub fn new() -> Self {
Galaxy::default()
}

pub fn from_file(_file_path: &str) -> Self {
println!("TODO: Load Galaxy from file");
let graph = random_graph(5, EdgeProbability(0.9));
println!("Random graph generated: {:?}", graph);
Galaxy::new()
}
impl Galaxy {
pub fn new() -> Self {
Galaxy::default()
}

#[allow(dead_code)]
#[derive(Debug, Default)]
pub struct SolarSystem {
star: String,
planets: Vec<Planet>,
pub fn from_file(_file_path: &str) -> Self {
println!("TODO: Load Galaxy from file");
let graph = random_graph(5, EdgeProbability(0.9));
println!("Random graph generated: {:?}", graph);
Galaxy::new()
}
}

#[derive(Debug, Default)]
struct Planet((String, Option<Vec<Station>>));
#[allow(dead_code)]
#[derive(Debug, Default)]
pub struct SolarSystem {
star: String,
planets: Vec<Planet>,
}

#[derive(Debug, Default)]
struct Station(String);
#[derive(Debug, Default)]
struct Planet((String, Option<Vec<Station>>));

#[derive(Debug, Default)]
struct EdgeProbability(f32);
#[derive(Debug, Default)]
struct Station(String);

#[allow(dead_code)]
impl EdgeProbability {
fn new(p: f32) -> Self {
EdgeProbability(p.clamp(0., 1.))
}
#[derive(Debug, Default)]
struct EdgeProbability(f32);

fn get(&self) -> f32 {
self.0
}
#[allow(dead_code)]
impl EdgeProbability {
fn new(p: f32) -> Self {
EdgeProbability(p.clamp(0., 1.))
}

pub fn debug_universe(universe: Res<Galaxy>) {
debug!("Debug Universe {:?}", universe);
fn get(&self) -> f32 {
self.0
}
}

pub fn debug_universe(universe: Res<Galaxy>) {
debug!("Debug Universe {:?}", universe);
}

fn random_graph(order: u32, probability: EdgeProbability) -> UnGraph<u32, ()> {
let mut edges = Vec::<(u32, u32)>::new();
for i in 0..=order {
for j in i..=order {
if i != j {
if rand::random::<f32>() < probability.get() {
edges.push((i, j));
}
}
fn random_graph(order: u32, probability: EdgeProbability) -> UnGraph<u32, ()> {
let mut edges = Vec::<(u32, u32)>::new();
for i in 0..=order {
for j in i..=order {
if i != j && rand::random::<f32>() < probability.get() {
edges.push((i, j));
}
}

UnGraph::from_edges(edges)
}

UnGraph::from_edges(edges)
}

0 comments on commit 66118bc

Please sign in to comment.