diff --git a/src/animations.rs b/src/animations.rs new file mode 100644 index 0000000..74b34ca --- /dev/null +++ b/src/animations.rs @@ -0,0 +1,74 @@ +use bevy::ecs::prelude::{Component, Query, Res}; +use bevy::prelude::*; +use bevy::prelude::{Time, Timer}; +use bevy::sprite::TextureAtlas; +use bevy_ecs_ldtk::ldtk::ldtk_fields::LdtkFields; +use bevy_ecs_ldtk::EntityInstance; + +use crate::player::Player; + +#[derive(Component, Default)] +pub struct AnimationIndices { + first: i32, + last: i32, +} + +#[derive(Component, Deref, DerefMut, Default)] +pub struct AnimationTimer(Timer); + +impl AnimationTimer { + fn default() -> Self { + AnimationTimer(Timer::from_seconds(0.1, TimerMode::Repeating)) + } +} +impl From<&EntityInstance> for AnimationTimer { + fn from(entity_instance: &EntityInstance) -> Self { + AnimationTimer(Timer::from_seconds( + entity_instance + .get_float_field("animation_timer") + .expect("items field should be correctly typed") + .clone(), + TimerMode::Repeating, + )) + } +} + +impl From<&EntityInstance> for AnimationIndices { + fn from(entity_instance: &EntityInstance) -> Self { + let indices: Vec = entity_instance + .iter_ints_field("animation_indices") + .expect("numbers field should be correctly typed") + .cloned() + .collect(); + + let first = indices.get(0).expect("fuck"); + let last = indices.get(1).expect("fuck"); + AnimationIndices { + first: *first, + last: *last, + } + } +} +fn animate_player( + time: Res