Browse Source

rustfmt up in this bizzzzzzzznas

Getty Ritter 4 years ago
parent
commit
862a3d2de7
8 changed files with 82 additions and 79 deletions
  1. 10 9
      src/com.rs
  2. 1 2
      src/consts.rs
  3. 9 12
      src/main.rs
  4. 15 13
      src/res.rs
  5. 14 16
      src/sys/drawing.rs
  6. 3 3
      src/sys/mod.rs
  7. 24 20
      src/sys/physics.rs
  8. 6 4
      src/types.rs

+ 10 - 9
src/com.rs

@@ -1,5 +1,5 @@
-use specs::{Component, VecStorage, NullStorage};
-use specs::world::{WorldExt};
+use specs::world::WorldExt;
+use specs::{Component, NullStorage, VecStorage};
 
 /// Register all the components with the world.
 pub fn register(world: &mut specs::World) {
@@ -34,9 +34,7 @@ impl Position {
     }
 
     pub fn to_grid(&self) -> (i32, i32) {
-        ((self.x / 24.0) as i32,
-         (self.y / 24.0) as i32,
-        )
+        ((self.x / 24.0) as i32, (self.y / 24.0) as i32)
     }
 
     pub fn moved(&self, vel: &Velocity) -> Position {
@@ -57,7 +55,6 @@ pub struct Velocity {
     pub dy: f32,
 }
 
-
 /// The `Sprite` components represents the current display location of
 /// a sprite in the spritesheet.
 #[derive(Component, Debug)]
@@ -109,7 +106,7 @@ pub struct Controlled;
 #[derive(Component, Debug)]
 #[storage(VecStorage)]
 pub struct Collision {
-    pub has_collision: bool
+    pub has_collision: bool,
 }
 
 #[derive(Component)]
@@ -119,13 +116,17 @@ pub struct Blocking {
 }
 
 impl Blocking {
-    pub fn new() -> Blocking { Default::default() }
+    pub fn new() -> Blocking {
+        Default::default()
+    }
 }
 
 impl Default for Blocking {
     fn default() -> Blocking {
         Blocking {
-            volume: Box::new(ncollide2d::shape::Cuboid::new(nalgebra::Vector2::new(11.0, 11.0))),
+            volume: Box::new(ncollide2d::shape::Cuboid::new(nalgebra::Vector2::new(
+                11.0, 11.0,
+            ))),
         }
     }
 }

+ 1 - 2
src/consts.rs

@@ -10,5 +10,4 @@ pub const BOARD_HEIGHT: usize = 12;
 pub const WINDOW_WIDTH: f32 = BOARD_WIDTH as f32 * (TILE_SIZE * SCALE);
 pub const WINDOW_HEIGHT: f32 = BOARD_HEIGHT as f32 * (TILE_SIZE * SCALE);
 pub const SCALE: f32 = 3.0;
-pub const TILED_TRUE: tiled::PropertyValue =
-    tiled::PropertyValue::BoolValue(true);
+pub const TILED_TRUE: tiled::PropertyValue = tiled::PropertyValue::BoolValue(true);

+ 9 - 12
src/main.rs

@@ -1,10 +1,9 @@
-#[macro_use] extern crate specs_derive;
+#[macro_use]
+extern crate specs_derive;
 
 use ggez::{
-    Context,
-    ContextBuilder,
-    GameResult,
     event::{self, EventHandler},
+    Context, ContextBuilder, GameResult,
 };
 
 mod nc {
@@ -14,8 +13,8 @@ mod nc {
 }
 use specs::world::WorldExt;
 
-pub mod consts;
 pub mod com;
+pub mod consts;
 pub mod game;
 pub mod res;
 pub mod sys;
@@ -84,15 +83,13 @@ fn main() -> Result<(), ggez::error::GameError> {
     world.insert(sprites);
     world.insert(res::KeySet::new());
 
-    let broad_phase: types::BPhase =
-        nc::DBVTBroadPhase::new(0.0f32);
+    let broad_phase: types::BPhase = nc::DBVTBroadPhase::new(0.0f32);
     world.insert(broad_phase);
 
-    let narrow_phase: types::NPhase =
-        nc::NarrowPhase::new(
-            Box::new(nc::DefaultContactDispatcher::new()),
-            Box::new(nc::DefaultProximityDispatcher::new()),
-        );
+    let narrow_phase: types::NPhase = nc::NarrowPhase::new(
+        Box::new(nc::DefaultContactDispatcher::new()),
+        Box::new(nc::DefaultProximityDispatcher::new()),
+    );
     world.insert(narrow_phase);
 
     let mut my_game = MyGame { world };

+ 15 - 13
src/res.rs

@@ -1,7 +1,7 @@
-use crate::consts;
 use crate::com::*;
+use crate::consts;
 
-use specs::world::{Builder,WorldExt};
+use specs::world::{Builder, WorldExt};
 use std::path::Path;
 
 #[derive(Debug, Default)]
@@ -36,7 +36,7 @@ enum DrawLayer {
     Decoration,
 }
 
-static DRAW_LAYERS: [DrawLayer;3] = [
+static DRAW_LAYERS: [DrawLayer; 3] = [
     DrawLayer::Background,
     DrawLayer::Foreground,
     DrawLayer::Decoration,
@@ -44,9 +44,7 @@ static DRAW_LAYERS: [DrawLayer;3] = [
 
 pub fn world_from_file<P: AsRef<Path>>(w: &mut specs::World, path: P) {
     let tiled::Map {
-        layers,
-        tilesets,
-        ..
+        layers, tilesets, ..
     } = tiled::parse_file(path.as_ref()).unwrap();
 
     for (phase, layer) in DRAW_LAYERS.iter().zip(layers) {
@@ -57,7 +55,8 @@ pub fn world_from_file<P: AsRef<Path>>(w: &mut specs::World, path: P) {
                     let y = y as f32 * consts::TILE_SIZE;
                     let u = ((n - 1) % 32) as u8;
                     let v = ((n - u as u32 - 1) / 32) as u8;
-                    let mut e = w.create_entity()
+                    let mut e = w
+                        .create_entity()
                         .with(Position { x, y })
                         .with(Sprite { u, v });
                     e = match phase {
@@ -66,12 +65,13 @@ pub fn world_from_file<P: AsRef<Path>>(w: &mut specs::World, path: P) {
                         DrawLayer::Decoration => e.with(Decoration),
                     };
 
-                    let e = if tilesets[0].tiles[n as usize].properties["pass"] ==
-                        tiled::PropertyValue::BoolValue(false) {
+                    let e = if tilesets[0].tiles[n as usize].properties["pass"]
+                        == tiled::PropertyValue::BoolValue(false)
+                    {
                         e.with(Blocking::new())
-                        } else {
-                            e
-                        };
+                    } else {
+                        e
+                    };
                     e.build();
                 }
             }
@@ -88,7 +88,9 @@ pub fn world_from_file<P: AsRef<Path>>(w: &mut specs::World, path: P) {
         .with(Velocity { dx: 0.0, dy: 0.0 })
         .with(Foreground)
         .with(Controlled)
-        .with(Collision { has_collision: false })
+        .with(Collision {
+            has_collision: false,
+        })
         .with(Blocking {
             volume: Box::new(ncollide2d::shape::Ball::new(10.0)),
         })

+ 14 - 16
src/sys/drawing.rs

@@ -1,12 +1,8 @@
+use crate::com::{self, Position, Sprite};
 use crate::consts;
-use crate::com::{self,Position,Sprite};
 use crate::game::MyGame;
 
-use ggez::{
-    Context,
-    graphics,
-    graphics::spritebatch::SpriteBatch,
-};
+use ggez::{graphics, graphics::spritebatch::SpriteBatch, Context};
 use specs::RunNow;
 
 /// The `Draw` system is parameterized by which phase we want to draw
@@ -17,7 +13,7 @@ pub struct Draw<'t, Phase> {
     pub _phase: Phase,
 }
 
-impl<'a, 't, Phase : specs::Component> specs::System<'a> for Draw<'t, Phase> {
+impl<'a, 't, Phase: specs::Component> specs::System<'a> for Draw<'t, Phase> {
     type SystemData = (
         specs::ReadStorage<'a, Position>,
         specs::ReadStorage<'a, Sprite>,
@@ -32,36 +28,38 @@ impl<'a, 't, Phase : specs::Component> specs::System<'a> for Draw<'t, Phase> {
             let param = graphics::DrawParam {
                 src: spr.to_rect(),
                 dest: pos.to_point(),
-                scale: mint::Vector2 { x: consts::SCALE, y: consts::SCALE },
+                scale: mint::Vector2 {
+                    x: consts::SCALE,
+                    y: consts::SCALE,
+                },
                 ..Default::default()
             };
             batch.add(param);
         }
         let basic: graphics::DrawParam = Default::default();
-        graphics::draw(
-            self.ctx,
-            &*batch,
-            basic).unwrap();
+        graphics::draw(self.ctx, &*batch, basic).unwrap();
         batch.clear();
     }
 }
 
-
 pub fn systems(game: &mut MyGame, ctx: &mut Context) -> ggez::GameResult<()> {
     graphics::clear(ctx, graphics::BLACK);
 
     Draw {
         ctx,
         _phase: com::Background,
-    }.run_now(&game.world);
+    }
+    .run_now(&game.world);
     Draw {
         ctx,
         _phase: com::Foreground,
-    }.run_now(&game.world);
+    }
+    .run_now(&game.world);
     Draw {
         ctx,
         _phase: com::Decoration,
-    }.run_now(&game.world);
+    }
+    .run_now(&game.world);
 
     graphics::present(ctx)
 }

+ 3 - 3
src/sys/mod.rs

@@ -1,5 +1,5 @@
-pub mod physics;
-pub mod input;
 pub mod drawing;
-pub use input::*;
+pub mod input;
+pub mod physics;
 pub use drawing::*;
+pub use input::*;

+ 24 - 20
src/sys/physics.rs

@@ -1,14 +1,12 @@
-use crate::com::{Blocking, Collision, Velocity, Position};
-use crate::types::{NPhase,BPhase};
+use crate::com::{Blocking, Collision, Position, Velocity};
 use crate::game::MyGame;
+use crate::types::{BPhase, NPhase};
 
 use nalgebra::{Isometry2, Vector2};
 use ncollide2d::broad_phase::{
-    broad_phase::BroadPhase,
-    broad_phase::BroadPhaseProxyHandle,
-    BroadPhaseInterferenceHandler,
+    broad_phase::BroadPhase, broad_phase::BroadPhaseProxyHandle, BroadPhaseInterferenceHandler,
 };
-use specs::{Join,RunNow};
+use specs::{Join, RunNow};
 
 struct InterferenceHandler<'a> {
     collisions: specs::WriteStorage<'a, Collision>,
@@ -21,15 +19,13 @@ impl<'a> BroadPhaseInterferenceHandler<specs::Entity> for InterferenceHandler<'a
     }
 
     fn interference_started(&mut self, a: &specs::Entity, b: &specs::Entity) {
-        self.collisions.get_mut(*a).map (|r| r.has_collision = true );
-        self.collisions.get_mut(*b).map (|r| r.has_collision = true );
+        self.collisions.get_mut(*a).map(|r| r.has_collision = true);
+        self.collisions.get_mut(*b).map(|r| r.has_collision = true);
     }
 
-    fn interference_stopped(&mut self, _: &specs::Entity, _: &specs::Entity) {
-    }
+    fn interference_stopped(&mut self, _: &specs::Entity, _: &specs::Entity) {}
 }
 
-
 struct Collide;
 
 impl<'a> specs::System<'a> for Collide {
@@ -43,20 +39,29 @@ impl<'a> specs::System<'a> for Collide {
         specs::WriteExpect<'a, NPhase>,
     );
 
-    fn run(&mut self, (entities, position, velocity, blocking, mut collisions, mut bf, _narrow): Self::SystemData) {
-        let _: Vec<()> = (&mut collisions).join().map( |c| c.has_collision = false ).collect();
-        let handles: Vec<BroadPhaseProxyHandle> =
-            (&entities, &position, &blocking).join().map( |(e, pos, bl)| {
+    fn run(
+        &mut self,
+        (entities, position, velocity, blocking, mut collisions, mut bf, _narrow): Self::SystemData,
+    ) {
+        let _: Vec<()> = (&mut collisions)
+            .join()
+            .map(|c| c.has_collision = false)
+            .collect();
+        let handles: Vec<BroadPhaseProxyHandle> = (&entities, &position, &blocking)
+            .join()
+            .map(|(e, pos, bl)| {
                 let np = if let Some(vel) = velocity.get(e) {
                     pos.moved(vel)
                 } else {
                     pos.clone()
                 };
                 bf.create_proxy(
-                    bl.volume.aabb(&Isometry2::new(Vector2::new(np.x, np.y), nalgebra::zero())),
+                    bl.volume
+                        .aabb(&Isometry2::new(Vector2::new(np.x, np.y), nalgebra::zero())),
                     e,
                 )
-        }).collect();
+            })
+            .collect();
 
         bf.update(&mut InterferenceHandler {
             collisions: collisions,
@@ -93,7 +98,7 @@ impl<'a> specs::System<'a> for Intersection {
 
 struct Physics;
 
-impl <'a> specs::System<'a> for Physics {
+impl<'a> specs::System<'a> for Physics {
     type SystemData = (
         specs::ReadStorage<'a, Velocity>,
         specs::ReadStorage<'a, Collision>,
@@ -113,8 +118,7 @@ impl <'a> specs::System<'a> for Physics {
 struct ResetCollision;
 
 impl<'a> specs::System<'a> for ResetCollision {
-    type SystemData =
-        specs::WriteStorage<'a, Collision>;
+    type SystemData = specs::WriteStorage<'a, Collision>;
 
     fn run(&mut self, mut collision: Self::SystemData) {
         for mut e in (&mut collision).join() {

+ 6 - 4
src/types.rs

@@ -1,4 +1,6 @@
-pub type BPhase =
-    ncollide2d::broad_phase::DBVTBroadPhase<f32, ncollide2d::bounding_volume::AABB<f32>, specs::Entity>;
-pub type NPhase =
-    ncollide2d::narrow_phase::NarrowPhase<f32, ()>;
+pub type BPhase = ncollide2d::broad_phase::DBVTBroadPhase<
+    f32,
+    ncollide2d::bounding_volume::AABB<f32>,
+    specs::Entity,
+>;
+pub type NPhase = ncollide2d::narrow_phase::NarrowPhase<f32, ()>;