refine queries
This commit is contained in:
parent
92458b55e5
commit
1d1787b8c0
@ -26,6 +26,7 @@ impl Plugin for TurtlePlugin {
|
|||||||
pub struct Turtle {
|
pub struct Turtle {
|
||||||
colors: Colors,
|
colors: Colors,
|
||||||
commands: TurtleCommands,
|
commands: TurtleCommands,
|
||||||
|
name: Name,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Turtle {
|
impl Default for Turtle {
|
||||||
@ -58,6 +59,7 @@ impl Default for Turtle {
|
|||||||
TurtleCommand::Right(Angle(150.)),
|
TurtleCommand::Right(Angle(150.)),
|
||||||
TurtleCommand::Forward(Length(100.)),
|
TurtleCommand::Forward(Length(100.)),
|
||||||
]),
|
]),
|
||||||
|
name: Name::new("Turtle"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,40 +204,40 @@ fn setup(mut commands: Commands) {
|
|||||||
},
|
},
|
||||||
Transform::identity(),
|
Transform::identity(),
|
||||||
))
|
))
|
||||||
.insert(animator);
|
.insert(animator)
|
||||||
|
.insert(TurtleShape);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_lines(
|
fn draw_lines(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
tcmd: Query<&TurtleCommands>,
|
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() {
|
for ev in query_event.iter() {
|
||||||
let index = ev.user_data;
|
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() {
|
||||||
match t {
|
let t = t.lines.get(index as usize).unwrap();
|
||||||
TurtleGraphElement::TurtleLine { start, end } => {
|
match t {
|
||||||
commands.spawn_bundle(GeometryBuilder::build_as(
|
TurtleGraphElement::TurtleLine { start, end } => {
|
||||||
&Line(*start, *end),
|
commands.spawn_bundle(GeometryBuilder::build_as(
|
||||||
DrawMode::Outlined {
|
&Line(*start, *end),
|
||||||
fill_mode: FillMode::color(Color::MIDNIGHT_BLUE),
|
DrawMode::Outlined {
|
||||||
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
|
fill_mode: FillMode::color(Color::MIDNIGHT_BLUE),
|
||||||
},
|
outline_mode: StrokeMode::new(Color::BLACK, 1.0),
|
||||||
Transform::identity(),
|
},
|
||||||
));
|
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(
|
fn keypresses(
|
||||||
//time: Res<Time>,
|
|
||||||
keys: Res<Input<KeyCode>>,
|
keys: Res<Input<KeyCode>>,
|
||||||
mut qry: Query<&mut Animator<Transform>>,
|
mut qry: Query<&mut Animator<Transform>, With<TurtleShape>>,
|
||||||
mut tcmd: Query<&mut TurtleCommands>,
|
mut tcmd: Query<&mut TurtleCommands>,
|
||||||
) {
|
) {
|
||||||
if keys.just_pressed(KeyCode::W) {
|
if keys.just_pressed(KeyCode::W) {
|
||||||
|
Loading…
Reference in New Issue
Block a user