refine queries

This commit is contained in:
Franz Dietrich 2022-08-09 22:37:26 +02:00
parent 92458b55e5
commit 1d1787b8c0

View File

@ -26,6 +26,7 @@ impl Plugin for TurtlePlugin {
pub struct Turtle {
colors: Colors,
commands: TurtleCommands,
name: Name,
}
impl Default for Turtle {
@ -58,6 +59,7 @@ impl Default for Turtle {
TurtleCommand::Right(Angle(150.)),
TurtleCommand::Forward(Length(100.)),
]),
name: Name::new("Turtle"),
}
}
}
@ -202,18 +204,20 @@ fn setup(mut commands: Commands) {
},
Transform::identity(),
))
.insert(animator);
.insert(animator)
.insert(TurtleShape);
}
fn draw_lines(
mut commands: Commands,
tcmd: Query<&TurtleCommands>,
mut query_event: EventReader<TweenCompleted>,
mut query_event: EventReader<TweenCompleted>, // TODO: howto attach only to the right event?
) {
for ev in query_event.iter() {
let index = ev.user_data;
let tcmd = tcmd.get_single().unwrap();
let t = tcmd.lines.get(index as usize).unwrap();
for t in tcmd.iter() {
let t = t.lines.get(index as usize).unwrap();
match t {
TurtleGraphElement::TurtleLine { start, end } => {
commands.spawn_bundle(GeometryBuilder::build_as(
@ -228,14 +232,12 @@ fn draw_lines(
TurtleGraphElement::Noop => (),
}
}
}
}
/// The sprite is animated by changing its translation depending on the time that has passed since
/// the last frame.
fn keypresses(
//time: Res<Time>,
keys: Res<Input<KeyCode>>,
mut qry: Query<&mut Animator<Transform>>,
mut qry: Query<&mut Animator<Transform>, With<TurtleShape>>,
mut tcmd: Query<&mut TurtleCommands>,
) {
if keys.just_pressed(KeyCode::W) {