I added the new Structure
Crossing
. It allows the movement of Item
s both vertically and horizontally.
The direction from where the last Item
was placed onto it then determines its horizontal or vertical movement direction.
pub struct Crossing {
left: Option<Material>,
right: Option<Material>,
top: Option<Material>,
bottom: Option<Material>,
horizontally: Horizontally,
vertically: Vertically,
...
}
pub enum Horizontally {
Right,
Left,
}
pub enum Vertically {
Up,
Down,
}
The Crossing
needs to know from which direction Item
s it accepts are coming from, to decide on one of the four possible slots and movement directions.
I therefore had to extend some of the ItemHandler
‘s functions from:
pub trait ItemHandler {
fn accepts(
&self,
pos: &PosRelative,
x: &Item,
...
) -> bool;
fn accept(
&mut self,
pos: &PosRelative,
x: Item,
...
);
...
to
pub trait ItemHandler {
fn accepts(
&self,
pos_self: &PosRelative,
pos_other: &PosRelative,
x: &Item,
...
) -> bool;
fn accept(
&mut self,
pos_self: &PosRelative,
pos_other: &PosRelative,
x: Item,
...
);
...