Browse Source

Cargo fmt

Getty Ritter 4 years ago
parent
commit
6a86dc282d
3 changed files with 38 additions and 22 deletions
  1. 28 14
      carpet/src/lib.rs
  2. 3 3
      ch1/src/main.rs
  3. 7 5
      ch2/src/main.rs

+ 28 - 14
carpet/src/lib.rs

@@ -1,6 +1,6 @@
-use ggez::{Context,GameError};
-use ggez::graphics::{Drawable,DrawParam,Image};
-use ggez::graphics::spritebatch::{SpriteBatch,SpriteIdx};
+use ggez::graphics::spritebatch::{SpriteBatch, SpriteIdx};
+use ggez::graphics::{DrawParam, Drawable, Image};
+use ggez::{Context, GameError};
 use std::path::Path;
 
 /// we only care about 16x16 tilesets
@@ -35,7 +35,11 @@ pub struct Tileset {
 }
 
 impl Tileset {
-    pub fn from_file(ctx: &mut Context, tile_size: impl Into<Size>, file: impl AsRef<Path>) -> Result<Tileset, GameError> {
+    pub fn from_file(
+        ctx: &mut Context,
+        tile_size: impl Into<Size>,
+        file: impl AsRef<Path>,
+    ) -> Result<Tileset, GameError> {
         let tile_size = tile_size.into();
         let image = Image::new(ctx, file)?;
         let mut batch = SpriteBatch::new(image);
@@ -43,10 +47,11 @@ impl Tileset {
         Ok(Tileset { tile_size, batch })
     }
 
-    fn to_screen(&self, coord: impl Into<Coord>) -> [f32;2] {
+    fn to_screen(&self, coord: impl Into<Coord>) -> [f32; 2] {
         let Coord { x, y } = coord.into();
-        [(x * self.tile_size.width) as f32,
-         (y * self.tile_size.height) as f32,
+        [
+            (x * self.tile_size.width) as f32,
+            (y * self.tile_size.height) as f32,
         ]
     }
 }
@@ -57,8 +62,8 @@ pub struct Size {
     height: usize,
 }
 
-impl From<[usize;2]> for Size {
-    fn from([width, height]: [usize;2]) -> Size {
+impl From<[usize; 2]> for Size {
+    fn from([width, height]: [usize; 2]) -> Size {
         Size { width, height }
     }
 }
@@ -69,8 +74,8 @@ pub struct Coord {
     y: usize,
 }
 
-impl From<[usize;2]> for Coord {
-    fn from([x, y]: [usize;2]) -> Coord {
+impl From<[usize; 2]> for Coord {
+    fn from([x, y]: [usize; 2]) -> Coord {
         Coord { x, y }
     }
 }
@@ -88,10 +93,14 @@ impl Board {
                 contents.push((0u8, idx));
             }
         }
-        Board { size, contents, tileset }
+        Board {
+            size,
+            contents,
+            tileset,
+        }
     }
 
-    fn sprite_location(ch: u8) -> [f32;4] {
+    fn sprite_location(ch: u8) -> [f32; 4] {
         let u = f32::from(ch % 16) * TILE_SIZE;
         let v = f32::from(ch / 16) * TILE_SIZE;
         [u, v, TILE_SIZE, TILE_SIZE]
@@ -110,7 +119,12 @@ impl Board {
         self.tileset.batch.set(self.contents[idx].1, param).unwrap();
     }
 
-    pub fn set_with_color(&mut self, at: impl Into<Coord>, ch: u8, color: impl Into<ggez::graphics::Color>) {
+    pub fn set_with_color(
+        &mut self,
+        at: impl Into<Coord>,
+        ch: u8,
+        color: impl Into<ggez::graphics::Color>,
+    ) {
         let at = at.into();
         let idx = at.x + at.y * self.size.width;
         let param = DrawParam::new()

+ 3 - 3
ch1/src/main.rs

@@ -1,4 +1,4 @@
-use ggez::{Context, GameError, event::EventHandler};
+use ggez::{event::EventHandler, Context, GameError};
 
 struct State {
     board: carpet::Board,
@@ -30,8 +30,8 @@ fn main() -> Result<(), GameError> {
             ..ggez::conf::WindowMode::default()
         })
         .build()?;
-    let tileset = carpet::Tileset::from_file(&mut ctx, [8,8], "/terminal8x8.jpg")?;
-    let mut board = carpet::Board::new([80,50], tileset);
+    let tileset = carpet::Tileset::from_file(&mut ctx, [8, 8], "/terminal8x8.jpg")?;
+    let mut board = carpet::Board::new([80, 50], tileset);
     board.print([1, 1], "Hello, world!");
     let mut state = State { board };
     ggez::event::run(&mut ctx, &mut evloop, &mut state)

+ 7 - 5
ch2/src/main.rs

@@ -1,7 +1,9 @@
-#[macro_use] extern crate specs_derive;
-#[macro_use] extern crate specs_system_macro;
+#[macro_use]
+extern crate specs_derive;
+#[macro_use]
+extern crate specs_system_macro;
 
-use ggez::{Context, GameError, event::EventHandler};
+use ggez::{event::EventHandler, Context, GameError};
 use specs::prelude::*;
 
 #[derive(Component)]
@@ -81,8 +83,8 @@ fn main() -> Result<(), GameError> {
     world.register::<Pos>();
     world.register::<Renderable>();
     world.register::<MoveLeft>();
-    let tileset = carpet::Tileset::from_file(&mut ctx, [8,8], "/terminal8x8.jpg")?;
-    let mut board = carpet::Board::new([80,50], tileset);
+    let tileset = carpet::Tileset::from_file(&mut ctx, [8, 8], "/terminal8x8.jpg")?;
+    let mut board = carpet::Board::new([80, 50], tileset);
     board.print([1, 1], "Hello, world!");
 
     world