|
|
|
@ -43,6 +43,7 @@ impl Plugin for BlocksPlugin {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
propogate_orientation.run_if(any_component_changed::<Orientation>),
|
|
|
|
propogate_orientation.run_if(any_component_changed::<Orientation>),
|
|
|
|
propogate_grid_position.run_if(any_component_changed::<GridPosition>),
|
|
|
|
propogate_grid_position.run_if(any_component_changed::<GridPosition>),
|
|
|
|
|
|
|
|
propogate_relative_position.run_if(any_component_changed::<RelativePosition>),
|
|
|
|
handle_kb_input.run_if(on_message::<KeyboardInput>),
|
|
|
|
handle_kb_input.run_if(on_message::<KeyboardInput>),
|
|
|
|
handle_movement.run_if(on_message::<Movement>),
|
|
|
|
handle_movement.run_if(on_message::<Movement>),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -444,17 +445,28 @@ fn propogate_grid_position(
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// When a shape's orientation changes, the blocks need to move
|
|
|
|
/// When a block's relative position changes, update it's grid position
|
|
|
|
|
|
|
|
fn propogate_relative_position(
|
|
|
|
|
|
|
|
mut children: Query<(&mut GridPosition, &RelativePosition, &ShapeBlock), Changed<RelativePosition>>,
|
|
|
|
|
|
|
|
parent: Query<&GridPosition, Without<ShapeBlock>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
children.iter_mut().for_each(|(mut gp, rp, sb)| {
|
|
|
|
|
|
|
|
let parent_gp = parent.get(sb.0).unwrap();
|
|
|
|
|
|
|
|
*gp = parent_gp.clone() + *rp;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// When a shape's orientation changes, the blocks need to move so assign new relative positions
|
|
|
|
fn propogate_orientation(
|
|
|
|
fn propogate_orientation(
|
|
|
|
parent: Query<(&GridPosition, &Orientation, &ShapeLayout, &ShapeBlocks), Changed<Orientation>>,
|
|
|
|
parent: Query<(&Orientation, &ShapeLayout, &ShapeBlocks), Changed<Orientation>>,
|
|
|
|
mut children: Query<&mut GridPosition, Without<ShapeBlocks>>,
|
|
|
|
mut children: Query<&mut RelativePosition>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
parent.iter().for_each(|(parent_gp, parent_o, sl, sbs)| {
|
|
|
|
parent.iter().for_each(|(parent_o, sl, sbs)| {
|
|
|
|
let new_layout = sl.positions(*parent_o);
|
|
|
|
let new_layout = sl.positions(*parent_o);
|
|
|
|
|
|
|
|
|
|
|
|
sbs.iter().zip(new_layout).for_each(|(e, rp)| {
|
|
|
|
sbs.iter().zip(new_layout).for_each(|(e, rp)| {
|
|
|
|
let mut gp = children.get_mut(e).unwrap();
|
|
|
|
let mut this_rp = children.get_mut(e).unwrap();
|
|
|
|
*gp = parent_gp.clone() + rp;
|
|
|
|
*this_rp = rp;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|