cleanup
This commit is contained in:
parent
ba1f404250
commit
4427b4c2fc
5 changed files with 36 additions and 38 deletions
|
@ -45,7 +45,7 @@ impl Board {
|
|||
let mut out = String::new();
|
||||
for row in &self.rows {
|
||||
for tile in row {
|
||||
out.push(tile.to_char())
|
||||
out.push(tile.to_char());
|
||||
}
|
||||
out.push('\n');
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ impl Board {
|
|||
// top
|
||||
{
|
||||
let mut n = 0;
|
||||
while n < self.height && self.rows[n].iter().all(Tile::is_blank) {
|
||||
while n < self.height && self.rows[n].iter().all(|t| t.is_blank()) {
|
||||
n += 1;
|
||||
}
|
||||
let trim_top = n.saturating_sub(margin);
|
||||
|
@ -166,7 +166,7 @@ impl Board {
|
|||
// bottom
|
||||
{
|
||||
let mut n = 0;
|
||||
while n < self.height && self.rows[self.height - n - 1].iter().all(Tile::is_blank) {
|
||||
while n < self.height && self.rows[self.height - n - 1].iter().all(|t| t.is_blank()) {
|
||||
n += 1;
|
||||
}
|
||||
let trim_bottom = n.saturating_sub(margin);
|
||||
|
|
|
@ -155,19 +155,19 @@ impl Tile {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_blank(&self) -> bool {
|
||||
pub fn is_blank(self) -> bool {
|
||||
matches!(self, Tile::Open(OpenTile::Blank, _))
|
||||
}
|
||||
|
||||
pub fn read_value(&self) -> MarbleValue {
|
||||
pub fn read_value(self) -> MarbleValue {
|
||||
match self {
|
||||
Tile::Marble { value, dir: _ } => *value,
|
||||
Tile::Open(OpenTile::Digit(d), _) => *d as MarbleValue,
|
||||
Tile::Marble { value, dir: _ } => value,
|
||||
Tile::Open(OpenTile::Digit(d), _) => d as MarbleValue,
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn texture(&self) -> &str {
|
||||
pub fn texture(self) -> &'static str {
|
||||
match self {
|
||||
Tile::Open(OpenTile::Blank, _) => "",
|
||||
Tile::Block => "block",
|
||||
|
@ -188,19 +188,19 @@ impl Tile {
|
|||
Tile::Mirror(mirror) => mirror.texture_name(),
|
||||
Tile::Arrow(dir) => dir.arrow_tile_texture_name(),
|
||||
Tile::Button(state) => {
|
||||
if *state {
|
||||
if state {
|
||||
return "button_on";
|
||||
}
|
||||
"button_off"
|
||||
}
|
||||
Tile::Wire(wire, state) => {
|
||||
if *state {
|
||||
if state {
|
||||
return wire.texture_name_on();
|
||||
}
|
||||
wire.texture_name_off()
|
||||
}
|
||||
Tile::Powerable(tile, state) => {
|
||||
if *state {
|
||||
if state {
|
||||
return match tile {
|
||||
PTile::Comparator(comp) => comp.texture_name_on(),
|
||||
PTile::Math(math_op) => math_op.texture_name_on(),
|
||||
|
@ -209,13 +209,13 @@ impl Tile {
|
|||
PTile::IO => "io_tile_on",
|
||||
};
|
||||
}
|
||||
return match tile {
|
||||
match tile {
|
||||
PTile::Comparator(comp) => comp.texture_name_off(),
|
||||
PTile::Math(math_op) => math_op.texture_name_off(),
|
||||
PTile::Silo => "silo_off",
|
||||
PTile::Flipper => "flipper_off",
|
||||
PTile::IO => "io_tile_off",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ impl Direction {
|
|||
Direction::Right,
|
||||
];
|
||||
|
||||
pub fn opposite(&self) -> Direction {
|
||||
pub fn opposite(self) -> Direction {
|
||||
match self {
|
||||
Direction::Up => Direction::Down,
|
||||
Direction::Down => Direction::Up,
|
||||
|
@ -238,7 +238,7 @@ impl Direction {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn right(&self) -> Direction {
|
||||
pub fn right(self) -> Direction {
|
||||
match self {
|
||||
Direction::Up => Direction::Right,
|
||||
Direction::Down => Direction::Left,
|
||||
|
@ -247,11 +247,11 @@ impl Direction {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn left(&self) -> Direction {
|
||||
pub fn left(self) -> Direction {
|
||||
self.right().opposite()
|
||||
}
|
||||
|
||||
pub fn step(&self, mut pos: Pos) -> Pos {
|
||||
pub fn step(self, mut pos: Pos) -> Pos {
|
||||
match self {
|
||||
Direction::Up => pos.y -= 1,
|
||||
Direction::Down => pos.y += 1,
|
||||
|
@ -261,7 +261,7 @@ impl Direction {
|
|||
pos
|
||||
}
|
||||
|
||||
pub const fn arrow_tile_texture_name(&self) -> &'static str {
|
||||
pub const fn arrow_tile_texture_name(self) -> &'static str {
|
||||
match self {
|
||||
Direction::Up => "arrow_up",
|
||||
Direction::Down => "arrow_down",
|
||||
|
@ -270,7 +270,7 @@ impl Direction {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn arrow_texture_name(&self) -> &'static str {
|
||||
pub const fn arrow_texture_name(self) -> &'static str {
|
||||
match self {
|
||||
Direction::Up => "direction_up",
|
||||
Direction::Down => "direction_down",
|
||||
|
@ -313,14 +313,14 @@ impl WireType {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn texture_name_on(&self) -> &'static str {
|
||||
pub const fn texture_name_on(self) -> &'static str {
|
||||
match self {
|
||||
WireType::Vertical => "wire_vertical_on",
|
||||
WireType::Horizontal => "wire_horizontal_on",
|
||||
WireType::Cross => "wire_cross_on",
|
||||
}
|
||||
}
|
||||
pub const fn texture_name_off(&self) -> &'static str {
|
||||
pub const fn texture_name_off(self) -> &'static str {
|
||||
match self {
|
||||
WireType::Vertical => "wire_vertical_off",
|
||||
WireType::Horizontal => "wire_horizontal_off",
|
||||
|
@ -354,7 +354,7 @@ impl MirrorType {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn texture_name(&self) -> &'static str {
|
||||
pub const fn texture_name(self) -> &'static str {
|
||||
match self {
|
||||
MirrorType::Forward => "mirror_forward",
|
||||
MirrorType::Back => "mirror_back",
|
||||
|
@ -363,7 +363,7 @@ impl MirrorType {
|
|||
}
|
||||
|
||||
impl MathOp {
|
||||
pub const fn texture_name_on(&self) -> &'static str {
|
||||
pub const fn texture_name_on(self) -> &'static str {
|
||||
match self {
|
||||
MathOp::Add => "add_on",
|
||||
MathOp::Sub => "sub_on",
|
||||
|
@ -372,7 +372,7 @@ impl MathOp {
|
|||
MathOp::Rem => "rem_on",
|
||||
}
|
||||
}
|
||||
pub const fn texture_name_off(&self) -> &'static str {
|
||||
pub const fn texture_name_off(self) -> &'static str {
|
||||
match self {
|
||||
MathOp::Add => "add_off",
|
||||
MathOp::Sub => "sub_off",
|
||||
|
@ -404,7 +404,7 @@ impl MathOp {
|
|||
}
|
||||
|
||||
impl Comparison {
|
||||
pub const fn texture_name_on(&self) -> &'static str {
|
||||
pub const fn texture_name_on(self) -> &'static str {
|
||||
match self {
|
||||
Comparison::LessThan => "lt_on",
|
||||
Comparison::GreaterThan => "gt_on",
|
||||
|
@ -412,7 +412,7 @@ impl Comparison {
|
|||
Comparison::NotEqual => "neq_on",
|
||||
}
|
||||
}
|
||||
pub const fn texture_name_off(&self) -> &'static str {
|
||||
pub const fn texture_name_off(self) -> &'static str {
|
||||
match self {
|
||||
Comparison::LessThan => "lt_off",
|
||||
Comparison::GreaterThan => "gt_off",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue