Assert when two entities should not share the same grid position but do

main
Elijah Voigt 2 months ago
parent a310bddce0
commit 2a5d7363fe

@ -77,6 +77,7 @@ fn main() {
adjust_block_lines
.run_if(any_component_changed::<Line>)
.after(clear_line),
assert_grid_position_uniqueness.run_if(any_component_changed::<GridPosition>),
),
)
// UI systems
@ -272,6 +273,9 @@ impl Display for ShapeStore {
}
}
#[derive(Component)]
struct GridBackground;
fn init_world(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
@ -299,6 +303,7 @@ fn init_world(
MeshMaterial2d(grid_material.clone()),
GridPosition { x, y },
Transform::from_xyz(0.0, 0.0, -1.0),
GridBackground,
TETRIS,
));
});
@ -441,13 +446,13 @@ fn init_ui(mut commands: Commands, output_images: Res<OutputImages>, images: Res
border: UiRect::all(Val::Px(5.0)),
..default()
},
BorderColor(BLACK.into()),
BorderColor(WHITE.into()),
)).with_children(|parent| {
let img = images.get(&output_images.tetris).unwrap();
parent.spawn((
Node {
width: Val::Px(img.size_f32().x * 0.5),
height: Val::Px(img.size_f32().y * 0.5),
width: Val::Px(img.size_f32().x * 0.75),
height: Val::Px(img.size_f32().y * 0.75),
..default()
},
ImageNode {
@ -465,7 +470,7 @@ fn init_ui(mut commands: Commands, output_images: Res<OutputImages>, images: Res
border: UiRect::all(Val::Px(5.0)),
..default()
},
BorderColor(BLACK.into()),
BorderColor(WHITE.into()),
)).with_children(|parent| {
let img = images.get(&output_images.battler).unwrap();
parent.spawn((
@ -919,7 +924,7 @@ fn clear_line(
fn adjust_block_lines(
query: Query<(Entity, &Line), Changed<Line>>,
parent: Query<&LineBlocks>,
mut blocks: Query<&mut GridPosition, With<ShapeBlock>>,
mut blocks: Query<&mut GridPosition>,
) {
query.iter().for_each(|(e, Line(i))| {
parent.iter_descendants(e).for_each(|block| {
@ -1093,3 +1098,11 @@ fn update_next_shapes(mut buffer: ResMut<ShapesBuffer>) {
]);
}
}
fn assert_grid_position_uniqueness(
grid_positions: Query<&GridPosition, (Without<GridBackground>, Without<Shape>)>
) {
grid_positions.iter_combinations().for_each(|[a, b]| {
assert_ne!(a, b, "Two entities are in the same grid position!");
});
}

Loading…
Cancel
Save