Skip to content

Commit

Permalink
refactor: changed animationId to animation, removed descriptor, only …
Browse files Browse the repository at this point in the history
…initial stays (#281)

* refactor: changed animationId to animation, removed descriptor, only inital

* fix: updated udl files
  • Loading branch information
samuelOsborne authored Jan 9, 2025
1 parent 1b57aa9 commit 7cee3ac
Show file tree
Hide file tree
Showing 33 changed files with 3,313 additions and 3,372 deletions.
1 change: 1 addition & 0 deletions dotlottie-ffi/src/dotlottie_player.udl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface StateMachineObserver {
void on_transition(string previous_state, string new_state);
void on_state_entered(string entering_state);
void on_state_exit(string leaving_state);
void on_custom_event(string message);
};

enum Mode {
Expand Down
8 changes: 8 additions & 0 deletions dotlottie-ffi/src/ffi/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,14 @@ impl dotlottie_rs::StateMachineObserver for StateMachineObserver {
}
}
}

fn on_custom_event(&self, message: String) {
if let Ok(message) = CString::new(message) {
unsafe {
(self.on_state_exit_op)(message.as_bytes_with_nul().as_ptr() as *const c_char)
}
}
}
}

impl StateMachineObserver {
Expand Down
8 changes: 4 additions & 4 deletions dotlottie-rs/src/state_machine_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl StateMachineEngine {

match parsed_state_machine {
Ok(parsed_state_machine) => {
let initial_state_index = parsed_state_machine.descriptor.initial.clone();
let initial_state_index = parsed_state_machine.initial.clone();

/* Build all trigger variables into hashmaps for easier use */
if let Some(triggers) = &parsed_state_machine.triggers {
Expand Down Expand Up @@ -926,10 +926,10 @@ impl StateMachineEngine {
// | PointerUp (No Layer) | PointerUp | PointerUp |
// | PointerUp (With Layer) | PointerUp | PointerUp |
// | PointerMove (No Layer) | PointerMove | PointerDown |
// | PointerEnter (No Layer) | PointerEnter | |
// | PointerEnter (No Layer) | PointerEnter | Not avail. |
// | PointerEnter (With Layer) | PointerMove + PointerEnter | PointerDown |
// | PointerExit (No Layer) | PointerExit | PointerUp |
// | PointerExit (With Layer) | PointerMove + PointerExit | |
// | PointerExit (No Layer) | PointerExit | Not avail. |
// | PointerExit (With Layer) | PointerMove + PointerExit | PointerUp |
// | ---------------------------------|-------------------------------| ----------- |

// Notes:
Expand Down
17 changes: 4 additions & 13 deletions dotlottie-rs/src/state_machine_engine/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,23 @@ pub enum StringNumber {
F32(f32),
}

#[derive(Deserialize, Debug)]
pub struct Descriptor {
pub id: String,
pub initial: String,
}

#[derive(Deserialize, Debug)]
pub struct StateMachine {
pub descriptor: Descriptor,
pub initial: String,
pub states: Vec<State>,
pub listeners: Option<Vec<Listener>>,
pub triggers: Option<Vec<Trigger>>,
}

impl StateMachine {
pub fn new(
descriptor: Descriptor,
initial: String,
states: Vec<State>,
listeners: Option<Vec<Listener>>,
triggers: Option<Vec<Trigger>>,
) -> Self {
StateMachine {
descriptor,
initial,
states,
listeners,
triggers,
Expand All @@ -79,10 +73,7 @@ impl StateMachine {
impl Default for StateMachine {
fn default() -> Self {
StateMachine {
descriptor: Descriptor {
id: "".to_string(),
initial: "".to_string(),
},
initial: "".to_string(),
states: Vec::new(),
listeners: None,
triggers: None,
Expand Down
21 changes: 10 additions & 11 deletions dotlottie-rs/src/state_machine_engine/states/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub trait StateTrait {
engine: &mut StateMachineEngine,
player: &Rc<RwLock<DotLottiePlayerContainer>>,
) -> Result<(), StateMachineActionError>;
fn animation_id(&self) -> &str;
fn animation(&self) -> &str;
fn transitions(&self) -> &Vec<Transition>;
fn entry_actions(&self) -> Option<&Vec<Action>>;
fn exit_actions(&self) -> Option<&Vec<Action>>;
Expand All @@ -40,7 +40,7 @@ pub enum State {
PlaybackState {
name: String,
transitions: Vec<Transition>,
animation_id: String,
animation: String,
r#loop: Option<bool>,
autoplay: Option<bool>,
mode: Option<String>,
Expand All @@ -54,7 +54,7 @@ pub enum State {
GlobalState {
name: String,
transitions: Vec<Transition>,
animation_id: Option<String>,
animation: Option<String>,
entry_actions: Option<Vec<Action>>,
exit_actions: Option<Vec<Action>>,
},
Expand All @@ -74,7 +74,7 @@ impl StateTrait for State {
) -> i32 {
match self {
State::PlaybackState {
animation_id,
animation,
r#loop,
autoplay,
mode,
Expand Down Expand Up @@ -121,9 +121,8 @@ impl StateTrait for State {
let size = player_read.size();

// Todo compare against currently loaded animation
if !animation_id.is_empty() && player_read.active_animation_id() != *animation_id
{
player_read.load_animation(animation_id, size.0, size.1);
if !animation.is_empty() && player_read.active_animation_id() != *animation {
player_read.load_animation(animation, size.0, size.1);
}

player_read.set_config(playback_config);
Expand All @@ -150,15 +149,15 @@ impl StateTrait for State {
}

State::GlobalState {
animation_id,
animation,
entry_actions,
..
} => {
if let Ok(player_read) = player.try_read() {
let size = player_read.size();

// Todo compare against currently loaded animation
if let Some(id) = animation_id {
if let Some(id) = animation {
player_read.load_animation(id, size.0, size.1);

// Perform entry actions
Expand All @@ -175,9 +174,9 @@ impl StateTrait for State {
0
}

fn animation_id(&self) -> &str {
fn animation(&self) -> &str {
match self {
State::PlaybackState { animation_id, .. } => animation_id,
State::PlaybackState { animation, .. } => animation,
State::GlobalState { .. } => "",
}
}
Expand Down
Loading

0 comments on commit 7cee3ac

Please sign in to comment.