clean up tile rendering
This commit is contained in:
parent
86548a8b0d
commit
5a23dde43a
5 changed files with 14 additions and 35 deletions
BIN
assets/missing.png
Normal file
BIN
assets/missing.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 148 B |
BIN
assets/transparent.png
Normal file
BIN
assets/transparent.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 75 B |
|
@ -1,5 +1,3 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use raylib::prelude::*;
|
||||
|
||||
pub mod board;
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, Texture2D>,
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue