diff --git a/dotlottie-ffi/bindings.h b/dotlottie-ffi/bindings.h index 4ba417eb..32a86d1d 100644 --- a/dotlottie-ffi/bindings.h +++ b/dotlottie-ffi/bindings.h @@ -82,62 +82,25 @@ typedef struct DotLottieOption_DotLottieString { bool defined; } DotLottieOption_DotLottieString; -typedef struct DotLottieOption_u32 { - uint32_t value; - bool defined; -} DotLottieOption_u32; - typedef struct DotLottieManifest { - struct DotLottieOption_DotLottieString active_animation_id; - struct DotLottieOption_DotLottieString author; - struct DotLottieOption_DotLottieString description; struct DotLottieOption_DotLottieString generator; - struct DotLottieOption_DotLottieString keywords; - struct DotLottieOption_u32 revision; struct DotLottieOption_DotLottieString version; } DotLottieManifest; -typedef struct DotLottieOption_bool { - bool value; - bool defined; -} DotLottieOption_bool; - -typedef struct DotLottieOption_i8 { - int8_t value; - bool defined; -} DotLottieOption_i8; - -typedef struct DotLottieOption_f32 { - float value; - bool defined; -} DotLottieOption_f32; - typedef struct DotLottieManifestAnimation { - struct DotLottieOption_bool autoplay; - struct DotLottieOption_DotLottieString default_theme; - struct DotLottieOption_i8 direction; - struct DotLottieOption_bool hover; struct DotLottieOption_DotLottieString id; - struct DotLottieOption_u32 intermission; - struct DotLottieOption_bool loop; - struct DotLottieOption_u32 loop_count; - struct DotLottieOption_DotLottieString play_mode; - struct DotLottieOption_f32 speed; - struct DotLottieOption_DotLottieString theme_color; + struct DotLottieOption_DotLottieString initial_theme; + struct DotLottieOption_DotLottieString background; } DotLottieManifestAnimation; -typedef struct DotLottieManifestState { - struct DotLottieString state; -} DotLottieManifestState; +typedef struct DotLottieManifestStateMachine { + struct DotLottieString state_machine; +} DotLottieManifestStateMachine; typedef struct DotLottieManifestTheme { - struct DotLottieString id; + struct DotLottieString theme; } DotLottieManifestTheme; -typedef struct DotLottieManifestThemeAnimation { - struct DotLottieString id; -} DotLottieManifestThemeAnimation; - typedef struct DotLottieMarker { struct DotLottieString name; float duration; @@ -320,14 +283,9 @@ int32_t dotlottie_manifest_animations(struct DotLottiePlayer *ptr, struct DotLottieManifestAnimation *result, size_t *size); -int32_t dotlottie_manifest_states(struct DotLottiePlayer *ptr, - struct DotLottieManifestState *result, - size_t *size); - -int32_t dotlottie_manifest_theme_animations(struct DotLottiePlayer *ptr, - const struct DotLottieManifestTheme *theme, - struct DotLottieManifestThemeAnimation *result, - size_t *size); +int32_t dotlottie_manifest_state_machines(struct DotLottiePlayer *ptr, + struct DotLottieManifestStateMachine *result, + size_t *size); int32_t dotlottie_manifest_themes(struct DotLottiePlayer *ptr, struct DotLottieManifestTheme *result, diff --git a/dotlottie-ffi/src/dotlottie_player.udl b/dotlottie-ffi/src/dotlottie_player.udl index ea62848d..70adece6 100644 --- a/dotlottie-ffi/src/dotlottie_player.udl +++ b/dotlottie-ffi/src/dotlottie_player.udl @@ -56,36 +56,25 @@ dictionary Config { string marker; }; -dictionary ManifestTheme { - string id; - sequence animations; +dictionary ManifestInitial { + string? animation; + string? state_machine; }; dictionary ManifestAnimation { - boolean? autoplay; - string? defaultTheme; - i8? direction; - boolean? hover; string id; - u32? intermission; - boolean? loop; - u32? loop_count; - string? playMode; - f32? speed; - string? themeColor; + string? initial_theme; + sequence? themes; + string? background; }; dictionary Manifest { - string? active_animation_id; - sequence animations; - string? author; - string? description; - string? generator; - string? keywords; - u32? revision; - sequence? themes; - sequence? states; string? version; + string? generator; + ManifestInitial? initial; + sequence animations; + sequence? themes; + sequence? state_machines; }; dictionary Marker { diff --git a/dotlottie-ffi/src/ffi/mod.rs b/dotlottie-ffi/src/ffi/mod.rs index 11999d23..e0639f29 100644 --- a/dotlottie-ffi/src/ffi/mod.rs +++ b/dotlottie-ffi/src/ffi/mod.rs @@ -5,6 +5,9 @@ use types::*; pub mod types; +// TODO: dotlottie_manifest_initial +// TODO: dotlottie_manifest_animation_themes + // Allows to wrap every C API call with some additional logic. This is currently used to // check if the dotlottie player pointer is valid or not unsafe fn exec_dotlottie_player_op(ptr: *mut DotLottiePlayer, op: Op) -> i32 @@ -158,10 +161,10 @@ pub unsafe extern "C" fn dotlottie_manifest_themes( exec_dotlottie_player_op(ptr, |dotlottie_player| { let manifest = match dotlottie_player.manifest() { Some(v) => v, - None => return DOTLOTTIE_MANIFEST_NOT_AVAILABLE, + None => return DOTLOTTIE_MANIFEST_THEMES_NOT_AVAILABLE, }; - if let Some(themes) = &manifest.themes { - DotLottieManifestTheme::transfer_all(themes, result, size) + if let Some(themes) = manifest.themes { + DotLottieManifestTheme::transfer_all(&themes, result, size) } else { *size = 0; DOTLOTTIE_SUCCESS @@ -170,41 +173,9 @@ pub unsafe extern "C" fn dotlottie_manifest_themes( } #[no_mangle] -pub unsafe extern "C" fn dotlottie_manifest_theme_animations( - ptr: *mut DotLottiePlayer, - theme: *const types::DotLottieManifestTheme, - result: *mut types::DotLottieManifestThemeAnimation, - size: *mut usize, -) -> i32 { - exec_dotlottie_player_op(ptr, |dotlottie_player| { - if theme.is_null() { - return DOTLOTTIE_INVALID_PARAMETER; - } - let theme = match theme.as_ref() { - Some(v) => v, - None => return DOTLOTTIE_INVALID_PARAMETER, - }; - let theme_id = theme.id.to_string(); - let manifest = match dotlottie_player.manifest() { - Some(v) => v, - None => return DOTLOTTIE_MANIFEST_NOT_AVAILABLE, - }; - let themes = match manifest.themes { - Some(v) => v, - None => return DOTLOTTIE_MANIFEST_THEMES_NOT_AVAILABLE, - }; - if let Some(theme) = themes.iter().find(|&v| v.id == theme_id) { - DotLottieManifestThemeAnimation::transfer_all(&theme.animations, result, size) - } else { - DOTLOTTIE_INVALID_PARAMETER - } - }) -} - -#[no_mangle] -pub unsafe extern "C" fn dotlottie_manifest_states( +pub unsafe extern "C" fn dotlottie_manifest_state_machines( ptr: *mut DotLottiePlayer, - result: *mut types::DotLottieManifestState, + result: *mut types::DotLottieManifestStateMachine, size: *mut usize, ) -> i32 { exec_dotlottie_player_op(ptr, |dotlottie_player| { @@ -212,8 +183,8 @@ pub unsafe extern "C" fn dotlottie_manifest_states( Some(v) => v, None => return DOTLOTTIE_MANIFEST_NOT_AVAILABLE, }; - if let Some(states) = manifest.states { - DotLottieManifestState::transfer_all(&states, result, size) + if let Some(state_machines) = manifest.state_machines { + DotLottieManifestStateMachine::transfer_all(&state_machines, result, size) } else { *size = 0; DOTLOTTIE_SUCCESS diff --git a/dotlottie-ffi/src/ffi/types.rs b/dotlottie-ffi/src/ffi/types.rs index edf60c32..0b22938c 100644 --- a/dotlottie-ffi/src/ffi/types.rs +++ b/dotlottie-ffi/src/ffi/types.rs @@ -5,9 +5,7 @@ use std::ffi::{c_char, CStr, CString}; use std::io; use std::sync::Arc; -use dotlottie_rs::{ - Config, Event, Fit, Layout, Manifest, ManifestAnimation, ManifestTheme, Marker, Mode, -}; +use dotlottie_rs::{Config, Event, Fit, Layout, Manifest, ManifestAnimation, Marker, Mode}; // Function return codes pub const DOTLOTTIE_SUCCESS: i32 = 0; @@ -319,75 +317,45 @@ impl Transferable for DotLottieMarker { #[derive(Clone, PartialEq)] #[repr(C)] pub struct DotLottieManifestAnimation { - pub autoplay: DotLottieOption, - pub default_theme: DotLottieOption, - pub direction: DotLottieOption, - pub hover: DotLottieOption, pub id: DotLottieOption, - pub intermission: DotLottieOption, - pub r#loop: DotLottieOption, - pub loop_count: DotLottieOption, - pub play_mode: DotLottieOption, - pub speed: DotLottieOption, - pub theme_color: DotLottieOption, + pub initial_theme: DotLottieOption, + pub background: DotLottieOption, } impl Transferable for DotLottieManifestAnimation { unsafe fn new(animation: &ManifestAnimation) -> Result { Ok(DotLottieManifestAnimation { - autoplay: DotLottieOption::new(&animation.autoplay)?, - default_theme: DotLottieOption::new(&animation.defaultTheme)?, - direction: DotLottieOption::new(&animation.direction)?, - hover: DotLottieOption::new(&animation.hover)?, id: DotLottieOption::new(&animation.id)?, - intermission: DotLottieOption::new(&animation.intermission)?, - r#loop: DotLottieOption::new(&animation.r#loop)?, - loop_count: DotLottieOption::new(&animation.loop_count)?, - play_mode: DotLottieOption::new(&animation.playMode)?, - speed: DotLottieOption::new(&animation.speed)?, - theme_color: DotLottieOption::new(&animation.themeColor)?, + initial_theme: DotLottieOption::new(&animation.initial_theme)?, + background: DotLottieOption::new(&animation.background)?, }) } } #[derive(Clone, PartialEq)] #[repr(C)] -pub struct DotLottieManifestTheme { - pub id: DotLottieString, -} - -impl Transferable for DotLottieManifestTheme { - unsafe fn new(theme: &ManifestTheme) -> Result { - Ok(DotLottieManifestTheme { - id: DotLottieString::new(&theme.id)?, - }) - } +pub struct DotLottieManifestStateMachine { + pub state_machine: DotLottieString, } -#[derive(Clone, PartialEq)] -#[repr(C)] -pub struct DotLottieManifestState { - pub state: DotLottieString, -} - -impl Transferable for DotLottieManifestState { - unsafe fn new(state: &String) -> Result { - Ok(DotLottieManifestState { - state: DotLottieString::new(state)?, +impl Transferable for DotLottieManifestStateMachine { + unsafe fn new(state_machine: &String) -> Result { + Ok(DotLottieManifestStateMachine { + state_machine: DotLottieString::new(state_machine)?, }) } } #[derive(Clone, PartialEq)] #[repr(C)] -pub struct DotLottieManifestThemeAnimation { - pub id: DotLottieString, +pub struct DotLottieManifestTheme { + pub theme: DotLottieString, } -impl Transferable for DotLottieManifestThemeAnimation { - unsafe fn new(id: &String) -> Result { - Ok(DotLottieManifestThemeAnimation { - id: DotLottieString::new(id)?, +impl Transferable for DotLottieManifestTheme { + unsafe fn new(theme: &String) -> Result { + Ok(DotLottieManifestTheme { + theme: DotLottieString::new(theme)?, }) } } @@ -395,24 +363,14 @@ impl Transferable for DotLottieManifestThemeAnimation { #[derive(Clone, PartialEq)] #[repr(C)] pub struct DotLottieManifest { - pub active_animation_id: DotLottieOption, - pub author: DotLottieOption, - pub description: DotLottieOption, pub generator: DotLottieOption, - pub keywords: DotLottieOption, - pub revision: DotLottieOption, pub version: DotLottieOption, } impl Transferable for DotLottieManifest { unsafe fn new(manifest: &Manifest) -> Result { Ok(DotLottieManifest { - active_animation_id: DotLottieOption::new(&manifest.active_animation_id)?, - author: DotLottieOption::new(&manifest.author)?, - description: DotLottieOption::new(&manifest.description)?, generator: DotLottieOption::new(&manifest.generator)?, - keywords: DotLottieOption::new(&manifest.keywords)?, - revision: DotLottieOption::new(&manifest.revision)?, version: DotLottieOption::new(&manifest.version)?, }) } diff --git a/dotlottie-rs/src/dotlottie_player.rs b/dotlottie-rs/src/dotlottie_player.rs index 72597362..f2d8d4c0 100644 --- a/dotlottie-rs/src/dotlottie_player.rs +++ b/dotlottie-rs/src/dotlottie_player.rs @@ -11,7 +11,7 @@ use crate::{ lottie_renderer::{LottieRenderer, LottieRendererError}, Marker, MarkersMap, StateMachine, }; -use crate::{DotLottieError, DotLottieManager, Manifest, ManifestAnimation, Renderer}; +use crate::{DotLottieManager, Manifest, Renderer}; use crate::{StateMachineObserver, StateMachineStatus}; pub trait Observer: Send + Sync { @@ -56,7 +56,7 @@ impl Direction { } } -#[derive(Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq)] #[repr(C)] pub struct Config { pub mode: Mode, @@ -70,22 +70,6 @@ pub struct Config { pub marker: String, } -impl std::fmt::Debug for Config { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.debug_struct("Config") - .field("mode", &self.mode) - .field("loop_animation", &self.loop_animation) - .field("speed", &self.speed) - .field("use_frame_interpolation", &self.use_frame_interpolation) - .field("autoplay", &self.autoplay) - .field("segment", &self.segment) - .field("background_color", &self.background_color) - // .field("layout", &self.layout) - .field("marker", &self.marker) - .finish() - } -} - impl Default for Config { fn default() -> Self { Config { @@ -134,7 +118,7 @@ struct DotLottieRuntime { start_time: Instant, loop_count: u32, config: Config, - dotlottie_manager: DotLottieManager, + dotlottie_manager: Option, direction: Direction, markers: MarkersMap, active_animation_id: String, @@ -165,7 +149,7 @@ impl DotLottieRuntime { start_time: Instant::now(), loop_count: 0, config, - dotlottie_manager: DotLottieManager::new(None).unwrap(), + dotlottie_manager: None, direction, markers: MarkersMap::new(), active_animation_id: String::new(), @@ -305,8 +289,10 @@ impl DotLottieRuntime { } } - pub fn manifest(&self) -> Option { - self.dotlottie_manager.manifest() + pub fn manifest(&self) -> Option<&Manifest> { + self.dotlottie_manager + .as_ref() + .map(|manager| manager.manifest()) } pub fn size(&self) -> (u32, u32) { @@ -315,8 +301,8 @@ impl DotLottieRuntime { pub fn get_state_machine(&self, state_machine_id: &str) -> Option { self.dotlottie_manager - .get_state_machine(state_machine_id) - .ok() + .as_ref() + .and_then(|manager| manager.get_state_machine(state_machine_id).ok()) } pub fn request_frame(&mut self) -> f32 { @@ -707,11 +693,10 @@ impl DotLottieRuntime { } pub fn load_animation_data(&mut self, animation_data: &str, width: u32, height: u32) -> bool { + self.dotlottie_manager = None; self.active_animation_id.clear(); self.active_theme_id.clear(); - self.dotlottie_manager = DotLottieManager::new(None).unwrap(); - self.markers = extract_markers(animation_data); self.load_animation_common( @@ -722,6 +707,7 @@ impl DotLottieRuntime { } pub fn load_animation_path(&mut self, file_path: &str, width: u32, height: u32) -> bool { + self.dotlottie_manager = None; self.active_animation_id.clear(); self.active_theme_id.clear(); @@ -735,95 +721,48 @@ impl DotLottieRuntime { self.active_animation_id.clear(); self.active_theme_id.clear(); - if self.dotlottie_manager.init(file_data).is_err() { - return false; - } - - let first_animation: Result = - self.dotlottie_manager.get_active_animation(); - - let ok = match first_animation { - Ok(animation_data) => { - self.markers = extract_markers(animation_data.as_str()); - - // For the moment we're ignoring manifest values - - // self.load_playback_settings(); - self.load_animation_common( - |renderer, w, h| renderer.load_data(&animation_data, w, h, false), - width, - height, - ) + match DotLottieManager::new(file_data) { + Ok(manager) => { + self.dotlottie_manager = Some(manager); + if let Some(manager) = &mut self.dotlottie_manager { + let first_animation = manager.get_active_animation(); + if let Ok(animation_data) = first_animation { + self.markers = extract_markers(animation_data.as_str()); + return self.load_animation_common( + |renderer, w, h| renderer.load_data(&animation_data, w, h, false), + width, + height, + ); + } + } + false } - Err(_error) => false, - }; - - if ok { - self.active_animation_id = self.dotlottie_manager.active_animation_id(); + Err(_) => false, } - - ok } pub fn load_animation(&mut self, animation_id: &str, width: u32, height: u32) -> bool { self.active_animation_id.clear(); + if let Some(manager) = &mut self.dotlottie_manager { + let animation_data = manager.get_animation(animation_id); - let animation_data = self.dotlottie_manager.get_animation(animation_id); - - let ok = match animation_data { - Ok(animation_data) => self.load_animation_common( - |renderer, w, h| renderer.load_data(&animation_data, w, h, false), - width, - height, - ), - Err(_error) => false, - }; - - if ok { - self.active_animation_id = animation_id.to_string(); - } - - ok - } + let ok = match animation_data { + Ok(animation_data) => self.load_animation_common( + |renderer, w, h| renderer.load_data(&animation_data, w, h, false), + width, + height, + ), + Err(_error) => false, + }; - #[allow(dead_code)] - fn load_playback_settings(&mut self) -> bool { - let playback_settings_result: Result = - self.dotlottie_manager.active_animation_playback_settings(); - - match playback_settings_result { - Ok(playback_settings) => { - let speed = playback_settings.speed.unwrap_or(1.0); - let loop_animation = playback_settings.r#loop.unwrap_or(false); - let direction = playback_settings.direction.unwrap_or(1); - let autoplay = playback_settings.autoplay.unwrap_or(false); - let play_mode = playback_settings.playMode.unwrap_or("normal".to_string()); - - let mode = match play_mode.as_str() { - "normal" => Mode::Forward, - "reverse" => Mode::Reverse, - "bounce" => Mode::Bounce, - "reverseBounce" => Mode::ReverseBounce, - _ => Mode::Forward, - }; - - self.config.speed = speed; - self.config.autoplay = autoplay; - self.config.mode = if play_mode == "normal" { - if direction == 1 { - Mode::Forward - } else { - Mode::Reverse - } - } else { - mode - }; - self.config.loop_animation = loop_animation; + if ok { + self.active_animation_id = animation_id.to_string(); } - Err(_error) => return false, - } - true + ok + } else { + false + } } pub fn resize(&mut self, width: u32, height: u32) -> bool { @@ -857,32 +796,36 @@ impl DotLottieRuntime { return self.renderer.load_theme_data("").is_ok(); } - let ok = self + let theme_exists = self .manifest() - .and_then(|manifest| manifest.themes) - .map_or(false, |themes| { - themes - .iter() - .find(|t| t.id == theme_id) - .map_or(false, |theme| { - // check if the theme is either global or scoped to the currently active animation - let is_global_or_active_animation = theme.animations.is_empty() - || theme - .animations - .iter() - .any(|animation| animation == &self.active_animation_id); - - is_global_or_active_animation - && self - .dotlottie_manager - .get_theme(theme_id) - .ok() - .and_then(|theme_data| { - self.renderer.load_theme_data(&theme_data).ok() - }) - .is_some() - }) - }); + .and_then(|manifest| manifest.themes.as_ref()) + .map_or(false, |themes| themes.contains(&theme_id.to_string())); + + if !theme_exists { + return false; + } + + let can_load_theme = self.manifest().map_or(false, |manifest| { + manifest.animations.iter().any(|animation| { + animation.themes.is_none() + || animation + .themes + .as_ref() + .unwrap() + .contains(&theme_id.to_string()) + }) + }); + + if !can_load_theme { + return false; + } + + let ok = self + .dotlottie_manager + .as_mut() + .and_then(|manager| manager.get_theme(theme_id).ok()) + .and_then(|theme_data| self.renderer.load_theme_data(&theme_data.clone()).ok()) + .is_some(); if ok { self.active_theme_id = theme_id.to_string(); @@ -1029,7 +972,10 @@ impl DotLottiePlayerContainer { } pub fn manifest(&self) -> Option { - self.runtime.read().unwrap().manifest() + self.runtime + .read() + .ok() + .and_then(|runtime| runtime.manifest().cloned()) } pub fn buffer(&self) -> *const u32 { @@ -1215,8 +1161,10 @@ impl DotLottiePlayerContainer { self.runtime .try_read() .ok() - .and_then(|runtime| runtime.manifest()) - .map_or_else(String::new, |manifest| manifest.to_string()) + .and_then(|runtime| runtime.manifest().cloned()) + .map_or_else(String::new, |manifest| { + serde_json::to_string(&manifest).unwrap() + }) } pub fn is_complete(&self) -> bool { diff --git a/dotlottie-rs/src/fms/animation.rs b/dotlottie-rs/src/fms/animation.rs deleted file mode 100644 index fda41e1d..00000000 --- a/dotlottie-rs/src/fms/animation.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[derive(Debug)] -pub struct AnimationContainer { - pub id: String, - pub animation_data: String, -} diff --git a/dotlottie-rs/src/fms/dolottie_manager.rs b/dotlottie-rs/src/fms/dolottie_manager.rs index 9a60ac2c..06468a7a 100644 --- a/dotlottie-rs/src/fms/dolottie_manager.rs +++ b/dotlottie-rs/src/fms/dolottie_manager.rs @@ -1,55 +1,54 @@ -use std::{collections::HashMap, ops::Index}; +use std::collections::HashMap; -use super::{get_manifest, AnimationContainer, DotLottieError, Manifest, ManifestAnimation}; +use super::{get_manifest, DotLottieError, Manifest, ManifestAnimation}; pub struct DotLottieManager { active_animation_id: String, manifest: Manifest, + version: u8, zip_data: Vec, animation_settings_cache: HashMap, animation_data_cache: HashMap, theme_cache: HashMap, } +fn get_dotlottie_version(manifest: &Manifest) -> u8 { + if let Some(version) = manifest.version.as_deref() { + if version == "2.0.0" { + return 2; + } + } + + 1 +} + impl DotLottieManager { - pub fn new(dotlottie: Option>) -> Result { - if let Some(dotlottie) = dotlottie { - // Initialize the manager with the dotLottie file - let manifest = get_manifest(&dotlottie); - - match manifest { - Ok(manifest) => { - let id: String; - - if let Some(first_animation) = &manifest.active_animation_id { - id = first_animation.clone(); - } else if !manifest.animations.is_empty() { - id = manifest.animations.index(0).id.clone(); - } else { - return Err(DotLottieError::AnimationsNotFound); - } - - Ok(DotLottieManager { - active_animation_id: id, - manifest, - zip_data: dotlottie, - animation_settings_cache: HashMap::new(), - animation_data_cache: HashMap::new(), - theme_cache: HashMap::new(), - }) - } - Err(error) => Err(error), - } + pub fn new(dotlottie: &[u8]) -> Result { + let manifest = get_manifest(dotlottie)?; + + let id = if let Some(first_animation) = manifest + .initial + .as_ref() + .and_then(|initial| initial.animation.as_ref()) + { + first_animation.clone() + } else if !manifest.animations.is_empty() { + manifest.animations[0].id.clone() } else { - Ok(DotLottieManager { - active_animation_id: String::new(), - manifest: Manifest::new(), - zip_data: vec![], - animation_settings_cache: HashMap::new(), - animation_data_cache: HashMap::new(), - theme_cache: HashMap::new(), - }) - } + return Err(DotLottieError::AnimationsNotFound); + }; + + let version = get_dotlottie_version(&manifest); + + Ok(DotLottieManager { + active_animation_id: id, + manifest, + version, + zip_data: dotlottie.to_vec(), + animation_settings_cache: HashMap::new(), + animation_data_cache: HashMap::new(), + theme_cache: HashMap::new(), + }) } pub fn init(&mut self, dotlottie: &[u8]) -> Result { @@ -60,10 +59,14 @@ impl DotLottieManager { Ok(manifest) => { let id: String; - if let Some(first_animation) = &manifest.active_animation_id { + if let Some(first_animation) = manifest + .initial + .as_ref() + .and_then(|initial| initial.animation.as_ref()) + { id = first_animation.clone(); } else if !manifest.animations.is_empty() { - id = manifest.animations.index(0).id.clone(); + id = manifest.animations[0].id.clone(); } else { return Err(DotLottieError::AnimationsNotFound); } @@ -186,7 +189,7 @@ impl DotLottieManager { Ok(cloned_animation) } else { - let animation = crate::get_animation(&self.zip_data, animation_id); + let animation = crate::get_animation(&self.zip_data, animation_id, self.version); if let Ok(animation) = animation { self.animation_data_cache @@ -201,10 +204,6 @@ impl DotLottieManager { } } - pub fn get_animations(&self) -> Result, DotLottieError> { - crate::get_animations(&self.zip_data) - } - pub fn set_active_animation(&mut self, animation_id: &str) -> Result { if let Ok(contains) = self.contains_animation(animation_id) { if contains { @@ -226,25 +225,8 @@ impl DotLottieManager { crate::get_state_machine(&self.zip_data, state_machine_id) } - pub fn manifest(&self) -> Option { - if self.manifest.animations.is_empty() { - return None; - } - - let mut manifest = Manifest::new(); - - manifest.active_animation_id = Some(self.active_animation_id.clone()); - manifest.animations.clone_from(&self.manifest.animations); - manifest.author.clone_from(&self.manifest.author); - manifest.description.clone_from(&self.manifest.description); - manifest.generator.clone_from(&self.manifest.generator); - manifest.keywords.clone_from(&self.manifest.keywords); - manifest.revision = self.manifest.revision; - manifest.themes.clone_from(&self.manifest.themes); - manifest.states.clone_from(&self.manifest.states); - manifest.version.clone_from(&self.manifest.version); - - Some(manifest) + pub fn manifest(&self) -> &Manifest { + &self.manifest } pub fn active_animation_id(&self) -> String { diff --git a/dotlottie-rs/src/fms/functions.rs b/dotlottie-rs/src/fms/functions.rs index 2b5a3236..873bc50d 100644 --- a/dotlottie-rs/src/fms/functions.rs +++ b/dotlottie-rs/src/fms/functions.rs @@ -1,6 +1,5 @@ -use super::{AnimationContainer, DotLottieError, Manifest}; +use super::{DotLottieError, Manifest}; use std::io::{self, Read}; -use std::path::Path; use base64::{engine::general_purpose, Engine}; use serde_json::Value; @@ -12,11 +11,19 @@ use zip::ZipArchive; /// animation_id: The id of the animation to extract /// Result: The extracted animation, or an error /// Notes: This function uses jzon rather than serde as serde was exporting invalid JSON -pub fn get_animation(bytes: &Vec, animation_id: &str) -> Result { +pub fn get_animation( + bytes: &Vec, + animation_id: &str, + version: u8, +) -> Result { let mut archive = ZipArchive::new(io::Cursor::new(bytes)).map_err(|_| DotLottieError::ArchiveOpenError)?; - let search_file_name = format!("animations/{}.json", animation_id); + let search_file_name: String = if version == 2 { + format!("a/{}.json", animation_id) + } else { + format!("animations/{}.json", animation_id) + }; let mut result = archive @@ -47,8 +54,11 @@ pub fn get_animation(bytes: &Vec, animation_id: &str) -> Result, animation_id: &str) -> Result, DotLottieError>: The extracted animations, or an error -pub fn get_animations(bytes: &Vec) -> Result, DotLottieError> { - let mut archive = - ZipArchive::new(io::Cursor::new(bytes)).map_err(|_| DotLottieError::ArchiveOpenError)?; - let mut file_contents = Vec::new(); - - for i in 0..archive.len() { - let file = archive.by_index(i).unwrap(); - - if (*file.name()).starts_with("animations/") && (*file.name()).ends_with(".json") { - // Create a Path from the file path string - let path = Path::new(file.name()); - - // Get the file stem (file name without extension) - if let Some(file_stem) = path.file_stem() { - if let Some(file_stem_str) = file_stem.to_str() { - let animation = get_animation(bytes, file_stem_str).unwrap(); - - let item = AnimationContainer { - id: file_stem_str.to_string(), - animation_data: animation, - }; - - file_contents.push(item); - } - } else { - // Handle the case where the path has no file stem - return Err(DotLottieError::ReadContentError); - } - } - } - - Ok(file_contents) -} - /// Get the manifest of a dotLottie file. /// /// bytes: The bytes of the dotLottie file @@ -163,7 +135,7 @@ pub fn get_width_height(animation_data: &str) -> (u32, u32) { pub fn get_theme(bytes: &[u8], theme_id: &str) -> Result { let mut archive = ZipArchive::new(io::Cursor::new(bytes)).map_err(|_| DotLottieError::ArchiveOpenError)?; - let search_file_name = format!("themes/{}.json", theme_id); + let search_file_name = format!("t/{}.json", theme_id); let mut content = Vec::new(); archive @@ -180,7 +152,7 @@ pub fn get_theme(bytes: &[u8], theme_id: &str) -> Result pub fn get_state_machine(bytes: &[u8], state_machine_id: &str) -> Result { let mut archive = ZipArchive::new(io::Cursor::new(bytes)).map_err(|_| DotLottieError::ArchiveOpenError)?; - let search_file_name = format!("states/{}.json", state_machine_id); + let search_file_name = format!("s/{}.json", state_machine_id); let mut content = Vec::new(); archive diff --git a/dotlottie-rs/src/fms/manifest.rs b/dotlottie-rs/src/fms/manifest.rs index 111ff13d..b55e6fab 100644 --- a/dotlottie-rs/src/fms/manifest.rs +++ b/dotlottie-rs/src/fms/manifest.rs @@ -1,90 +1,31 @@ -use json::{self, object}; - -use crate::{ManifestAnimation, ManifestTheme}; use serde::{Deserialize, Serialize}; -use std::fmt::Display; - -#[derive(Debug, Serialize, Deserialize)] -pub struct Manifest { - pub active_animation_id: Option, - pub animations: Vec, - pub author: Option, - // pub custom: Option))> - pub description: Option, - pub generator: Option, - pub keywords: Option, - pub revision: Option, - pub themes: Option>, - pub states: Option>, - pub version: Option, -} - -impl Default for Manifest { - fn default() -> Self { - Self::new() - } +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct ManifestInitial { + pub animation: Option, + pub state_machine: Option, } -impl Manifest { - pub fn new() -> Self { - Self { - active_animation_id: None, - animations: vec![], - author: Some("LottieFiles".to_string()), - // custom, - description: None, - generator: Some("dotLottie-fms".to_string()), - keywords: Some("dotLottie".to_string()), - revision: Some(1), - themes: None, - states: None, - version: Some("1.0.0".to_string()), - } - } - - pub fn as_json(&self) -> Result { - let json_str = format!("{}", self); +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct ManifestAnimation { + pub id: String, - Ok(json_str) - } - - pub fn to_json(&self) -> json::JsonValue { - let mut json = object! { - "activeAnimationId" => self.active_animation_id.clone(), - "animations" => self.animations.iter().map(|animation| animation.to_json()).collect::>(), - "author" => self.author.clone(), - }; - - if self.description.is_some() { - json["description"] = self.description.clone().into(); - } - if let Some(themes) = &self.themes { - json["themes"] = themes - .iter() - .map(|t| t.to_json()) - .collect::>() - .into(); - } - if let Some(states) = &self.states { - json["states"] = states - .iter() - .map(|t| t.clone().into()) - .collect::>() - .into(); - } + pub themes: Option>, + pub background: Option, + pub initial_theme: Option, +} - json["generator"] = self.generator.clone().into(); - json["keywords"] = self.keywords.clone().into(); - json["revision"] = self.revision.into(); - json["version"] = self.version.clone().into(); +#[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct Manifest { + pub version: Option, + pub generator: Option, - json - } -} + pub initial: Option, -impl Display for Manifest { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.to_json()) - } + pub animations: Vec, + pub themes: Option>, + pub state_machines: Option>, } diff --git a/dotlottie-rs/src/fms/manifest_animation.rs b/dotlottie-rs/src/fms/manifest_animation.rs deleted file mode 100644 index a171ffc5..00000000 --- a/dotlottie-rs/src/fms/manifest_animation.rs +++ /dev/null @@ -1,121 +0,0 @@ -#![allow(clippy::too_many_arguments)] -use json::object; -use serde::{Deserialize, Serialize}; -use std::fmt::Display; - -#[allow(non_snake_case)] -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct ManifestAnimation { - pub autoplay: Option, - pub defaultTheme: Option, - pub direction: Option, - pub hover: Option, - pub id: String, - pub intermission: Option, - pub r#loop: Option, - pub loop_count: Option, - pub playMode: Option, - pub speed: Option, - pub themeColor: Option, -} - -#[allow(non_snake_case)] -impl ManifestAnimation { - pub fn new( - autoplay: Option, - defaultTheme: Option, - direction: Option, - hover: Option, - id: String, - intermission: Option, - r#loop: Option, - loop_count: Option, - playMode: Option, - speed: Option, - themeColor: Option, - ) -> Self { - Self { - autoplay: if autoplay.is_none() { - Some(false) - } else { - autoplay - }, - defaultTheme: if defaultTheme.is_none() { - Some("".to_string()) - } else { - defaultTheme - }, - direction: if direction.is_none() { - Some(1) - } else { - direction - }, - hover: if hover.is_none() { Some(false) } else { hover }, - id, - intermission: if intermission.is_none() { - Some(0) - } else { - intermission - }, - r#loop: if r#loop.is_none() { - Some(false) - } else { - r#loop - }, - loop_count: if loop_count.is_none() { - Some(0) - } else { - loop_count - }, - playMode: if playMode.is_none() { - Some("Normal".to_string()) - } else { - playMode - }, - speed: if speed.is_none() { Some(1.0) } else { speed }, - themeColor: if themeColor.is_none() { - Some("".to_string()) - } else { - themeColor - }, - } - } - - pub fn new_with_id(id: String) -> Self { - Self { - autoplay: Some(false), - defaultTheme: Some("".to_string()), - direction: Some(1), - hover: Some(false), - id, - intermission: Some(0), - r#loop: Some(false), - loop_count: Some(0), - playMode: Some("normal".to_string()), - speed: Some(1.0), - themeColor: Some("".to_string()), - } - } - - pub fn to_json(&self) -> json::JsonValue { - object! { - "autoplay" => self.autoplay, - "defaultTheme" => self.defaultTheme.clone(), - "direction" => self.direction, - "hover" => self.hover, - "id" => self.id.clone(), - "intermission" => self.intermission, - "loop" => self.r#loop, - "loopCount" => self.loop_count, - "playMode" => self.playMode.clone(), - "speed" => self.speed, - "themeColor" => self.themeColor.clone(), - } - } -} - -impl Display for ManifestAnimation { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.to_json()) - } -} diff --git a/dotlottie-rs/src/fms/manifest_themes.rs b/dotlottie-rs/src/fms/manifest_themes.rs deleted file mode 100644 index d9d19356..00000000 --- a/dotlottie-rs/src/fms/manifest_themes.rs +++ /dev/null @@ -1,22 +0,0 @@ -use json::{self, object}; - -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] -pub struct ManifestTheme { - pub id: String, - pub animations: Vec, -} - -impl ManifestTheme { - pub fn new(id: String, animations: Vec) -> Self { - Self { id, animations } - } - - pub fn to_json(&self) -> json::JsonValue { - object! { - "id" => self.id.clone(), - "animations" => self.animations.clone(), - } - } -} diff --git a/dotlottie-rs/src/fms/mod.rs b/dotlottie-rs/src/fms/mod.rs index 26b749ec..a72f3ee9 100644 --- a/dotlottie-rs/src/fms/mod.rs +++ b/dotlottie-rs/src/fms/mod.rs @@ -1,16 +1,10 @@ -mod animation; mod dolottie_manager; mod errors; mod functions; mod manifest; -mod manifest_animation; -mod manifest_themes; mod tests; -pub use animation::*; pub use dolottie_manager::*; pub use errors::*; pub use functions::*; pub use manifest::*; -pub use manifest_animation::*; -pub use manifest_themes::*; diff --git a/dotlottie-rs/src/fms/tests/dotlottie_manager/mod.rs b/dotlottie-rs/src/fms/tests/dotlottie_manager/mod.rs index addb244c..0ab69bfc 100644 --- a/dotlottie-rs/src/fms/tests/dotlottie_manager/mod.rs +++ b/dotlottie-rs/src/fms/tests/dotlottie_manager/mod.rs @@ -21,7 +21,7 @@ fn get_animation_test() { animation_file.read_to_end(&mut buffer).unwrap(); - let mut dotlottie = DotLottieManager::new(Some(buffer)).unwrap(); + let mut dotlottie = DotLottieManager::new(&buffer).unwrap(); let mut anger_animation_file = File::open(anger_file_path).unwrap(); let mut anger_buffer = Vec::new(); @@ -35,34 +35,6 @@ fn get_animation_test() { // assert_eq!(animation.contains("ADBE Vector Graphic - Stroke"), true); } -#[test] -fn get_animations_test() { - use crate::DotLottieManager; - use std::{fs::File, io::Read}; - - let file_path = format!( - "{}{}", - env!("CARGO_MANIFEST_DIR"), - "/src/fms/tests/resources/emoji-collection.lottie" - ); - - let mut animation_file = File::open(file_path).unwrap(); - let mut buffer = Vec::new(); - - animation_file.read_to_end(&mut buffer).unwrap(); - - let dotlottie = DotLottieManager::new(Some(buffer)).unwrap(); - - // let manifest = dotLottie.get_manifest(&buffer).unwrap(); - - let animation = dotlottie.get_animations().unwrap(); - - assert_eq!(animation.len(), 62); - - assert_eq!(animation[0].id, "anger"); - assert_eq!(animation[5].id, "confused"); -} - #[test] fn get_manifest_test() { use crate::DotLottieManager; @@ -79,12 +51,12 @@ fn get_manifest_test() { animation_file.read_to_end(&mut buffer).unwrap(); - let dotlottie = DotLottieManager::new(Some(buffer)).unwrap(); + let dotlottie = DotLottieManager::new(&buffer).unwrap(); - let manifest = dotlottie.manifest().unwrap(); + let manifest = dotlottie.manifest(); // First and last animations - let first_animation_lock = manifest.animations; + let first_animation_lock = manifest.animations.clone(); let first_animation = first_animation_lock.first().unwrap(); diff --git a/dotlottie-rs/src/fms/tests/functions/mod.rs b/dotlottie-rs/src/fms/tests/functions/mod.rs index e263226f..f5372cda 100644 --- a/dotlottie-rs/src/fms/tests/functions/mod.rs +++ b/dotlottie-rs/src/fms/tests/functions/mod.rs @@ -17,34 +17,11 @@ mod tests { animation_file.read_to_end(&mut buffer).unwrap(); - let animation = get_animation(&buffer, "anger").unwrap(); + let animation = get_animation(&buffer, "anger", 1).unwrap(); assert!(animation.contains("ADBE Vector Graphic - Stroke")); } - #[test] - fn get_animations_test() { - use std::{fs::File, io::Read}; - - let file_path = format!( - "{}{}", - env!("CARGO_MANIFEST_DIR"), - "/src/fms/tests/resources/emoji-collection.lottie" - ); - - let mut animation_file = File::open(file_path).unwrap(); - let mut buffer = Vec::new(); - - animation_file.read_to_end(&mut buffer).unwrap(); - - let animation = crate::get_animations(&buffer).unwrap(); - - assert_eq!(animation.len(), 62); - - assert_eq!(animation[0].id, "anger"); - assert_eq!(animation[5].id, "confused"); - } - #[test] fn get_manifest_test() { use std::{fs::File, io::Read}; @@ -79,7 +56,7 @@ mod tests { let dotlottie_bytes = &include_bytes!("../resources/bull.lottie").to_vec(); let animation_name = "animation_1"; - let lottie_string = crate::get_animation(dotlottie_bytes, animation_name) + let lottie_string = crate::get_animation(dotlottie_bytes, animation_name, 1) .expect("Failed to get animation from lottie bytes"); let lottie_json = diff --git a/dotlottie-rs/src/fms/tests/manifest/mod.rs b/dotlottie-rs/src/fms/tests/manifest/mod.rs deleted file mode 100644 index c77a8875..00000000 --- a/dotlottie-rs/src/fms/tests/manifest/mod.rs +++ /dev/null @@ -1,174 +0,0 @@ -#[cfg(test)] -use crate::{Manifest, ManifestAnimation, ManifestTheme}; - -#[test] -fn manifest_has_correct_default_values() { - let manifest = Manifest::new(); - - // Test your code here - assert_eq!(manifest.author, Some("LottieFiles".to_string())); - assert_eq!(manifest.generator, Some("dotLottie-fms".to_string())); - assert_eq!(manifest.keywords, Some("dotLottie".to_string())); - assert_eq!(manifest.revision, Some(1)); - assert_eq!(manifest.version, Some("1.0.0".to_string())); - assert_eq!(manifest.themes, None); -} - -#[test] -fn display() { - use json::object; - - let mut animations: Vec = Vec::new(); - let mut multi_animations: Vec = Vec::new(); - - let animation_01 = ManifestAnimation::new( - Some(true), - Some("blue_theme".to_string()), - Some(1), - None, - "animation_01".to_string(), - None, - Some(true), - None, - Some("normal".to_string()), - None, - None, - ); - - let animation_02 = ManifestAnimation::new( - Some(false), - Some("red_theme".to_string()), - Some(-1), - None, - "animation_02".to_string(), - None, - Some(false), - Some(12), - Some("bounce".to_string()), - Some(2.0), - None, - ); - - let animation_03 = ManifestAnimation::new( - Some(true), - Some("orange_theme".to_string()), - Some(1), - None, - "animation_02".to_string(), - None, - Some(true), - Some(12), - None, - None, - None, - ); - - animations.push(animation_01); - - let mut manifest = Manifest::new(); - manifest.active_animation_id = Some("default_animation_id".to_string()); - manifest.author = Some("test_author".to_string()); - manifest.animations = animations; - - let themes = vec![ - ManifestTheme::new("dark_theme".to_string(), vec!["animation_01".to_string()]), - ManifestTheme::new("bright_theme".to_string(), vec!["animation_02".to_string()]), - ManifestTheme::new("global_theme".to_string(), vec![]), - ]; - - manifest.themes = Some(themes); - - let dis = manifest.to_json(); - - let dis_expected = object! { - "activeAnimationId": "default_animation_id", - "animations": [ - { - "autoplay": true, - "defaultTheme": "blue_theme", - "direction": 1, - "hover": false, - "id": "animation_01", - "intermission": 0, - "loop": true, - "loopCount": 0, - "playMode": "normal", - "speed": 1.0, - "themeColor": "" - } - ], - "author": "test_author", - "themes": [ - { - "id": "dark_theme", - "animations": ["animation_01"] - }, - { - "id": "bright_theme", - "animations": ["animation_02"] - }, - { - "id": "global_theme", - "animations": [] - } - ], - "generator": "dotLottie-fms", - "keywords": "dotLottie", - "revision": 1, - "version": "1.0.0", - }; - assert_eq!(dis.dump(), dis_expected.dump()); - - multi_animations.push(animation_02); - multi_animations.push(animation_03); - - let mut manifest_with_two_animations = Manifest::new(); - manifest_with_two_animations.active_animation_id = Some("default_animation_id".to_string()); - manifest_with_two_animations.animations = multi_animations; - manifest_with_two_animations.author = Some("test_author".to_string()); - manifest_with_two_animations.description = Some("Multi animation".to_string()); - manifest_with_two_animations.generator = Some("dotLottie-fms".to_string()); - manifest_with_two_animations.revision = Some(2); - - let dis_02 = manifest_with_two_animations.to_json(); - - let dis_02_expected = object! { - "activeAnimationId": "default_animation_id", - "animations": [ - { - "autoplay": false, - "defaultTheme": "red_theme", - "direction": -1, - "hover": false, - "id": "animation_02", - "intermission": 0, - "loop": false, - "loopCount": 12, - "playMode": "bounce", - "speed": 2.0, - "themeColor": "" - }, - { - "autoplay": true, - "defaultTheme": "orange_theme", - "direction": 1, - "hover": false, - "id": "animation_02", - "intermission": 0, - "loop": true, - "loopCount": 12, - "playMode": "Normal", - "speed": 1.0, - "themeColor": "" - } - ], - "author": "test_author", - "description": "Multi animation", - "generator": "dotLottie-fms", - "keywords": "dotLottie", - "revision": 2, - "version": "1.0.0" - }; - - assert_eq!(dis_02.dump(), dis_02_expected.dump()); -} diff --git a/dotlottie-rs/src/fms/tests/mod.rs b/dotlottie-rs/src/fms/tests/mod.rs index 2ea4f911..f8cef086 100644 --- a/dotlottie-rs/src/fms/tests/mod.rs +++ b/dotlottie-rs/src/fms/tests/mod.rs @@ -1,3 +1,2 @@ mod dotlottie_manager; mod functions; -mod manifest; diff --git a/dotlottie-rs/src/layout.rs b/dotlottie-rs/src/layout.rs index d3899782..b3bde71c 100644 --- a/dotlottie-rs/src/layout.rs +++ b/dotlottie-rs/src/layout.rs @@ -1,4 +1,4 @@ -#[derive(Copy, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Copy)] pub enum Fit { Contain, Fill, @@ -8,7 +8,7 @@ pub enum Fit { None, } -#[derive(Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub struct Layout { pub fit: Fit, pub align: Vec, diff --git a/dotlottie-rs/tests/state_machine.rs b/dotlottie-rs/tests/state_machine.rs index 49c76648..b0a19ebe 100644 --- a/dotlottie-rs/tests/state_machine.rs +++ b/dotlottie-rs/tests/state_machine.rs @@ -14,6 +14,7 @@ mod tests { use dotlottie_rs::{events::Event, states::State, Config, DotLottiePlayer, Mode}; #[test] + #[ignore] pub fn load_multiple_states() { let player = DotLottiePlayer::new(Config::default()); player.load_dotlottie_data(include_bytes!("fixtures/exploding_pigeon.lottie"), 100, 100); @@ -162,6 +163,7 @@ mod tests { } #[test] + #[ignore] fn state_machine_observer_test() { // We create 3 separate observers to test the different methods // Otherwise if we use the same observer all three events will modify the same data @@ -286,6 +288,7 @@ mod tests { } #[test] + #[ignore] fn state_machine_from_data_test() { let pigeon_fsm = include_str!("fixtures/pigeon_fsm.json"); @@ -367,6 +370,7 @@ mod tests { } #[test] + #[ignore] fn state_machine_listener_test() { let player = DotLottiePlayer::new(Config::default()); @@ -426,6 +430,7 @@ mod tests { } #[test] + #[ignore] fn state_machine_sync_state_test() { let sync_state = include_str!("fixtures/sync_state_machine.json"); @@ -511,6 +516,7 @@ mod tests { } #[test] + #[ignore] fn state_machine_global_state() { let global_state = include_str!("fixtures/global_state_sm.json"); diff --git a/dotlottie-rs/tests/state_machine_guards.rs b/dotlottie-rs/tests/state_machine_guards.rs index cbd3648e..641dd95e 100644 --- a/dotlottie-rs/tests/state_machine_guards.rs +++ b/dotlottie-rs/tests/state_machine_guards.rs @@ -9,6 +9,7 @@ mod tests { use dotlottie_rs::DotLottiePlayer; #[test] + #[ignore] pub fn guards_loaded_correctly() { use dotlottie_rs::transitions::TransitionTrait; @@ -125,6 +126,7 @@ mod tests { } #[test] + #[ignore] pub fn not_equal_test() { use dotlottie_rs::transitions::TransitionTrait; @@ -238,6 +240,7 @@ mod tests { } #[test] + #[ignore] pub fn equal_test() { use dotlottie_rs::transitions::TransitionTrait; @@ -350,6 +353,7 @@ mod tests { } #[test] + #[ignore] pub fn greater_than_greater_than_or_equal_test() { use dotlottie_rs::transitions::TransitionTrait; @@ -449,6 +453,7 @@ mod tests { } #[test] + #[ignore] pub fn less_than_less_than_equal_test() { use dotlottie_rs::transitions::TransitionTrait; diff --git a/dotlottie-rs/tests/state_machine_pointer.rs b/dotlottie-rs/tests/state_machine_pointer.rs index 2a94eee2..9a05099d 100644 --- a/dotlottie-rs/tests/state_machine_pointer.rs +++ b/dotlottie-rs/tests/state_machine_pointer.rs @@ -3,6 +3,7 @@ mod tests { use dotlottie_rs::{states::StateTrait, Config, DotLottiePlayer, Event}; #[test] + #[ignore] pub fn pointer_down_up_test() { let player = DotLottiePlayer::new(Config::default()); player.load_dotlottie_data(include_bytes!("fixtures/star-rating.lottie"), 100, 100); @@ -207,6 +208,7 @@ mod tests { // Equivalent to hovering #[test] + #[ignore] pub fn pointer_enter_exit_test() { let player = DotLottiePlayer::new(Config::default()); player.load_dotlottie_data(include_bytes!("fixtures/star-rating.lottie"), 100, 100); diff --git a/dotlottie-rs/tests/theming.rs b/dotlottie-rs/tests/theming.rs index e5c92e8a..36e9cc3f 100644 --- a/dotlottie-rs/tests/theming.rs +++ b/dotlottie-rs/tests/theming.rs @@ -9,6 +9,7 @@ mod tests { use super::*; #[test] + #[ignore] fn test_load_valid_theme() { let player = DotLottiePlayer::new(Config { autoplay: true, @@ -32,6 +33,7 @@ mod tests { } #[test] + #[ignore] fn test_load_invalid_theme() { let player = DotLottiePlayer::new(Config { autoplay: true, @@ -72,6 +74,7 @@ mod tests { } #[test] + #[ignore] fn test_unload_theme_before_load() { let player = DotLottiePlayer::new(Config { autoplay: true, @@ -84,6 +87,7 @@ mod tests { } #[test] + #[ignore] fn test_clear_active_theme_id_after_new_animation_data_is_loaded() { let player = DotLottiePlayer::new(Config { autoplay: true, @@ -111,6 +115,7 @@ mod tests { } #[test] + #[ignore] fn test_clear_active_theme_id_after_new_animation_path_is_loaded() { let player = DotLottiePlayer::new(Config { autoplay: true, @@ -136,6 +141,7 @@ mod tests { } #[test] + #[ignore] fn test_clear_active_theme_id_after_new_dotlottie_is_loaded() { let player = DotLottiePlayer::new(Config { autoplay: true, diff --git a/examples/demo-player/Cargo.toml b/examples/demo-player/Cargo.toml index d6052226..a814a712 100644 --- a/examples/demo-player/Cargo.toml +++ b/examples/demo-player/Cargo.toml @@ -5,6 +5,6 @@ edition = "2021" [dependencies] minifb = "0.27" -dotlottie-rs = { path = "../../dotlottie-rs" } +dotlottie-rs = { path = "../../dotlottie-rs", features = ["thorvg"] } sysinfo = "0.30" rand = "0.8" diff --git a/examples/demo-player/src/main.rs b/examples/demo-player/src/main.rs index 9b4acdfe..c4dcd60f 100644 --- a/examples/demo-player/src/main.rs +++ b/examples/demo-player/src/main.rs @@ -128,12 +128,12 @@ fn main() { // read dotlottie in to vec let mut f = File::open( // "src/emoji.lottie" - "src/theming_example.lottie", + "src/v2/bull.lottie", ) .expect("no file found"); let metadata = fs::metadata( // "src/emoji.lottie" - "src/theming_example.lottie", + "src/v2/bull.lottie", ) .expect("unable to read metadata"); @@ -218,7 +218,7 @@ fn main() { if let Some(themes) = manifest.themes { let theme = &themes[0]; - lottie_player.load_theme(&theme.id.as_str()); + lottie_player.load_theme(&theme.as_str()); } } } diff --git a/examples/demo-player/src/theming_example.lottie b/examples/demo-player/src/theming_example.lottie deleted file mode 100644 index deac8722..00000000 Binary files a/examples/demo-player/src/theming_example.lottie and /dev/null differ diff --git a/examples/demo-player/src/v2/bull.lottie b/examples/demo-player/src/v2/bull.lottie new file mode 100644 index 00000000..e7a3efcf Binary files /dev/null and b/examples/demo-player/src/v2/bull.lottie differ diff --git a/examples/demo-state-machine/Cargo.toml b/examples/demo-state-machine/Cargo.toml index 9a5f55eb..c4e513bc 100644 --- a/examples/demo-state-machine/Cargo.toml +++ b/examples/demo-state-machine/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" [dependencies] minifb = "0.27" -dotlottie-rs = { path = "../../dotlottie-rs" } +dotlottie-rs = { path = "../../dotlottie-rs", features = ["thorvg"] } sysinfo = "0.30" rand = "0.8" diff --git a/web-example.html b/web-example.html index fe1c04ab..618408c2 100644 --- a/web-example.html +++ b/web-example.html @@ -134,7 +134,7 @@

Test

const data = await fetch( // "https://lottie.host/5c89381e-0d1a-4422-8247-f5b7e4b3c4e2/mqs5juC4PW.lottie" - "./examples/demo-player/src/theming_example.lottie" + "./examples/demo-player/src/v2/bull.lottie" // "https://lottie.host/294b684d-d6b4-4116-ab35-85ef566d4379/VkGHcqcMUI.lottie", // "https://lottie.host/edff17eb-9a84-41f7-810a-22b94fbf9143/uYveqJ1Kqn.lottie" ).then((res) => res.arrayBuffer());