merge input and output tiles into one, where output is accomplished by marbles moving into the tile, like a bag

This commit is contained in:
Crispy 2024-10-08 22:04:12 +02:00
parent ae4e84bb90
commit 9f21c2b258
10 changed files with 11 additions and 19 deletions

View file

@ -8,7 +8,6 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
story/lore
blueprints
scroll level list
should the output tile consume marbles like the bag instead of needing power? then input and output could be merged to one tile type
make marble movement more consistent (`>o o<` depends on internal marble order)
decide on marble data size (u32 or byte?)
blueprint rotation

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

BIN
assets/tiles/io_tile_on.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 B

View file

@ -577,8 +577,7 @@ impl Editor {
tool_button((0, 0), "block", Tool::SetTile(Tile::from_char('#')));
tool_button((0, 1), "bag_off", Tool::SetTile(Tile::from_char('B')));
tool_button((0, 2), "trigger_off", Tool::SetTile(Tile::from_char('*')));
tool_button((0, 3), "input_off", Tool::SetTile(Tile::from_char('I')));
tool_button((0, 4), "output_off", Tool::SetTile(Tile::from_char('P')));
tool_button((0, 3), "io_tile_off", Tool::SetTile(Tile::from_char('I')));
tool_button((0, 5), "flipper_off", Tool::SetTile(Tile::from_char('F')));
tool_button((1, 0), "marble", Tool::SetTile(Tile::from_char('o')));

View file

@ -128,7 +128,7 @@ impl Machine {
.iter()
.map(|&pos| {
let marble = self.board.get(pos).unwrap();
let Tile::Marble { value: _, dir } = marble else {
let Tile::Marble { value, dir } = marble else {
panic!("broken marble");
};
let front_pos = dir.step(pos);
@ -139,6 +139,10 @@ impl Machine {
if let Tile::Powerable(PTile::Bag, _) = front_tile {
return Event::Remove;
}
if let Tile::Powerable(PTile::IO, _) = front_tile{
self.output.push(value as u8);
return Event::Remove;
}
let can_move_to = |tile| matches!(tile, Some(Tile::Blank | Tile::Digit(_)));
@ -307,19 +311,13 @@ impl Machine {
self.propagate_power(*d, d.step(pos));
}
}
PTile::Output => {
let sample = self.board.get_or_blank(front_pos);
if let Tile::Marble { value, dir: _ } = sample {
self.output.push(value as u8);
}
}
PTile::Bag => {
if let Some(front) = self.board.get_blank_mut(front_pos) {
*front = Tile::Marble { value: 0, dir };
self.marbles.push(front_pos);
}
}
PTile::Input => {
PTile::IO => {
if let Some(front) = self.board.get_blank_mut(front_pos) {
if self.input_index < self.input.len() {
let value = self.input[self.input_index] as MarbleValue;

View file

@ -25,8 +25,7 @@ pub enum PTile {
Math(MathOp),
Bag,
Flipper,
Input,
Output,
IO,
}
#[derive(Debug, Clone, Copy, PartialEq)]
@ -88,8 +87,7 @@ impl Tile {
'!' => Tile::Powerable(PTile::Gate(GateType::NotEqual), false),
'L' => Tile::Powerable(PTile::Gate(GateType::LessThan), false),
'G' => Tile::Powerable(PTile::Gate(GateType::GreaterThan), false),
'P' => Tile::Powerable(PTile::Output, false),
'I' => Tile::Powerable(PTile::Input, false),
'I' | 'P' => Tile::Powerable(PTile::IO, false),
'F' => Tile::Powerable(PTile::Flipper, false),
'A' => Tile::Powerable(PTile::Math(MathOp::Add), false),
'S' => Tile::Powerable(PTile::Math(MathOp::Sub), false),
@ -142,8 +140,7 @@ impl Tile {
},
PTile::Bag => 'B',
PTile::Flipper => 'F',
PTile::Input => 'I',
PTile::Output => 'P',
PTile::IO => 'I',
},
}
}
@ -176,8 +173,7 @@ impl Tile {
PTile::Math(math_op) => math_op.texture_name(),
PTile::Bag => "bag",
PTile::Flipper => "flipper",
PTile::Input => "input",
PTile::Output => "output",
PTile::IO => "io_tile",
};
return format!("{root}_{}", if *state { "on" } else { "off" });
}