refine queries
This commit is contained in:
parent
92458b55e5
commit
1d1787b8c0
@ -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,40 +204,40 @@ 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();
|
||||
match t {
|
||||
TurtleGraphElement::TurtleLine { start, end } => {
|
||||
commands.spawn_bundle(GeometryBuilder::build_as(
|
||||
&Line(*start, *end),
|
||||
DrawMode::Outlined {
|
||||
fill_mode: FillMode::color(Color::MIDNIGHT_BLUE),
|
||||
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
|
||||
},
|
||||
Transform::identity(),
|
||||
));
|
||||
|
||||
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(
|
||||
&Line(*start, *end),
|
||||
DrawMode::Outlined {
|
||||
fill_mode: FillMode::color(Color::MIDNIGHT_BLUE),
|
||||
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
|
||||
},
|
||||
Transform::identity(),
|
||||
));
|
||||
}
|
||||
TurtleGraphElement::Noop => (),
|
||||
}
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user