Browse Source

cargo fmt

Getty Ritter 4 years ago
parent
commit
25a2771696
2 changed files with 42 additions and 26 deletions
  1. 42 25
      carpet/src/lib.rs
  2. 0 1
      ch2/src/main.rs

+ 42 - 25
carpet/src/lib.rs

@@ -21,14 +21,13 @@ impl From<Color> for ggez::graphics::Color {
     }
 }
 
-
 /// The `Tile` trait is used to identify which tile we care about on a
 /// tilesheet, and also to provide a sensible 'blank' tile. The tile
 /// identifiers we care about should at least be `Clone`, but often
 /// they'll be (wrappers over) small identifiers (like a `u8` or a
 /// `u16`) and could probably be `Copy`.
 pub trait Tile: Clone + Send + Sync {
-    fn to_location(self) -> [f32;4];
+    fn to_location(self) -> [f32; 4];
     fn blank() -> Self;
 }
 
@@ -54,7 +53,7 @@ impl CP437 {
             0x2022 => 7,
             // fill this in some time later
             // standard ASCII mappings
-            0x20 ..= 0x7e => ch as u8,
+            0x20..=0x7e => ch as u8,
             0x2302 => 0x7f,
             _ => panic!("Character {} does not have a CP437 equivalent", ch),
         })
@@ -62,7 +61,7 @@ impl CP437 {
 }
 
 impl Tile for CP437 {
-    fn to_location(self) -> [f32;4] {
+    fn to_location(self) -> [f32; 4] {
         const TILE_SIZE: f32 = 1.0 / 16.0;
         let u = f32::from(self.0 % 16) * TILE_SIZE;
         let v = f32::from(self.0 / 16) * TILE_SIZE;
@@ -74,7 +73,6 @@ impl Tile for CP437 {
     }
 }
 
-
 pub struct Board<Idx: Tile> {
     size: Size,
     contents: Vec<(Idx, SpriteIdx)>,
@@ -224,7 +222,7 @@ fn do_nothing() -> Updater {
     Box::new(|_| {})
 }
 
-impl <Idx: Tile + 'static> World<Idx> {
+impl<Idx: Tile + 'static> World<Idx> {
     pub fn new(board: Board<Idx>) -> World<Idx> {
         let mut world = specs::World::new();
         world.insert(board);
@@ -289,19 +287,20 @@ pub struct Game<Idx> {
     pub world: World<Idx>,
 }
 
-
 impl<Idx: Tile + 'static> Game<Idx> {
-    pub fn create(board: Board<Idx>, ctx: ggez::Context, evloop: ggez::event::EventsLoop) -> Result<Game<Idx>, ggez::GameError> {
+    pub fn create(
+        board: Board<Idx>,
+        ctx: ggez::Context,
+        evloop: ggez::event::EventsLoop,
+    ) -> Result<Game<Idx>, ggez::GameError> {
         let world = World::new(board);
-        Ok(Game {
-            world,
-            ctx,
-            evloop,
-        })
+        Ok(Game { world, ctx, evloop })
     }
 
     pub fn register<C>(&mut self)
-        where C: specs::Component, <C as specs::Component>::Storage: std::default::Default
+    where
+        C: specs::Component,
+        <C as specs::Component>::Storage: std::default::Default,
     {
         self.world.world.register::<C>();
     }
@@ -315,18 +314,28 @@ impl<Idx: Tile + 'static> Game<Idx> {
     }
 
     pub fn run(self) -> ggez::GameResult<()> {
-        let Game { mut world, mut ctx, mut evloop } = self;
+        let Game {
+            mut world,
+            mut ctx,
+            mut evloop,
+        } = self;
         ggez::event::run(&mut ctx, &mut evloop, &mut world)
     }
 
-    pub fn run_with_systems(self, update: impl FnMut(&mut specs::World) + 'static) -> ggez::GameResult<()> {
-        let Game { mut world, mut ctx, mut evloop } = self;
+    pub fn run_with_systems(
+        self,
+        update: impl FnMut(&mut specs::World) + 'static,
+    ) -> ggez::GameResult<()> {
+        let Game {
+            mut world,
+            mut ctx,
+            mut evloop,
+        } = self;
         world.on_update(update);
         ggez::event::run(&mut ctx, &mut evloop, &mut world)
     }
 }
 
-
 // game builder
 use std::path::PathBuf;
 
@@ -334,9 +343,9 @@ pub struct GameBuilder<Idx: Tile> {
     name: String,
     author: String,
     resource_path: Option<PathBuf>,
-    tile_size: Option<[usize;2]>,
+    tile_size: Option<[usize; 2]>,
     tile_path: Option<PathBuf>,
-    map_size: Option<[usize;2]>,
+    map_size: Option<[usize; 2]>,
     idx: std::marker::PhantomData<Idx>,
 }
 
@@ -368,7 +377,11 @@ impl<Idx: Tile + 'static> GameBuilder<Idx> {
         self
     }
 
-    pub fn tileset(mut self, image: impl AsRef<Path>, size: impl Into<[usize;2]>) -> GameBuilder<Idx> {
+    pub fn tileset(
+        mut self,
+        image: impl AsRef<Path>,
+        size: impl Into<[usize; 2]>,
+    ) -> GameBuilder<Idx> {
         self.tile_path = Some(image.as_ref().to_path_buf());
         self.tile_size = Some(size.into());
         self
@@ -381,13 +394,17 @@ impl<Idx: Tile + 'static> GameBuilder<Idx> {
 
     pub fn build(self) -> ggez::GameResult<Game<Idx>> {
         use ggez::error::GameError::ResourceLoadError;
-        let resource_path = self.resource_path
+        let resource_path = self
+            .resource_path
             .ok_or_else(|| ResourceLoadError("No resource path specified".to_owned()))?;
-        let tile_path = self.tile_path
+        let tile_path = self
+            .tile_path
             .ok_or_else(|| ResourceLoadError("No tile path specified".to_owned()))?;
-        let tile_size = self.tile_size
+        let tile_size = self
+            .tile_size
             .ok_or_else(|| ResourceLoadError("No tile size specified".to_owned()))?;
-        let map_size = self.map_size
+        let map_size = self
+            .map_size
             .ok_or_else(|| ResourceLoadError("No map size specified".to_owned()))?;
         let (mut ctx, evloop) = ggez::ContextBuilder::new(&self.name, &self.author)
             .add_resource_path(resource_path)

+ 0 - 1
ch2/src/main.rs

@@ -21,7 +21,6 @@ pub struct Renderable {
 #[derive(Component)]
 pub struct MoveLeft;
 
-
 system_impl! {
     Draw(
         resource mut board: carpet::Board<carpet::CP437>,