turtlers/src/animation_step.rs
2022-11-21 06:54:46 +01:00

54 lines
1.8 KiB
Rust

use bevy::prelude::{Commands, Query, Transform, With};
use bevy_tweening::Animator;
use crate::{
turtle::{TurtleCommands, TurtleGraphElement, TurtleShape},
turtle_movement::TurtleStep,
};
pub(crate) fn run_animation_step(
commands: &mut Commands,
tcmd: &mut TurtleCommands,
turtle: &mut Query<&mut Animator<Transform>, With<TurtleShape>>,
) {
loop {
match tcmd.get_next() {
Some(TurtleStep {
turtle_animation: Some(turtle_animation),
line_segment: Some(graph_element_to_draw),
line_animation: Some(line_animation),
}) => {
let mut turtle = turtle.single_mut();
turtle.set_tweenable(turtle_animation);
match graph_element_to_draw {
TurtleGraphElement::TurtleLine(line) => {
commands.spawn((line, line_animation));
}
TurtleGraphElement::Noop => (),
TurtleGraphElement::TurtleCircle(circle) => {
commands.spawn((circle, line_animation));
}
}
return;
}
// In case a rotation is performed the line drawing can be skipped
Some(TurtleStep {
turtle_animation: Some(turtle_animation),
line_segment: Some(_),
line_animation: None,
}) => {
let mut turtle = turtle.single_mut();
turtle.set_tweenable(turtle_animation);
return;
}
Some(_) => {
println!("without animation");
}
None => {
println!("nothing to draw");
return;
}
};
}
}