diff --git a/README.md b/README.md index 366d445..d60eeba 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble ## todo - undo/redo - more levels -- make direct power (gate -> machine) work, (needs storing power direction in machine tiles) +- make direct power (comparator -> machine) work, (needs storing power direction in machine tiles) - cut selections, copy to system clipboard - timestamps in solutions and blueprints - multiple input/output sets diff --git a/src/editor.rs b/src/editor.rs index dd8d9cc..e1877b3 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -14,7 +14,7 @@ use crate::{ marble_engine::{ board::Board, pos::{Pos, PosInt}, - tile::{Claim, Direction, GateType, MathOp, MirrorType, OpenTile, PTile, Tile, WireType}, + tile::{Claim, Comparison, Direction, MathOp, MirrorType, OpenTile, PTile, Tile, WireType}, Machine, }, simple_button, simple_option_button, simple_toggle_button, slider, @@ -49,7 +49,7 @@ pub struct Editor { input_as_text: bool, active_tool: Tool, tool_math: MathOp, - tool_gate: GateType, + tool_comparator: Comparison, tool_arrow: Direction, tool_mirror: MirrorType, tool_wire: WireType, @@ -87,7 +87,7 @@ enum Tool { SetTile(Tile), Digits(Option), Math, - Gate, + Comparator, Wire, Arrow, Mirror, @@ -133,7 +133,7 @@ impl Editor { sim_speed: 3, time_since_step: 0., tool_math: MathOp::Add, - tool_gate: GateType::Equal, + tool_comparator: Comparison::Equal, tool_arrow: Direction::Right, tool_mirror: MirrorType::Forward, tool_wire: WireType::Vertical, @@ -219,7 +219,7 @@ impl Editor { if shift { match &self.active_tool { Tool::Math => self.tool_math.prev(), - Tool::Gate => self.tool_gate.prev(), + Tool::Comparator => self.tool_comparator.prev(), Tool::Arrow => self.tool_arrow = self.tool_arrow.left(), Tool::Mirror => self.tool_mirror.flip(), Tool::Wire => self.tool_wire.prev(), @@ -228,7 +228,7 @@ impl Editor { } else { match &self.active_tool { Tool::Math => self.tool_math.next(), - Tool::Gate => self.tool_gate.next(), + Tool::Comparator => self.tool_comparator.next(), Tool::Arrow => self.tool_arrow = self.tool_arrow.right(), Tool::Mirror => self.tool_mirror.flip(), Tool::Wire => self.tool_wire.next(), @@ -828,11 +828,11 @@ impl Editor { } match tool_button( (1, 5), - &Tile::Powerable(PTile::Gate(self.tool_gate), false).texture(), - Tool::Gate, + &Tile::Powerable(PTile::Comparator(self.tool_comparator), false).texture(), + Tool::Comparator, ) { - Some(Scroll::Down) => self.tool_gate.next(), - Some(Scroll::Up) => self.tool_gate.prev(), + Some(Scroll::Down) => self.tool_comparator.next(), + Some(Scroll::Up) => self.tool_comparator.prev(), None => (), } } @@ -972,7 +972,7 @@ impl Editor { Tool::Erase => "cancel".into(), Tool::SetTile(t) => t.texture(), Tool::Math => format!("{}_off", self.tool_math.texture_name()), - Tool::Gate => format!("{}_off", self.tool_gate.texture_name()), + Tool::Comparator => format!("{}_off", self.tool_comparator.texture_name()), Tool::Wire => format!("{}_off", self.tool_wire.texture_name()), Tool::Arrow => self.tool_arrow.arrow_tile_texture_name().into(), Tool::Mirror => self.tool_mirror.texture_name().into(), @@ -1004,9 +1004,10 @@ impl Editor { Tool::Math => { self.set_tile(pos, Tile::Powerable(PTile::Math(self.tool_math), false)) } - Tool::Gate => { - self.set_tile(pos, Tile::Powerable(PTile::Gate(self.tool_gate), false)) - } + Tool::Comparator => self.set_tile( + pos, + Tile::Powerable(PTile::Comparator(self.tool_comparator), false), + ), Tool::Wire => self.set_tile(pos, Tile::Wire(self.tool_wire, false)), Tool::Arrow => self.set_tile(pos, Tile::Arrow(self.tool_arrow)), Tool::Mirror => self.set_tile(pos, Tile::Mirror(self.tool_mirror)), diff --git a/src/marble_engine.rs b/src/marble_engine.rs index c682a91..f99ddd2 100644 --- a/src/marble_engine.rs +++ b/src/marble_engine.rs @@ -125,7 +125,7 @@ impl Machine { }; // `machine`` is being powered, in direction `dir`` match machine { - PTile::Gate(_) => (), // handled at the power propagation stage (end of step) + PTile::Comparator(_) => (), // handled at the power propagation stage (end of step) PTile::Math(op) => { if front_tile.is_blank() { let pos_a = dir.left().step(pos); @@ -458,9 +458,9 @@ impl Machine { } } } - Tile::Powerable(PTile::Gate(gate), state) => { + Tile::Powerable(PTile::Comparator(comp), state) => { *state = true; - let gate = *gate; + let comp = *comp; for dir in Direction::ALL { let front_pos = dir.step(pos); let source_pos = dir.opposite().step(pos); @@ -482,11 +482,11 @@ impl Machine { let val_a = self.board.get_or_blank(pos_a).read_value(); let val_b = self.board.get_or_blank(pos_b).read_value(); - let result = match gate { - GateType::LessThan => val_a < val_b, - GateType::GreaterThan => val_a > val_b, - GateType::Equal => val_a == val_b, - GateType::NotEqual => val_a != val_b, + let result = match comp { + Comparison::LessThan => val_a < val_b, + Comparison::GreaterThan => val_a > val_b, + Comparison::Equal => val_a == val_b, + Comparison::NotEqual => val_a != val_b, }; if result { self.powered.push(front_pos); diff --git a/src/marble_engine/tile.rs b/src/marble_engine/tile.rs index 03e98ed..cc41320 100644 --- a/src/marble_engine/tile.rs +++ b/src/marble_engine/tile.rs @@ -31,7 +31,7 @@ pub enum OpenTile { #[derive(Debug, Clone, Copy, PartialEq)] pub enum PTile { - Gate(GateType), + Comparator(Comparison), Math(MathOp), Silo, Flipper, @@ -54,7 +54,7 @@ pub enum MathOp { } #[derive(Debug, Clone, Copy, PartialEq)] -pub enum GateType { +pub enum Comparison { LessThan, GreaterThan, Equal, @@ -94,10 +94,10 @@ impl Tile { 'v' => Tile::Arrow(Direction::Down), '<' => Tile::Arrow(Direction::Left), '>' => Tile::Arrow(Direction::Right), - '=' => Tile::Powerable(PTile::Gate(GateType::Equal), false), - '!' => Tile::Powerable(PTile::Gate(GateType::NotEqual), false), - 'L' => Tile::Powerable(PTile::Gate(GateType::LessThan), false), - 'G' => Tile::Powerable(PTile::Gate(GateType::GreaterThan), false), + '=' => 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), @@ -135,11 +135,11 @@ impl Tile { WireType::Cross => '+', }, Tile::Powerable(tile, _) => match tile { - PTile::Gate(gate) => match gate { - GateType::LessThan => 'L', - GateType::GreaterThan => 'G', - GateType::Equal => '=', - GateType::NotEqual => '!', + PTile::Comparator(comp) => match comp { + Comparison::LessThan => 'L', + Comparison::GreaterThan => 'G', + Comparison::Equal => '=', + Comparison::NotEqual => '!', }, PTile::Math(math) => match math { MathOp::Add => 'A', @@ -191,7 +191,7 @@ impl Tile { } Tile::Powerable(tile, state) => { let root = match tile { - PTile::Gate(gate) => gate.texture_name(), + PTile::Comparator(comp) => comp.texture_name(), PTile::Math(math_op) => math_op.texture_name(), PTile::Silo => "silo", PTile::Flipper => "flipper", @@ -370,31 +370,31 @@ impl MathOp { } } -impl GateType { +impl Comparison { pub const fn texture_name(&self) -> &'static str { match self { - GateType::LessThan => "lt", - GateType::GreaterThan => "gt", - GateType::Equal => "eq", - GateType::NotEqual => "neq", + Comparison::LessThan => "lt", + Comparison::GreaterThan => "gt", + Comparison::Equal => "eq", + Comparison::NotEqual => "neq", } } pub fn next(&mut self) { *self = match self { - GateType::LessThan => GateType::GreaterThan, - GateType::GreaterThan => GateType::Equal, - GateType::Equal => GateType::NotEqual, - GateType::NotEqual => GateType::LessThan, + Comparison::LessThan => Comparison::GreaterThan, + Comparison::GreaterThan => Comparison::Equal, + Comparison::Equal => Comparison::NotEqual, + Comparison::NotEqual => Comparison::LessThan, } } pub fn prev(&mut self) { *self = match self { - GateType::LessThan => GateType::NotEqual, - GateType::GreaterThan => GateType::LessThan, - GateType::Equal => GateType::GreaterThan, - GateType::NotEqual => GateType::Equal, + Comparison::LessThan => Comparison::NotEqual, + Comparison::GreaterThan => Comparison::LessThan, + Comparison::Equal => Comparison::GreaterThan, + Comparison::NotEqual => Comparison::Equal, } } }