diff --git a/src/turtle.rs b/src/turtle.rs index cef2c6f..877ed33 100644 --- a/src/turtle.rs +++ b/src/turtle.rs @@ -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, + mut query_event: EventReader, // 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