cleanup
This commit is contained in:
parent
ba1f404250
commit
4427b4c2fc
5 changed files with 36 additions and 38 deletions
|
@ -196,8 +196,8 @@ impl Editor {
|
|||
let action = &self.undo_history[self.undo_index];
|
||||
match action {
|
||||
Action::SetArea(deltas, pos, old, _new) => {
|
||||
self.source_board.paste_board(*pos, &old);
|
||||
self.source_board.shrink(&deltas);
|
||||
self.source_board.paste_board(*pos, old);
|
||||
self.source_board.shrink(deltas);
|
||||
self.shift_world(-(deltas.x_neg as f32), -(deltas.y_neg as f32));
|
||||
}
|
||||
}
|
||||
|
@ -356,7 +356,7 @@ impl Editor {
|
|||
let id = get_free_id(&self.blueprints, Blueprint::id);
|
||||
let mut blueprint = Blueprint::new(&board, id);
|
||||
if !self.new_blueprint_name.is_empty() {
|
||||
blueprint.name = self.new_blueprint_name.clone();
|
||||
blueprint.name.clone_from(&self.new_blueprint_name);
|
||||
}
|
||||
blueprint.save();
|
||||
self.blueprints.push(blueprint);
|
||||
|
@ -944,7 +944,7 @@ impl Editor {
|
|||
{
|
||||
format!("{:?}", expected_byte as char)
|
||||
} else {
|
||||
format!("{}", expected_byte)
|
||||
format!("{expected_byte}")
|
||||
};
|
||||
d.draw_text(&top_text, x + 2, y + 5, 20, Color::WHITE);
|
||||
}
|
||||
|
@ -954,7 +954,7 @@ impl Editor {
|
|||
{
|
||||
format!("{:?}", real_byte as char)
|
||||
} else {
|
||||
format!("{}", real_byte)
|
||||
format!("{real_byte}")
|
||||
};
|
||||
d.draw_text(&bottom_text, x + 2, y + 40, 20, Color::WHITE);
|
||||
}
|
||||
|
@ -1057,11 +1057,10 @@ impl Editor {
|
|||
if d.is_mouse_button_pressed(MouseButton::MOUSE_BUTTON_LEFT) {
|
||||
let pos = tile_pos.into();
|
||||
match self.active_tool {
|
||||
Tool::None => (),
|
||||
Tool::Erase => (),
|
||||
Tool::None | Tool::Erase | Tool::SelectArea(_) => (),
|
||||
Tool::SetTile(tile) => self.set_tile(pos, tile),
|
||||
Tool::Math => {
|
||||
self.set_tile(pos, Tile::Powerable(PTile::Math(self.tool_math), false))
|
||||
self.set_tile(pos, Tile::Powerable(PTile::Math(self.tool_math), false));
|
||||
}
|
||||
Tool::Comparator => self.set_tile(
|
||||
pos,
|
||||
|
@ -1086,13 +1085,12 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
}
|
||||
Tool::SelectArea(_) => (),
|
||||
}
|
||||
}
|
||||
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT)
|
||||
&& self.active_tool == Tool::Erase
|
||||
{
|
||||
self.set_tile(tile_pos.into(), Tile::BLANK)
|
||||
self.set_tile(tile_pos.into(), Tile::BLANK);
|
||||
}
|
||||
if let Tool::SelectArea(selection) = &mut self.active_tool {
|
||||
if d.is_mouse_button_down(MouseButton::MOUSE_BUTTON_LEFT) {
|
||||
|
|
|
@ -302,7 +302,7 @@ fn get_solutions() -> HashMap<String, Vec<Solution>> {
|
|||
.as_deref()
|
||||
.and_then(|s| serde_json::from_str(s).ok());
|
||||
if let Some(solution) = s {
|
||||
solutions.push(solution)
|
||||
solutions.push(solution);
|
||||
}
|
||||
}
|
||||
solutions.sort_unstable_by_key(Solution::id);
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -278,7 +278,7 @@ pub fn slider(
|
|||
let percent = (mouse_pos.x - bounds.x) / bounds.width;
|
||||
let new_value = min + (percent * (max - min + 1) as f32) as u8;
|
||||
if *value != new_value {
|
||||
*value = new_value
|
||||
*value = new_value;
|
||||
}
|
||||
} else if d.get_mouse_wheel_move() > 0.5 && *value < max {
|
||||
*value += 1;
|
||||
|
|
Loading…
Reference in a new issue