stop cloning strings for every tile texture name lookup, general clippy fixes
This commit is contained in:
parent
499aad7898
commit
6d8bfa03b0
3 changed files with 108 additions and 67 deletions
|
@ -263,7 +263,7 @@ impl Board {
|
|||
if texname.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let texture = textures.get(&texname);
|
||||
let texture = textures.get(texname);
|
||||
draw_scaled_texture(d, texture, px, py, scale);
|
||||
} else {
|
||||
d.draw_rectangle(px, py, tile_size, tile_size, Color::new(0, 0, 0, 80));
|
||||
|
|
|
@ -167,40 +167,57 @@ impl Tile {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn texture(&self) -> String {
|
||||
pub fn texture(&self) -> &str {
|
||||
match self {
|
||||
Tile::Open(OpenTile::Blank, _) => "",
|
||||
Tile::Block => "block",
|
||||
Tile::Marble { value: _, dir: _ } => "marble",
|
||||
Tile::Open(OpenTile::Digit(n), _) => return format!("tile_digit_{n}"),
|
||||
Tile::Open(OpenTile::Digit(n), _) => match n {
|
||||
0 => "tile_digit_0",
|
||||
1 => "tile_digit_1",
|
||||
2 => "tile_digit_2",
|
||||
3 => "tile_digit_3",
|
||||
4 => "tile_digit_4",
|
||||
5 => "tile_digit_5",
|
||||
6 => "tile_digit_6",
|
||||
7 => "tile_digit_7",
|
||||
8 => "tile_digit_8",
|
||||
9 => "tile_digit_9",
|
||||
_ => unreachable!(),
|
||||
},
|
||||
Tile::Mirror(mirror) => mirror.texture_name(),
|
||||
Tile::Arrow(dir) => dir.arrow_tile_texture_name(),
|
||||
Tile::Button(state) => {
|
||||
if *state {
|
||||
"button_on"
|
||||
} else {
|
||||
"button_off"
|
||||
return "button_on";
|
||||
}
|
||||
"button_off"
|
||||
}
|
||||
Tile::Wire(wire, state) => {
|
||||
return format!(
|
||||
"{}_{}",
|
||||
wire.texture_name(),
|
||||
if *state { "on" } else { "off" }
|
||||
)
|
||||
if *state {
|
||||
return wire.texture_name_on();
|
||||
}
|
||||
wire.texture_name_off()
|
||||
}
|
||||
Tile::Powerable(tile, state) => {
|
||||
let root = match tile {
|
||||
PTile::Comparator(comp) => comp.texture_name(),
|
||||
PTile::Math(math_op) => math_op.texture_name(),
|
||||
PTile::Silo => "silo",
|
||||
PTile::Flipper => "flipper",
|
||||
PTile::IO => "io_tile",
|
||||
if *state {
|
||||
return match tile {
|
||||
PTile::Comparator(comp) => comp.texture_name_on(),
|
||||
PTile::Math(math_op) => math_op.texture_name_on(),
|
||||
PTile::Silo => "silo_on",
|
||||
PTile::Flipper => "flipper_on",
|
||||
PTile::IO => "io_tile_on",
|
||||
};
|
||||
}
|
||||
return 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",
|
||||
};
|
||||
return format!("{root}_{}", if *state { "on" } else { "off" });
|
||||
}
|
||||
}
|
||||
.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -296,11 +313,18 @@ impl WireType {
|
|||
}
|
||||
}
|
||||
|
||||
pub const fn texture_name(&self) -> &'static str {
|
||||
pub const fn texture_name_on(&self) -> &'static str {
|
||||
match self {
|
||||
WireType::Vertical => "wire_vertical",
|
||||
WireType::Horizontal => "wire_horizontal",
|
||||
WireType::Cross => "wire_cross",
|
||||
WireType::Vertical => "wire_vertical_on",
|
||||
WireType::Horizontal => "wire_horizontal_on",
|
||||
WireType::Cross => "wire_cross_on",
|
||||
}
|
||||
}
|
||||
pub const fn texture_name_off(&self) -> &'static str {
|
||||
match self {
|
||||
WireType::Vertical => "wire_vertical_off",
|
||||
WireType::Horizontal => "wire_horizontal_off",
|
||||
WireType::Cross => "wire_cross_off",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -339,13 +363,22 @@ impl MirrorType {
|
|||
}
|
||||
|
||||
impl MathOp {
|
||||
pub const fn texture_name(&self) -> &'static str {
|
||||
pub const fn texture_name_on(&self) -> &'static str {
|
||||
match self {
|
||||
MathOp::Add => "add",
|
||||
MathOp::Sub => "sub",
|
||||
MathOp::Mul => "mul",
|
||||
MathOp::Div => "div",
|
||||
MathOp::Rem => "rem",
|
||||
MathOp::Add => "add_on",
|
||||
MathOp::Sub => "sub_on",
|
||||
MathOp::Mul => "mul_on",
|
||||
MathOp::Div => "div_on",
|
||||
MathOp::Rem => "rem_on",
|
||||
}
|
||||
}
|
||||
pub const fn texture_name_off(&self) -> &'static str {
|
||||
match self {
|
||||
MathOp::Add => "add_off",
|
||||
MathOp::Sub => "sub_off",
|
||||
MathOp::Mul => "mul_off",
|
||||
MathOp::Div => "div_off",
|
||||
MathOp::Rem => "rem_off",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,12 +404,20 @@ impl MathOp {
|
|||
}
|
||||
|
||||
impl Comparison {
|
||||
pub const fn texture_name(&self) -> &'static str {
|
||||
pub const fn texture_name_on(&self) -> &'static str {
|
||||
match self {
|
||||
Comparison::LessThan => "lt",
|
||||
Comparison::GreaterThan => "gt",
|
||||
Comparison::Equal => "eq",
|
||||
Comparison::NotEqual => "neq",
|
||||
Comparison::LessThan => "lt_on",
|
||||
Comparison::GreaterThan => "gt_on",
|
||||
Comparison::Equal => "eq_on",
|
||||
Comparison::NotEqual => "neq_on",
|
||||
}
|
||||
}
|
||||
pub const fn texture_name_off(&self) -> &'static str {
|
||||
match self {
|
||||
Comparison::LessThan => "lt_off",
|
||||
Comparison::GreaterThan => "gt_off",
|
||||
Comparison::Equal => "eq_off",
|
||||
Comparison::NotEqual => "neq_off",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue