|  | @@ -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()
 |