|
|
|
@ -64,7 +64,6 @@ fn main() {
|
|
|
|
sync_resource_to_ui::<ShapesBuffer>.run_if(resource_changed::<ShapesBuffer>),
|
|
|
|
sync_resource_to_ui::<ShapesBuffer>.run_if(resource_changed::<ShapesBuffer>),
|
|
|
|
sync_resource_to_ui::<Score>.run_if(resource_changed::<Score>),
|
|
|
|
sync_resource_to_ui::<Score>.run_if(resource_changed::<Score>),
|
|
|
|
sync_singleton_to_ui::<Shape>.run_if(any_component_changed::<Shape>),
|
|
|
|
sync_singleton_to_ui::<Shape>.run_if(any_component_changed::<Shape>),
|
|
|
|
sync_singleton_to_ui::<Orientation>.run_if(any_component_changed::<Orientation>),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(Update, draw_grid)
|
|
|
|
.add_systems(Update, draw_grid)
|
|
|
|
@ -200,46 +199,6 @@ impl std::ops::AddAssign<&GridPosition> for GridPosition {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component, Default, Event, Clone, Debug)]
|
|
|
|
|
|
|
|
enum Orientation {
|
|
|
|
|
|
|
|
#[default]
|
|
|
|
|
|
|
|
Up,
|
|
|
|
|
|
|
|
Left,
|
|
|
|
|
|
|
|
Down,
|
|
|
|
|
|
|
|
Right,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Orientation {
|
|
|
|
|
|
|
|
fn next(&self) -> Self {
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::Up => Self::Left,
|
|
|
|
|
|
|
|
Self::Left => Self::Down,
|
|
|
|
|
|
|
|
Self::Down => Self::Right,
|
|
|
|
|
|
|
|
Self::Right => Self::Up,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn prev(&self) -> Self {
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::Up => Self::Right,
|
|
|
|
|
|
|
|
Self::Right => Self::Down,
|
|
|
|
|
|
|
|
Self::Down => Self::Left,
|
|
|
|
|
|
|
|
Self::Left => Self::Up,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Display for Orientation {
|
|
|
|
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Orientation::Up => write!(f, "up"),
|
|
|
|
|
|
|
|
Orientation::Down => write!(f, "down"),
|
|
|
|
|
|
|
|
Orientation::Left => write!(f, "<-"),
|
|
|
|
|
|
|
|
Orientation::Right => write!(f, "->"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(States, Clone, Eq, PartialEq, Debug, Hash, Default, Component)]
|
|
|
|
#[derive(States, Clone, Eq, PartialEq, Debug, Hash, Default, Component)]
|
|
|
|
enum GameState {
|
|
|
|
enum GameState {
|
|
|
|
#[default]
|
|
|
|
#[default]
|
|
|
|
@ -361,10 +320,6 @@ fn init_debug_ui(mut commands: Commands) {
|
|
|
|
Node::default(),
|
|
|
|
Node::default(),
|
|
|
|
children![
|
|
|
|
children![
|
|
|
|
(Text::new("SHAPE"), SyncSingleton::<Shape>::default()),
|
|
|
|
(Text::new("SHAPE"), SyncSingleton::<Shape>::default()),
|
|
|
|
(
|
|
|
|
|
|
|
|
Text::new("ORIENTATION"),
|
|
|
|
|
|
|
|
SyncSingleton::<Orientation>::default()
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
],
|
|
|
|
));
|
|
|
|
));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -482,10 +437,6 @@ impl Shape {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn rotate(&mut self) {
|
|
|
|
|
|
|
|
*self = self.rotated();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn coordinates(
|
|
|
|
fn coordinates(
|
|
|
|
&self,
|
|
|
|
&self,
|
|
|
|
center: &GridPosition,
|
|
|
|
center: &GridPosition,
|
|
|
|
@ -557,13 +508,13 @@ fn update_position(
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Inline this to when movement occurs
|
|
|
|
// TODO: Inline this to when movement occurs
|
|
|
|
fn update_shape_blocks(
|
|
|
|
fn update_shape_blocks(
|
|
|
|
query: Query<(Entity, &Shape, &Orientation, &GridPosition), Or<(Added<Shape>, Changed<Shape>)>>,
|
|
|
|
query: Query<(Entity, &Shape, &GridPosition), Or<(Added<Shape>, Changed<Shape>)>>,
|
|
|
|
mut blocks: Query<&mut GridPosition, (With<ShapeBlock>, Without<Shape>)>,
|
|
|
|
mut blocks: Query<&mut GridPosition, (With<ShapeBlock>, Without<Shape>)>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
visuals: Res<Visuals>,
|
|
|
|
visuals: Res<Visuals>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
query.iter().for_each(|(e, s, o, center)| {
|
|
|
|
query.iter().for_each(|(e, s, center)| {
|
|
|
|
debug!("Setting piece: {e:?} {o:?} {center:?}\n{}", s.as_ascii());
|
|
|
|
debug!("Setting piece: {e:?} {center:?}\n{}", s.as_ascii());
|
|
|
|
|
|
|
|
|
|
|
|
if blocks.is_empty() {
|
|
|
|
if blocks.is_empty() {
|
|
|
|
let mesh = Mesh2d(visuals.mesh.clone());
|
|
|
|
let mesh = Mesh2d(visuals.mesh.clone());
|
|
|
|
@ -668,7 +619,6 @@ fn clock_cycle(n: f32) -> impl FnMut(Res<Time>, Local<f32>) -> bool {
|
|
|
|
fn add_piece(mut commands: Commands, mut shapes: ResMut<ShapesBuffer>) {
|
|
|
|
fn add_piece(mut commands: Commands, mut shapes: ResMut<ShapesBuffer>) {
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.spawn((
|
|
|
|
.spawn((
|
|
|
|
Orientation::default(),
|
|
|
|
|
|
|
|
GridPosition::default(),
|
|
|
|
GridPosition::default(),
|
|
|
|
shapes.next.pop_front().unwrap(),
|
|
|
|
shapes.next.pop_front().unwrap(),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
|