use std::time::Duration;
use bevy::prelude::*;
use bevy_egui::{egui, EguiContexts, EguiPlugin};
use timeline_rs::{easing::{self, EasingFunction, EasingType}, loader::TimelineXMLLoader, Keyframe, Timeline, TimelineTrack, Track, TrackGetter};
// use egui_dropdown::DropDownBox;
// use lazy_static::lazy_static;
fn s(dur: f32) -> Duration {
Duration::from_secs_f32(dur)
}
fn create_timeline() -> Timeline {
let mut tl = Timeline::new();
let xml_x = r#"
0
0
0.375000000
0
0
0.408691406
0
0
0.324999988
0
0
0.777343750
4
0
0.330175757
"#;
let xml_y = r#"
0
0
0.585546851
4
2
0.141503930
1
1
0.443359375
0
2
0.400390625
4
0
0.586718738
"#;
// NOTE: you can also use json
tl.load_xml_str::("x", xml_x).unwrap();
tl.load_xml_str::("y", xml_y).unwrap();
tl
}
#[derive(Resource)]
struct TimelineData {
pub timeline: Timeline,
pub t : f32,
pub x : f32,
pub y : f32,
pub looped: bool,
}
impl Default for TimelineData {
fn default() -> Self {
TimelineData {
timeline: create_timeline(),
t: 0.0,
x: 0.0,
y: 0.0,
looped: true,
}
}
}
pub fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(EguiPlugin)
.insert_resource(TimelineData::default())
.add_systems(Startup, setup)
.add_systems(Update, update_egui)
.add_systems(Update, update)
.add_systems(Update, bevy::window::close_on_esc)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
}
fn update_egui (
mut contexts: EguiContexts,
mut data: ResMut,
) {
egui::Window::new("Easing").show(contexts.ctx_mut(), |ui| {
// display looped as checkbox
ui.checkbox(&mut data.looped, "Looped");
let duration: f32 = data.timeline.get_max_duration().as_secs_f32();
// display t as slider
ui.add(egui::Slider::new(&mut data.t, 0.0..=duration).text("t"));
// display x as slider
ui.add(egui::Slider::new(&mut data.x, 0.0..=1.0).text("x"));
// display y as slider
ui.add(egui::Slider::new(&mut data.y, 0.0..=1.0).text("y"));
});
}
fn update(
mut gizmos: Gizmos,
time: Res