diff --git a/assets/missing.png b/assets/missing.png new file mode 100644 index 0000000..3f52410 Binary files /dev/null and b/assets/missing.png differ diff --git a/assets/transparent.png b/assets/transparent.png new file mode 100644 index 0000000..f021542 Binary files /dev/null and b/assets/transparent.png differ diff --git a/src/marble_engine.rs b/src/marble_engine.rs index 87a5706..9a4ce86 100644 --- a/src/marble_engine.rs +++ b/src/marble_engine.rs @@ -1,5 +1,3 @@ -use std::collections::HashMap; - use raylib::prelude::*; pub mod board; diff --git a/src/marble_engine/board.rs b/src/marble_engine/board.rs index 722a981..0a7c4a9 100644 --- a/src/marble_engine/board.rs +++ b/src/marble_engine/board.rs @@ -101,7 +101,14 @@ impl Board { if let Some(tile) = self.get((x, y).into()) { let px = x as i32 * tile_size + offset.x as i32 + tile_size / 2; let py = y as i32 * tile_size + offset.y as i32 + tile_size / 2; - tile.draw(d, textures, px, py, tile_size, zoom); + let texture = textures.get(&tile.texture()).unwrap_or_else(||textures.get("missing").unwrap()); + d.draw_texture_ex( + texture, + Vector2::new((px - tile_size / 2) as f32, (py - tile_size / 2) as f32), + 0.0, + (1 << zoom) as f32, + Color::WHITE, + ); } } } diff --git a/src/marble_engine/tile.rs b/src/marble_engine/tile.rs index a037786..7c2da37 100644 --- a/src/marble_engine/tile.rs +++ b/src/marble_engine/tile.rs @@ -1,7 +1,3 @@ -use std::collections::HashMap; - -use raylib::prelude::*; - use super::board::Pos; pub type MarbleValue = u32; @@ -84,17 +80,9 @@ impl Tile { } } - pub fn draw( - &self, - d: &mut RaylibDrawHandle, - textures: &HashMap, - x: i32, - y: i32, - size: i32, - zoom: i32, - ) { - let tex_name = match self { - Tile::Blank => "", + pub fn texture(&self) -> String { + match self { + Tile::Blank => "transparent", Tile::Block => "block", Tile::Marble { value: _, dir: _ } => "marble", Tile::Digit(n) => match n { @@ -121,7 +109,7 @@ impl Tile { Direction::Right => "right", }, Tile::Powerable(tile, state) => { - let t = match tile { + let root = match tile { PTile::Trigger => "trigger", PTile::Wire(wire) => match wire { WireType::Vertical => "wire_vertical", @@ -146,24 +134,10 @@ impl Tile { PTile::Input => "input", PTile::Output => "output", }; - &format!("{t}_{}", if *state { "on" } else { "off" }) + return format!("{root}_{}", if *state { "on" } else { "off" }); } - }; - if let Some(texture) = textures.get(tex_name) { - d.draw_texture_ex( - texture, - Vector2::new((x - size / 2) as f32, (y - size / 2) as f32), - 0.0, - (1 << zoom) as f32, - Color::WHITE, - ); - return; - } - - match self { - Tile::Blank => (), - _ => d.draw_rectangle(x - size / 2, y - size / 2, size, size, Color::RED), } + .to_owned() } }