From 5a23dde43ac82d8735b885ce62620afd74618ef7 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 5 Oct 2024 15:18:41 +0200 Subject: [PATCH] clean up tile rendering --- assets/missing.png | Bin 0 -> 148 bytes assets/transparent.png | Bin 0 -> 75 bytes src/marble_engine.rs | 2 -- src/marble_engine/board.rs | 9 ++++++++- src/marble_engine/tile.rs | 38 ++++++------------------------------- 5 files changed, 14 insertions(+), 35 deletions(-) create mode 100644 assets/missing.png create mode 100644 assets/transparent.png diff --git a/assets/missing.png b/assets/missing.png new file mode 100644 index 0000000000000000000000000000000000000000..3f524101447f5a24d6672718e99eef7820daea5b GIT binary patch literal 148 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|(Vi}jAsQ2t|NQ@N&#c+N8vLSh zmz7cY!)LxJdct*AXDInZJQc~i=VC0eocBcDfmQ9StAlJ9x_M{lsdzDOs^`c)uyj_# vxAwlR3R`njxgN@xNA(Tp&< literal 0 HcmV?d00001 diff --git a/assets/transparent.png b/assets/transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..f02154247c2653f7aa4f2c50135ee47eb28d1f9f GIT binary patch literal 75 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`LY^*;Ar`&K2@, - 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() } }