add sub-tick debugging, add direction information to state of powerable tiles
This commit is contained in:
parent
181f76a341
commit
d3a3471fcb
8 changed files with 176 additions and 65 deletions
|
@ -214,6 +214,16 @@ impl Board {
|
|||
}
|
||||
let texture = textures.get(texname);
|
||||
draw_scaled_texture(d, texture, px, py, scale);
|
||||
#[cfg(debug_assertions)]
|
||||
// TODO: some in-game option to show power direction
|
||||
if let Tile::Powerable(_, state) = &tile {
|
||||
for dir in Direction::ALL {
|
||||
if state.get_dir(dir) {
|
||||
let texture = textures.get(dir.debug_arrow_texture_name());
|
||||
draw_scaled_texture(d, texture, px, py, scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
d.draw_rectangle(px, py, tile_size, tile_size, Color::new(0, 0, 0, 80));
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ pub enum Tile {
|
|||
Arrow(Direction),
|
||||
Button(bool),
|
||||
Wire(WireType, bool),
|
||||
Powerable(PTile, bool),
|
||||
Powerable(PTile, Power),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
|
@ -38,6 +38,11 @@ pub enum PTile {
|
|||
IO,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Power {
|
||||
directions: u8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum MirrorType {
|
||||
Forward,
|
||||
|
@ -94,18 +99,18 @@ impl Tile {
|
|||
'v' => Tile::Arrow(Direction::Down),
|
||||
'<' => Tile::Arrow(Direction::Left),
|
||||
'>' => Tile::Arrow(Direction::Right),
|
||||
'=' => Tile::Powerable(PTile::Comparator(Comparison::Equal), false),
|
||||
'!' => Tile::Powerable(PTile::Comparator(Comparison::NotEqual), false),
|
||||
'L' => Tile::Powerable(PTile::Comparator(Comparison::LessThan), false),
|
||||
'G' => Tile::Powerable(PTile::Comparator(Comparison::GreaterThan), false),
|
||||
'I' | 'P' => Tile::Powerable(PTile::IO, false),
|
||||
'F' => Tile::Powerable(PTile::Flipper, false),
|
||||
'A' => Tile::Powerable(PTile::Math(MathOp::Add), false),
|
||||
'S' => Tile::Powerable(PTile::Math(MathOp::Sub), false),
|
||||
'M' => Tile::Powerable(PTile::Math(MathOp::Mul), false),
|
||||
'D' => Tile::Powerable(PTile::Math(MathOp::Div), false),
|
||||
'R' => Tile::Powerable(PTile::Math(MathOp::Rem), false),
|
||||
'B' => Tile::Powerable(PTile::Silo, false),
|
||||
'=' => Tile::Powerable(PTile::Comparator(Comparison::Equal), Power::OFF),
|
||||
'!' => Tile::Powerable(PTile::Comparator(Comparison::NotEqual), Power::OFF),
|
||||
'L' => Tile::Powerable(PTile::Comparator(Comparison::LessThan), Power::OFF),
|
||||
'G' => Tile::Powerable(PTile::Comparator(Comparison::GreaterThan), Power::OFF),
|
||||
'I' | 'P' => Tile::Powerable(PTile::IO, Power::OFF),
|
||||
'F' => Tile::Powerable(PTile::Flipper, Power::OFF),
|
||||
'A' => Tile::Powerable(PTile::Math(MathOp::Add), Power::OFF),
|
||||
'S' => Tile::Powerable(PTile::Math(MathOp::Sub), Power::OFF),
|
||||
'M' => Tile::Powerable(PTile::Math(MathOp::Mul), Power::OFF),
|
||||
'D' => Tile::Powerable(PTile::Math(MathOp::Div), Power::OFF),
|
||||
'R' => Tile::Powerable(PTile::Math(MathOp::Rem), Power::OFF),
|
||||
'B' => Tile::Powerable(PTile::Silo, Power::OFF),
|
||||
d @ '0'..='9' => Tile::Open(OpenTile::Digit(d as u8 - b'0'), Claim::Free),
|
||||
'#' => Tile::Block,
|
||||
_ => Tile::Open(OpenTile::Blank, Claim::Free),
|
||||
|
@ -200,7 +205,7 @@ impl Tile {
|
|||
wire.texture_name_off()
|
||||
}
|
||||
Tile::Powerable(tile, state) => {
|
||||
if state {
|
||||
if state.any() {
|
||||
return match tile {
|
||||
PTile::Comparator(comp) => comp.texture_name_on(),
|
||||
PTile::Math(math_op) => math_op.texture_name_on(),
|
||||
|
@ -270,6 +275,15 @@ impl Direction {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn debug_arrow_texture_name(self) -> &'static str {
|
||||
match self {
|
||||
Direction::Up => "debug_arrow_up",
|
||||
Direction::Down => "debug_arrow_down",
|
||||
Direction::Left => "debug_arrow_left",
|
||||
Direction::Right => "debug_arrow_right",
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn arrow_tile_human_name(self) -> &'static str {
|
||||
match self {
|
||||
Direction::Up => "Up Arrow",
|
||||
|
@ -517,3 +531,22 @@ impl Claim {
|
|||
was_free
|
||||
}
|
||||
}
|
||||
|
||||
impl Power {
|
||||
pub const OFF: Self = Self { directions: 0 };
|
||||
|
||||
#[inline]
|
||||
pub fn any(self) -> bool {
|
||||
self.directions != 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_dir(self, dir: Direction) -> bool {
|
||||
self.directions & (1 << (dir as u8)) != 0
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn add_dir(&mut self, dir: Direction) {
|
||||
self.directions |= 1 << (dir as u8)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue