rename gate to comparator
This commit is contained in:
parent
e98ad65ec3
commit
9792410f02
4 changed files with 49 additions and 48 deletions
|
@ -6,7 +6,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
|
||||||
## todo
|
## todo
|
||||||
- undo/redo
|
- undo/redo
|
||||||
- more levels
|
- 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
|
- cut selections, copy to system clipboard
|
||||||
- timestamps in solutions and blueprints
|
- timestamps in solutions and blueprints
|
||||||
- multiple input/output sets
|
- multiple input/output sets
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
marble_engine::{
|
marble_engine::{
|
||||||
board::Board,
|
board::Board,
|
||||||
pos::{Pos, PosInt},
|
pos::{Pos, PosInt},
|
||||||
tile::{Claim, Direction, GateType, MathOp, MirrorType, OpenTile, PTile, Tile, WireType},
|
tile::{Claim, Comparison, Direction, MathOp, MirrorType, OpenTile, PTile, Tile, WireType},
|
||||||
Machine,
|
Machine,
|
||||||
},
|
},
|
||||||
simple_button, simple_option_button, simple_toggle_button, slider,
|
simple_button, simple_option_button, simple_toggle_button, slider,
|
||||||
|
@ -49,7 +49,7 @@ pub struct Editor {
|
||||||
input_as_text: bool,
|
input_as_text: bool,
|
||||||
active_tool: Tool,
|
active_tool: Tool,
|
||||||
tool_math: MathOp,
|
tool_math: MathOp,
|
||||||
tool_gate: GateType,
|
tool_comparator: Comparison,
|
||||||
tool_arrow: Direction,
|
tool_arrow: Direction,
|
||||||
tool_mirror: MirrorType,
|
tool_mirror: MirrorType,
|
||||||
tool_wire: WireType,
|
tool_wire: WireType,
|
||||||
|
@ -87,7 +87,7 @@ enum Tool {
|
||||||
SetTile(Tile),
|
SetTile(Tile),
|
||||||
Digits(Option<Pos>),
|
Digits(Option<Pos>),
|
||||||
Math,
|
Math,
|
||||||
Gate,
|
Comparator,
|
||||||
Wire,
|
Wire,
|
||||||
Arrow,
|
Arrow,
|
||||||
Mirror,
|
Mirror,
|
||||||
|
@ -133,7 +133,7 @@ impl Editor {
|
||||||
sim_speed: 3,
|
sim_speed: 3,
|
||||||
time_since_step: 0.,
|
time_since_step: 0.,
|
||||||
tool_math: MathOp::Add,
|
tool_math: MathOp::Add,
|
||||||
tool_gate: GateType::Equal,
|
tool_comparator: Comparison::Equal,
|
||||||
tool_arrow: Direction::Right,
|
tool_arrow: Direction::Right,
|
||||||
tool_mirror: MirrorType::Forward,
|
tool_mirror: MirrorType::Forward,
|
||||||
tool_wire: WireType::Vertical,
|
tool_wire: WireType::Vertical,
|
||||||
|
@ -219,7 +219,7 @@ impl Editor {
|
||||||
if shift {
|
if shift {
|
||||||
match &self.active_tool {
|
match &self.active_tool {
|
||||||
Tool::Math => self.tool_math.prev(),
|
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::Arrow => self.tool_arrow = self.tool_arrow.left(),
|
||||||
Tool::Mirror => self.tool_mirror.flip(),
|
Tool::Mirror => self.tool_mirror.flip(),
|
||||||
Tool::Wire => self.tool_wire.prev(),
|
Tool::Wire => self.tool_wire.prev(),
|
||||||
|
@ -228,7 +228,7 @@ impl Editor {
|
||||||
} else {
|
} else {
|
||||||
match &self.active_tool {
|
match &self.active_tool {
|
||||||
Tool::Math => self.tool_math.next(),
|
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::Arrow => self.tool_arrow = self.tool_arrow.right(),
|
||||||
Tool::Mirror => self.tool_mirror.flip(),
|
Tool::Mirror => self.tool_mirror.flip(),
|
||||||
Tool::Wire => self.tool_wire.next(),
|
Tool::Wire => self.tool_wire.next(),
|
||||||
|
@ -828,11 +828,11 @@ impl Editor {
|
||||||
}
|
}
|
||||||
match tool_button(
|
match tool_button(
|
||||||
(1, 5),
|
(1, 5),
|
||||||
&Tile::Powerable(PTile::Gate(self.tool_gate), false).texture(),
|
&Tile::Powerable(PTile::Comparator(self.tool_comparator), false).texture(),
|
||||||
Tool::Gate,
|
Tool::Comparator,
|
||||||
) {
|
) {
|
||||||
Some(Scroll::Down) => self.tool_gate.next(),
|
Some(Scroll::Down) => self.tool_comparator.next(),
|
||||||
Some(Scroll::Up) => self.tool_gate.prev(),
|
Some(Scroll::Up) => self.tool_comparator.prev(),
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -972,7 +972,7 @@ impl Editor {
|
||||||
Tool::Erase => "cancel".into(),
|
Tool::Erase => "cancel".into(),
|
||||||
Tool::SetTile(t) => t.texture(),
|
Tool::SetTile(t) => t.texture(),
|
||||||
Tool::Math => format!("{}_off", self.tool_math.texture_name()),
|
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::Wire => format!("{}_off", self.tool_wire.texture_name()),
|
||||||
Tool::Arrow => self.tool_arrow.arrow_tile_texture_name().into(),
|
Tool::Arrow => self.tool_arrow.arrow_tile_texture_name().into(),
|
||||||
Tool::Mirror => self.tool_mirror.texture_name().into(),
|
Tool::Mirror => self.tool_mirror.texture_name().into(),
|
||||||
|
@ -1004,9 +1004,10 @@ impl Editor {
|
||||||
Tool::Math => {
|
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::Gate => {
|
Tool::Comparator => self.set_tile(
|
||||||
self.set_tile(pos, Tile::Powerable(PTile::Gate(self.tool_gate), false))
|
pos,
|
||||||
}
|
Tile::Powerable(PTile::Comparator(self.tool_comparator), false),
|
||||||
|
),
|
||||||
Tool::Wire => self.set_tile(pos, Tile::Wire(self.tool_wire, 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::Arrow => self.set_tile(pos, Tile::Arrow(self.tool_arrow)),
|
||||||
Tool::Mirror => self.set_tile(pos, Tile::Mirror(self.tool_mirror)),
|
Tool::Mirror => self.set_tile(pos, Tile::Mirror(self.tool_mirror)),
|
||||||
|
|
|
@ -125,7 +125,7 @@ impl Machine {
|
||||||
};
|
};
|
||||||
// `machine`` is being powered, in direction `dir``
|
// `machine`` is being powered, in direction `dir``
|
||||||
match machine {
|
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) => {
|
PTile::Math(op) => {
|
||||||
if front_tile.is_blank() {
|
if front_tile.is_blank() {
|
||||||
let pos_a = dir.left().step(pos);
|
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;
|
*state = true;
|
||||||
let gate = *gate;
|
let comp = *comp;
|
||||||
for dir in Direction::ALL {
|
for dir in Direction::ALL {
|
||||||
let front_pos = dir.step(pos);
|
let front_pos = dir.step(pos);
|
||||||
let source_pos = dir.opposite().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_a = self.board.get_or_blank(pos_a).read_value();
|
||||||
let val_b = self.board.get_or_blank(pos_b).read_value();
|
let val_b = self.board.get_or_blank(pos_b).read_value();
|
||||||
|
|
||||||
let result = match gate {
|
let result = match comp {
|
||||||
GateType::LessThan => val_a < val_b,
|
Comparison::LessThan => val_a < val_b,
|
||||||
GateType::GreaterThan => val_a > val_b,
|
Comparison::GreaterThan => val_a > val_b,
|
||||||
GateType::Equal => val_a == val_b,
|
Comparison::Equal => val_a == val_b,
|
||||||
GateType::NotEqual => val_a != val_b,
|
Comparison::NotEqual => val_a != val_b,
|
||||||
};
|
};
|
||||||
if result {
|
if result {
|
||||||
self.powered.push(front_pos);
|
self.powered.push(front_pos);
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub enum OpenTile {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum PTile {
|
pub enum PTile {
|
||||||
Gate(GateType),
|
Comparator(Comparison),
|
||||||
Math(MathOp),
|
Math(MathOp),
|
||||||
Silo,
|
Silo,
|
||||||
Flipper,
|
Flipper,
|
||||||
|
@ -54,7 +54,7 @@ pub enum MathOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum GateType {
|
pub enum Comparison {
|
||||||
LessThan,
|
LessThan,
|
||||||
GreaterThan,
|
GreaterThan,
|
||||||
Equal,
|
Equal,
|
||||||
|
@ -94,10 +94,10 @@ impl Tile {
|
||||||
'v' => Tile::Arrow(Direction::Down),
|
'v' => Tile::Arrow(Direction::Down),
|
||||||
'<' => Tile::Arrow(Direction::Left),
|
'<' => Tile::Arrow(Direction::Left),
|
||||||
'>' => Tile::Arrow(Direction::Right),
|
'>' => Tile::Arrow(Direction::Right),
|
||||||
'=' => Tile::Powerable(PTile::Gate(GateType::Equal), false),
|
'=' => Tile::Powerable(PTile::Comparator(Comparison::Equal), false),
|
||||||
'!' => Tile::Powerable(PTile::Gate(GateType::NotEqual), false),
|
'!' => Tile::Powerable(PTile::Comparator(Comparison::NotEqual), false),
|
||||||
'L' => Tile::Powerable(PTile::Gate(GateType::LessThan), false),
|
'L' => Tile::Powerable(PTile::Comparator(Comparison::LessThan), false),
|
||||||
'G' => Tile::Powerable(PTile::Gate(GateType::GreaterThan), false),
|
'G' => Tile::Powerable(PTile::Comparator(Comparison::GreaterThan), false),
|
||||||
'I' | 'P' => Tile::Powerable(PTile::IO, false),
|
'I' | 'P' => Tile::Powerable(PTile::IO, false),
|
||||||
'F' => Tile::Powerable(PTile::Flipper, false),
|
'F' => Tile::Powerable(PTile::Flipper, false),
|
||||||
'A' => Tile::Powerable(PTile::Math(MathOp::Add), false),
|
'A' => Tile::Powerable(PTile::Math(MathOp::Add), false),
|
||||||
|
@ -135,11 +135,11 @@ impl Tile {
|
||||||
WireType::Cross => '+',
|
WireType::Cross => '+',
|
||||||
},
|
},
|
||||||
Tile::Powerable(tile, _) => match tile {
|
Tile::Powerable(tile, _) => match tile {
|
||||||
PTile::Gate(gate) => match gate {
|
PTile::Comparator(comp) => match comp {
|
||||||
GateType::LessThan => 'L',
|
Comparison::LessThan => 'L',
|
||||||
GateType::GreaterThan => 'G',
|
Comparison::GreaterThan => 'G',
|
||||||
GateType::Equal => '=',
|
Comparison::Equal => '=',
|
||||||
GateType::NotEqual => '!',
|
Comparison::NotEqual => '!',
|
||||||
},
|
},
|
||||||
PTile::Math(math) => match math {
|
PTile::Math(math) => match math {
|
||||||
MathOp::Add => 'A',
|
MathOp::Add => 'A',
|
||||||
|
@ -191,7 +191,7 @@ impl Tile {
|
||||||
}
|
}
|
||||||
Tile::Powerable(tile, state) => {
|
Tile::Powerable(tile, state) => {
|
||||||
let root = match tile {
|
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::Math(math_op) => math_op.texture_name(),
|
||||||
PTile::Silo => "silo",
|
PTile::Silo => "silo",
|
||||||
PTile::Flipper => "flipper",
|
PTile::Flipper => "flipper",
|
||||||
|
@ -370,31 +370,31 @@ impl MathOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GateType {
|
impl Comparison {
|
||||||
pub const fn texture_name(&self) -> &'static str {
|
pub const fn texture_name(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
GateType::LessThan => "lt",
|
Comparison::LessThan => "lt",
|
||||||
GateType::GreaterThan => "gt",
|
Comparison::GreaterThan => "gt",
|
||||||
GateType::Equal => "eq",
|
Comparison::Equal => "eq",
|
||||||
GateType::NotEqual => "neq",
|
Comparison::NotEqual => "neq",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn next(&mut self) {
|
pub fn next(&mut self) {
|
||||||
*self = match self {
|
*self = match self {
|
||||||
GateType::LessThan => GateType::GreaterThan,
|
Comparison::LessThan => Comparison::GreaterThan,
|
||||||
GateType::GreaterThan => GateType::Equal,
|
Comparison::GreaterThan => Comparison::Equal,
|
||||||
GateType::Equal => GateType::NotEqual,
|
Comparison::Equal => Comparison::NotEqual,
|
||||||
GateType::NotEqual => GateType::LessThan,
|
Comparison::NotEqual => Comparison::LessThan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prev(&mut self) {
|
pub fn prev(&mut self) {
|
||||||
*self = match self {
|
*self = match self {
|
||||||
GateType::LessThan => GateType::NotEqual,
|
Comparison::LessThan => Comparison::NotEqual,
|
||||||
GateType::GreaterThan => GateType::LessThan,
|
Comparison::GreaterThan => Comparison::LessThan,
|
||||||
GateType::Equal => GateType::GreaterThan,
|
Comparison::Equal => Comparison::GreaterThan,
|
||||||
GateType::NotEqual => GateType::Equal,
|
Comparison::NotEqual => Comparison::Equal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue