From 7cee3ac73c7f6bc3eb2a6b17ad0b641b9f7822e8 Mon Sep 17 00:00:00 2001 From: SamuelOsborne Date: Thu, 9 Jan 2025 11:00:13 +0100 Subject: [PATCH] refactor: changed animationId to animation, removed descriptor, only initial stays (#281) * refactor: changed animationId to animation, removed descriptor, only inital * fix: updated udl files --- dotlottie-ffi/src/dotlottie_player.udl | 1 + dotlottie-ffi/src/ffi/types.rs | 8 + dotlottie-rs/src/state_machine_engine/mod.rs | 8 +- .../state_machine_engine/state_machine/mod.rs | 17 +- .../src/state_machine_engine/states/mod.rs | 21 +- .../action_tests/decr_rating.json | 405 ++++++++------- .../statemachines/action_tests/fire.json | 149 +++--- .../action_tests/fire_custom_event.json | 443 ++++++++-------- .../action_tests/inc_rating.json | 405 ++++++++------- .../statemachines/action_tests/reset.json | 305 ++++++----- .../statemachines/action_tests/set_frame.json | 133 +++-- .../action_tests/set_progress.json | 133 +++-- .../action_tests/set_triggers.json | 295 ++++++----- .../statemachines/action_tests/toggle.json | 149 +++--- .../guard_tests/equal_not_equal.json | 155 +++--- .../guard_tests/greater_than.json | 231 +++++---- .../guard_tests/greater_than_equal.json | 231 +++++---- .../statemachines/guard_tests/less_than.json | 189 ++++--- .../guard_tests/less_than_equal.json | 189 ++++--- .../listener_tests/on_complete.json | 303 ++++++----- .../listener_tests/pigeon_fsm.json | 201 ++++---- .../listener_tests/pointer_down.json | 243 +++++---- .../listener_tests/pointer_down_up.json | 395 +++++++------- .../listener_tests/pointer_enter.json | 361 +++++++------ .../listener_tests/pointer_exit.json | 483 +++++++++--------- .../listener_tests/pointer_move.json | 241 +++++---- .../test_global_and_guardless.json | 167 +++--- .../test_guarded_and_guardless.json | 215 ++++---- .../test_guardless_and_event.json | 179 ++++--- .../security_tests/compare_to.json | 149 +++--- .../security_tests/event_guards.json | 141 +++-- .../security_tests/guardless_transitions.json | 103 ++-- .../src/bin/new-format/new-format.rs | 37 +- 33 files changed, 3313 insertions(+), 3372 deletions(-) diff --git a/dotlottie-ffi/src/dotlottie_player.udl b/dotlottie-ffi/src/dotlottie_player.udl index c716566f..f9f22965 100644 --- a/dotlottie-ffi/src/dotlottie_player.udl +++ b/dotlottie-ffi/src/dotlottie_player.udl @@ -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 { diff --git a/dotlottie-ffi/src/ffi/types.rs b/dotlottie-ffi/src/ffi/types.rs index 0b283511..07b2efe6 100644 --- a/dotlottie-ffi/src/ffi/types.rs +++ b/dotlottie-ffi/src/ffi/types.rs @@ -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 { diff --git a/dotlottie-rs/src/state_machine_engine/mod.rs b/dotlottie-rs/src/state_machine_engine/mod.rs index 10e38573..2d1e2a46 100644 --- a/dotlottie-rs/src/state_machine_engine/mod.rs +++ b/dotlottie-rs/src/state_machine_engine/mod.rs @@ -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 { @@ -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: diff --git a/dotlottie-rs/src/state_machine_engine/state_machine/mod.rs b/dotlottie-rs/src/state_machine_engine/state_machine/mod.rs index a1a72d63..4f009605 100644 --- a/dotlottie-rs/src/state_machine_engine/state_machine/mod.rs +++ b/dotlottie-rs/src/state_machine_engine/state_machine/mod.rs @@ -30,15 +30,9 @@ 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, pub listeners: Option>, pub triggers: Option>, @@ -46,13 +40,13 @@ pub struct StateMachine { impl StateMachine { pub fn new( - descriptor: Descriptor, + initial: String, states: Vec, listeners: Option>, triggers: Option>, ) -> Self { StateMachine { - descriptor, + initial, states, listeners, triggers, @@ -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, diff --git a/dotlottie-rs/src/state_machine_engine/states/mod.rs b/dotlottie-rs/src/state_machine_engine/states/mod.rs index 52b5043c..3669b6b3 100644 --- a/dotlottie-rs/src/state_machine_engine/states/mod.rs +++ b/dotlottie-rs/src/state_machine_engine/states/mod.rs @@ -25,7 +25,7 @@ pub trait StateTrait { engine: &mut StateMachineEngine, player: &Rc>, ) -> Result<(), StateMachineActionError>; - fn animation_id(&self) -> &str; + fn animation(&self) -> &str; fn transitions(&self) -> &Vec; fn entry_actions(&self) -> Option<&Vec>; fn exit_actions(&self) -> Option<&Vec>; @@ -40,7 +40,7 @@ pub enum State { PlaybackState { name: String, transitions: Vec, - animation_id: String, + animation: String, r#loop: Option, autoplay: Option, mode: Option, @@ -54,7 +54,7 @@ pub enum State { GlobalState { name: String, transitions: Vec, - animation_id: Option, + animation: Option, entry_actions: Option>, exit_actions: Option>, }, @@ -74,7 +74,7 @@ impl StateTrait for State { ) -> i32 { match self { State::PlaybackState { - animation_id, + animation, r#loop, autoplay, mode, @@ -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); @@ -150,7 +149,7 @@ impl StateTrait for State { } State::GlobalState { - animation_id, + animation, entry_actions, .. } => { @@ -158,7 +157,7 @@ impl StateTrait for State { 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 @@ -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 { .. } => "", } } diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/decr_rating.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/decr_rating.json index 514a4580..f2cddab5 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/decr_rating.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/decr_rating.json @@ -1,226 +1,223 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ + "initial": "global", + "states": [ + { + "name": "global", + "animation": "", + "type": "GlobalState", + "transitions": [ { - "name": "global", - "animationId": "", - "type": "GlobalState", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - }, - { - "type": "Transition", - "toState": "star_6", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 6 - } - ] - }, - { - "type": "Transition", - "toState": "star_12", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 12 - } - ] - }, - { - "type": "Transition", - "toState": "star_13", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 13 - } - ] - }, - { - "type": "Transition", - "toState": "star_14", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 14 - } - ] - } - ] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "animationId": "", - "name": "star_1", - "autoplay": true, - "segment": "star_1", - "transitions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "animationId": "", - "name": "star_2", - "autoplay": true, - "segment": "star_2", - "transitions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "animationId": "", - "name": "star_3", - "autoplay": true, - "segment": "star_3", - "transitions": [], - "entryActions": [ - { - "type": "Decrement", - "triggerName": "rating", - "value": 2.0 - } - ] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "animationId": "", - "name": "star_4", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] }, { - "type": "PlaybackState", - "animationId": "", - "name": "star_5", - "autoplay": true, - "segment": "star_5", - "transitions": [], - "entryActions": [ - { - "type": "Decrement", - "triggerName": "rating" - } - ] + "type": "Transition", + "toState": "star_6", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 6 + } + ] }, { - "type": "PlaybackState", - "name": "star_6", - "animationId": "", - "autoplay": true, - "transitions": [], - "entryActions": [ - { - "type": "Decrement", - "triggerName": "rating", - "value": "$rating" - } - ] + "type": "Transition", + "toState": "star_12", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 12 + } + ] }, { - "type": "PlaybackState", - "name": "star_12", - "animationId": "", - "autoplay": true, - "transitions": [] + "type": "Transition", + "toState": "star_13", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 13 + } + ] }, { - "type": "PlaybackState", - "name": "star_13", - "animationId": "", - "autoplay": true, - "transitions": [], - "entryActions": [ - { - "type": "Decrement", - "triggerName": "rating", - "value": "$badTriggerName" - } - ] - }, + "type": "Transition", + "toState": "star_14", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 14 + } + ] + } + ] + }, + { + "type": "PlaybackState", + "animation": "", + "name": "star_1", + "autoplay": true, + "segment": "star_1", + "transitions": [] + }, + { + "type": "PlaybackState", + "animation": "", + "name": "star_2", + "autoplay": true, + "segment": "star_2", + "transitions": [] + }, + { + "type": "PlaybackState", + "animation": "", + "name": "star_3", + "autoplay": true, + "segment": "star_3", + "transitions": [], + "entryActions": [ + { + "type": "Decrement", + "triggerName": "rating", + "value": 2.0 + } + ] + }, + { + "type": "PlaybackState", + "animation": "", + "name": "star_4", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "type": "PlaybackState", + "animation": "", + "name": "star_5", + "autoplay": true, + "segment": "star_5", + "transitions": [], + "entryActions": [ + { + "type": "Decrement", + "triggerName": "rating" + } + ] + }, + { + "type": "PlaybackState", + "name": "star_6", + "animation": "", + "autoplay": true, + "transitions": [], + "entryActions": [ { - "type": "PlaybackState", - "name": "star_14", - "animationId": "", - "autoplay": true, - "transitions": [] + "type": "Decrement", + "triggerName": "rating", + "value": "$rating" } - ], - "listeners": [], - "triggers": [ + ] + }, + { + "type": "PlaybackState", + "name": "star_12", + "animation": "", + "autoplay": true, + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_13", + "animation": "", + "autoplay": true, + "transitions": [], + "entryActions": [ { - "type": "Numeric", - "name": "rating", - "value": 0.0 + "type": "Decrement", + "triggerName": "rating", + "value": "$badTriggerName" } - ] -} \ No newline at end of file + ] + }, + { + "type": "PlaybackState", + "name": "star_14", + "animation": "", + "autoplay": true, + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0.0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/fire.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/fire.json index fa456d83..4b6a9749 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/fire.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/fire.json @@ -1,85 +1,82 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "c", - "guards": [ - { - "type": "Event", - "triggerName": "Step" - } - ] - }, - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": true - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": false - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "name": "a", - "type": "PlaybackState", - "animationId": "", - "transitions": [], - "entryActions": [ - { - "type": "Fire", - "triggerName": "Step" - } - ] + "type": "Transition", + "toState": "c", + "guards": [ + { + "type": "Event", + "triggerName": "Step" + } + ] }, { - "name": "b", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": true + } + ] }, { - "name": "c", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": false + } + ] } - ], - "listeners": [], - "triggers": [ - { - "type": "Boolean", - "name": "OnOffSwitch", - "value": false - }, + ] + }, + { + "name": "a", + "type": "PlaybackState", + "animation": "", + "transitions": [], + "entryActions": [ { - "type": "Event", - "name": "Step" + "type": "Fire", + "triggerName": "Step" } - ] -} \ No newline at end of file + ] + }, + { + "name": "b", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "c", + "type": "PlaybackState", + "animation": "", + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Boolean", + "name": "OnOffSwitch", + "value": false + }, + { + "type": "Event", + "name": "Step" + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/fire_custom_event.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/fire_custom_event.json index 52b9cf50..c98f88ba 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/fire_custom_event.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/fire_custom_event.json @@ -1,244 +1,241 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "star_0", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 0 - } - ] - }, - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "type": "PlaybackState", - "name": "star_0", - "animationId": "", - "autoplay": true, - "segment": "star_0", - "transitions": [], - "entryActions": [ - { - "type": "FireCustomEvent", - "value": "WOOHOO STAR 0" - } - ] + "type": "Transition", + "toState": "star_0", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 0 + } + ] }, { - "type": "PlaybackState", - "name": "star_1", - "animationId": "", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [ - { - "type": "FireCustomEvent", - "value": "WOOHOO STAR 1" - } - ] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "star_2", - "animationId": "", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [ - { - "type": "FireCustomEvent", - "value": "WOOHOO STAR 2" - } - ] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "name": "star_3", - "animationId": "", - "autoplay": true, - "segment": "star_3", - "transitions": [], - "entryActions": [ - { - "type": "FireCustomEvent", - "value": "WOOHOO STAR 3" - } - ] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "name": "star_4", - "animationId": "", - "autoplay": true, - "segment": "star_4", - "transitions": [], - "entryActions": [ - { - "type": "FireCustomEvent", - "value": "WOOHOO STAR 4" - } - ] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "name": "star_5", - "animationId": "", - "autoplay": true, - "segment": "star_5", - "transitions": [], - "entryActions": [ - { - "type": "FireCustomEvent", - "value": "WOOHOO STAR 5" - } - ] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] } - ], - "listeners": [ - { - "type": "PointerDown", - "layerName": "star1", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 1 - } - ] - }, + ] + }, + { + "type": "PlaybackState", + "name": "star_0", + "animation": "", + "autoplay": true, + "segment": "star_0", + "transitions": [], + "entryActions": [ { - "type": "PointerDown", - "layerName": "star2", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 2 - } - ] - }, + "type": "FireCustomEvent", + "value": "WOOHOO STAR 0" + } + ] + }, + { + "type": "PlaybackState", + "name": "star_1", + "animation": "", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [ { - "type": "PointerDown", - "layerName": "star3", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 3 - } - ] - }, + "type": "FireCustomEvent", + "value": "WOOHOO STAR 1" + } + ] + }, + { + "type": "PlaybackState", + "name": "star_2", + "animation": "", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [ { - "type": "PointerDown", - "layerName": "star4", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 4 - } - ] - }, + "type": "FireCustomEvent", + "value": "WOOHOO STAR 2" + } + ] + }, + { + "type": "PlaybackState", + "name": "star_3", + "animation": "", + "autoplay": true, + "segment": "star_3", + "transitions": [], + "entryActions": [ { - "type": "PointerDown", - "layerName": "star5", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 5 - } - ] - }, + "type": "FireCustomEvent", + "value": "WOOHOO STAR 3" + } + ] + }, + { + "type": "PlaybackState", + "name": "star_4", + "animation": "", + "autoplay": true, + "segment": "star_4", + "transitions": [], + "entryActions": [ + { + "type": "FireCustomEvent", + "value": "WOOHOO STAR 4" + } + ] + }, + { + "type": "PlaybackState", + "name": "star_5", + "animation": "", + "autoplay": true, + "segment": "star_5", + "transitions": [], + "entryActions": [ { - "type": "PointerExit", - "actions": [ - { - "type": "Reset", - "triggerName": "rating" - } - ] + "type": "FireCustomEvent", + "value": "WOOHOO STAR 5" } - ], - "triggers": [ + ] + } + ], + "listeners": [ + { + "type": "PointerDown", + "layerName": "star1", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 1 + } + ] + }, + { + "type": "PointerDown", + "layerName": "star2", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 2 + } + ] + }, + { + "type": "PointerDown", + "layerName": "star3", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 3 + } + ] + }, + { + "type": "PointerDown", + "layerName": "star4", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 4 + } + ] + }, + { + "type": "PointerDown", + "layerName": "star5", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 5 + } + ] + }, + { + "type": "PointerExit", + "actions": [ { - "type": "Numeric", - "name": "rating", - "value": 0 + "type": "Reset", + "triggerName": "rating" } - ] -} \ No newline at end of file + ] + } + ], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/inc_rating.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/inc_rating.json index 50395a9a..8883f69b 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/inc_rating.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/inc_rating.json @@ -1,226 +1,223 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ + "initial": "global", + "states": [ + { + "animation": "", + "name": "global", + "type": "GlobalState", + "transitions": [ { - "animationId": "", - "name": "global", - "type": "GlobalState", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - }, - { - "type": "Transition", - "toState": "star_6", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 6 - } - ] - }, - { - "type": "Transition", - "toState": "star_12", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 12 - } - ] - }, - { - "type": "Transition", - "toState": "star_13", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 13 - } - ] - }, - { - "type": "Transition", - "toState": "star_14", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 14 - } - ] - } - ] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_1", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [ - { - "type": "Increment", - "triggerName": "rating" - } - ] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_2", - "autoplay": true, - "segment": "star_2", - "transitions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_3", - "autoplay": true, - "segment": "star_3", - "transitions": [], - "entryActions": [ - { - "type": "Increment", - "triggerName": "rating", - "value": 2.0 - } - ] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_4", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_5", - "autoplay": true, - "segment": "star_5", - "transitions": [] + "type": "Transition", + "toState": "star_6", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 6 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_6", - "autoplay": true, - "transitions": [], - "entryActions": [ - { - "type": "Increment", - "triggerName": "rating", - "value": "$rating" - } - ] + "type": "Transition", + "toState": "star_12", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 12 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_12", - "autoplay": true, - "transitions": [] + "type": "Transition", + "toState": "star_13", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 13 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_13", - "autoplay": true, - "transitions": [], - "entryActions": [ - { - "type": "Increment", - "triggerName": "rating", - "value": "$badTriggerName" - } - ] - }, + "type": "Transition", + "toState": "star_14", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 14 + } + ] + } + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_1", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [ + { + "type": "Increment", + "triggerName": "rating" + } + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_2", + "autoplay": true, + "segment": "star_2", + "transitions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_3", + "autoplay": true, + "segment": "star_3", + "transitions": [], + "entryActions": [ { - "animationId": "", - "type": "PlaybackState", - "name": "star_14", - "autoplay": true, - "transitions": [] + "type": "Increment", + "triggerName": "rating", + "value": 2.0 } - ], - "listeners": [], - "triggers": [ + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_4", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_5", + "autoplay": true, + "segment": "star_5", + "transitions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_6", + "autoplay": true, + "transitions": [], + "entryActions": [ + { + "type": "Increment", + "triggerName": "rating", + "value": "$rating" + } + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_12", + "autoplay": true, + "transitions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_13", + "autoplay": true, + "transitions": [], + "entryActions": [ { - "type": "Numeric", - "name": "rating", - "value": 0.0 + "type": "Increment", + "triggerName": "rating", + "value": "$badTriggerName" } - ] -} \ No newline at end of file + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_14", + "autoplay": true, + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0.0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/reset.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/reset.json index 43425cd9..f13fa5d3 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/reset.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/reset.json @@ -1,171 +1,168 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "star_0", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 0 - } - ] - }, - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - }, - { - "type": "Transition", - "toState": "star_6", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 6 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "type": "PlaybackState", - "name": "star_0", - "animationId": "", - "autoplay": true, - "segment": "star_0", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_0", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 0 + } + ] }, { - "type": "PlaybackState", - "name": "star_1", - "animationId": "", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "star_2", - "animationId": "", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "name": "star_3", - "animationId": "", - "autoplay": true, - "segment": "star_3", - "transitions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "name": "star_4", - "animationId": "", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "name": "star_5", - "animationId": "", - "autoplay": true, - "segment": "star_5", - "transitions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] }, { - "type": "PlaybackState", - "name": "star_6", - "animationId": "", - "autoplay": true, - "transitions": [], - "entryActions": [ - { - "type": "Reset", - "triggerName": "rating" - } - ] + "type": "Transition", + "toState": "star_6", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 6 + } + ] } - ], - "listeners": [], - "triggers": [ + ] + }, + { + "type": "PlaybackState", + "name": "star_0", + "animation": "", + "autoplay": true, + "segment": "star_0", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_1", + "animation": "", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_2", + "animation": "", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_3", + "animation": "", + "autoplay": true, + "segment": "star_3", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_4", + "animation": "", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_5", + "animation": "", + "autoplay": true, + "segment": "star_5", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_6", + "animation": "", + "autoplay": true, + "transitions": [], + "entryActions": [ { - "type": "Numeric", - "name": "rating", - "value": 0 + "type": "Reset", + "triggerName": "rating" } - ] -} \ No newline at end of file + ] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_frame.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_frame.json index e684e234..0dfaf590 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_frame.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_frame.json @@ -1,76 +1,73 @@ { - "descriptor": { - "id": "starRating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": true - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": false - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "name": "a", - "type": "PlaybackState", - "animationId": "", - "transitions": [], - "entryActions": [ - { - "type": "SetFrame", - "value": 10 - } - ] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": true + } + ] }, { - "name": "b", - "type": "PlaybackState", - "animationId": "", - "transitions": [], - "entryActions": [ - { - "type": "SetFrame", - "value": "$frameHolder" - } - ] + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": false + } + ] } - ], - "listeners": [], - "triggers": [ + ] + }, + { + "name": "a", + "type": "PlaybackState", + "animation": "", + "transitions": [], + "entryActions": [ { - "type": "Boolean", - "name": "OnOffSwitch", - "value": false - }, + "type": "SetFrame", + "value": 10 + } + ] + }, + { + "name": "b", + "type": "PlaybackState", + "animation": "", + "transitions": [], + "entryActions": [ { - "type": "Numeric", - "name": "frameHolder", - "value": 35 + "type": "SetFrame", + "value": "$frameHolder" } - ] -} \ No newline at end of file + ] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Boolean", + "name": "OnOffSwitch", + "value": false + }, + { + "type": "Numeric", + "name": "frameHolder", + "value": 35 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_progress.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_progress.json index 7025c633..314f7393 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_progress.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_progress.json @@ -1,76 +1,73 @@ { - "descriptor": { - "id": "starRating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": true - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": false - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "name": "a", - "type": "PlaybackState", - "animationId": "", - "transitions": [], - "entryActions": [ - { - "type": "SetProgress", - "value": 10 - } - ] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": true + } + ] }, { - "name": "b", - "type": "PlaybackState", - "animationId": "", - "transitions": [], - "entryActions": [ - { - "type": "SetProgress", - "value": "$frameHolder" - } - ] + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": false + } + ] } - ], - "listeners": [], - "triggers": [ + ] + }, + { + "name": "a", + "type": "PlaybackState", + "animation": "", + "transitions": [], + "entryActions": [ { - "type": "Boolean", - "name": "OnOffSwitch", - "value": false - }, + "type": "SetProgress", + "value": 10 + } + ] + }, + { + "name": "b", + "type": "PlaybackState", + "animation": "", + "transitions": [], + "entryActions": [ { - "type": "Numeric", - "name": "frameHolder", - "value": 75 + "type": "SetProgress", + "value": "$frameHolder" } - ] -} \ No newline at end of file + ] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Boolean", + "name": "OnOffSwitch", + "value": false + }, + { + "type": "Numeric", + "name": "frameHolder", + "value": 75 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_triggers.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_triggers.json index c0d6d6b4..d4efcc2c 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_triggers.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/set_triggers.json @@ -1,167 +1,164 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "e", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "NumericTrigger", - "compareTo": 10.0 - } - ] - }, - { - "type": "Transition", - "toState": "d", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "NumericTrigger", - "compareTo": 20.0 - } - ] - }, - { - "type": "Transition", - "toState": "f", - "guards": [ - { - "type": "String", - "conditionType": "Equal", - "triggerName": "StringTrigger", - "compareTo": "second" - } - ] - }, - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": true - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": false - } - ] - }, - { - "type": "Transition", - "toState": "c", - "guards": [ - { - "type": "Event", - "triggerName": "Step" - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "name": "a", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "e", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "NumericTrigger", + "compareTo": 10.0 + } + ] }, { - "name": "b", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "d", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "NumericTrigger", + "compareTo": 20.0 + } + ] }, { - "name": "c", - "type": "PlaybackState", - "animationId": "", - "transitions": [], - "entryActions": [ - { - "type": "SetBoolean", - "triggerName": "OnOffSwitch", - "value": true - } - ] + "type": "Transition", + "toState": "f", + "guards": [ + { + "type": "String", + "conditionType": "Equal", + "triggerName": "StringTrigger", + "compareTo": "second" + } + ] }, { - "name": "d", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": true + } + ] }, { - "name": "e", - "type": "PlaybackState", - "animationId": "", - "transitions": [], - "entryActions": [ - { - "type": "SetNumeric", - "triggerName": "NumericTrigger", - "value": 20 - }, - { - "type": "SetString", - "triggerName": "StringTrigger", - "value": "second" - } - ] + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": false + } + ] }, { - "name": "f", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "c", + "guards": [ + { + "type": "Event", + "triggerName": "Step" + } + ] } - ], - "listeners": [], - "triggers": [ - { - "type": "Boolean", - "name": "OnOffSwitch", - "value": false - }, - { - "type": "Event", - "name": "Step" - }, + ] + }, + { + "name": "a", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "b", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "c", + "type": "PlaybackState", + "animation": "", + "transitions": [], + "entryActions": [ { - "type": "Numeric", - "name": "NumericTrigger", - "value": 0 - }, + "type": "SetBoolean", + "triggerName": "OnOffSwitch", + "value": true + } + ] + }, + { + "name": "d", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "e", + "type": "PlaybackState", + "animation": "", + "transitions": [], + "entryActions": [ { - "type": "Numeric", - "name": "NumericTrigger", - "value": 0 + "type": "SetNumeric", + "triggerName": "NumericTrigger", + "value": 20 }, { - "type": "String", - "name": "StringTrigger", - "value": "first" + "type": "SetString", + "triggerName": "StringTrigger", + "value": "second" } - ] -} \ No newline at end of file + ] + }, + { + "name": "f", + "type": "PlaybackState", + "animation": "", + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Boolean", + "name": "OnOffSwitch", + "value": false + }, + { + "type": "Event", + "name": "Step" + }, + { + "type": "Numeric", + "name": "NumericTrigger", + "value": 0 + }, + { + "type": "Numeric", + "name": "NumericTrigger", + "value": 0 + }, + { + "type": "String", + "name": "StringTrigger", + "value": "first" + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/action_tests/toggle.json b/dotlottie-rs/tests/fixtures/statemachines/action_tests/toggle.json index 1e890c10..06d0840e 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/action_tests/toggle.json +++ b/dotlottie-rs/tests/fixtures/statemachines/action_tests/toggle.json @@ -1,85 +1,82 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "animationId": "", - "name": "global", - "type": "GlobalState", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": true - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": false - } - ] - }, - { - "type": "Transition", - "toState": "c", - "guards": [ - { - "type": "Event", - "triggerName": "Step" - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "animation": "", + "name": "global", + "type": "GlobalState", + "transitions": [ { - "name": "a", - "animationId": "", - "type": "PlaybackState", - "transitions": [] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": true + } + ] }, { - "name": "b", - "animationId": "", - "type": "PlaybackState", - "transitions": [] + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": false + } + ] }, { - "name": "c", - "animationId": "", - "type": "PlaybackState", - "transitions": [], - "entryActions": [ - { - "type": "Toggle", - "triggerName": "OnOffSwitch" - } - ] + "type": "Transition", + "toState": "c", + "guards": [ + { + "type": "Event", + "triggerName": "Step" + } + ] } - ], - "listeners": [], - "triggers": [ - { - "type": "Boolean", - "name": "OnOffSwitch", - "value": false - }, + ] + }, + { + "name": "a", + "animation": "", + "type": "PlaybackState", + "transitions": [] + }, + { + "name": "b", + "animation": "", + "type": "PlaybackState", + "transitions": [] + }, + { + "name": "c", + "animation": "", + "type": "PlaybackState", + "transitions": [], + "entryActions": [ { - "type": "Event", - "name": "Step" + "type": "Toggle", + "triggerName": "OnOffSwitch" } - ] -} \ No newline at end of file + ] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Boolean", + "name": "OnOffSwitch", + "value": false + }, + { + "type": "Event", + "name": "Step" + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/equal_not_equal.json b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/equal_not_equal.json index 8367a767..2db4ee4e 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/equal_not_equal.json +++ b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/equal_not_equal.json @@ -1,86 +1,83 @@ { - "descriptor": { - "id": "not-equal", - "initial": "global" - }, - "states": [ - { - "animationId": "", - "name": "global", - "type": "GlobalState", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "NotEqual", - "triggerName": "rating", - "compareTo": 2.0 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "animation": "", + "name": "global", + "type": "GlobalState", + "transitions": [ { - "animationId": "", - "type": "PlaybackState", - "name": "star_1", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_2", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_5", - "autoplay": true, - "segment": "star_5", - "transitions": [], - "entryActions": [] - } - ], - "listeners": [], - "triggers": [ - { - "type": "Numeric", - "name": "rating", - "value": 2.0 + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "NotEqual", + "triggerName": "rating", + "compareTo": 2.0 + } + ] } - ] -} \ No newline at end of file + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_1", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_2", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_5", + "autoplay": true, + "segment": "star_5", + "transitions": [], + "entryActions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 2.0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/greater_than.json b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/greater_than.json index 5b64d299..9faf0f62 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/greater_than.json +++ b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/greater_than.json @@ -1,128 +1,125 @@ { - "descriptor": { - "id": "not-equal", - "initial": "global" - }, - "states": [ - { - "animationId": "", - "name": "global", - "type": "GlobalState", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "GreaterThan", - "triggerName": "rating", - "compareTo": 2.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5.0 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "animation": "", + "name": "global", + "type": "GlobalState", + "transitions": [ { - "animationId": "", - "type": "PlaybackState", - "name": "star_1", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_2", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "GreaterThan", + "triggerName": "rating", + "compareTo": 2.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_3", - "autoplay": true, - "segment": "star_3", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_4", - "autoplay": true, - "segment": "star_4", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_5", - "autoplay": true, - "segment": "star_5", - "transitions": [], - "entry_actions": [] - } - ], - "listeners": [], - "triggers": [ - { - "type": "Numeric", - "name": "rating", - "value": 0.0 + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5.0 + } + ] } - ] -} \ No newline at end of file + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_1", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_2", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_3", + "autoplay": true, + "segment": "star_3", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_4", + "autoplay": true, + "segment": "star_4", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_5", + "autoplay": true, + "segment": "star_5", + "transitions": [], + "entry_actions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0.0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/greater_than_equal.json b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/greater_than_equal.json index cccfd3d5..af84219a 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/greater_than_equal.json +++ b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/greater_than_equal.json @@ -1,128 +1,125 @@ { - "descriptor": { - "id": "not-equal", - "initial": "global" - }, - "states": [ - { - "animationId": "", - "name": "global", - "type": "GlobalState", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "GreaterThanOrEqual", - "triggerName": "rating", - "compareTo": 2.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5.0 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "animation": "", + "name": "global", + "type": "GlobalState", + "transitions": [ { - "animationId": "", - "type": "PlaybackState", - "name": "star_1", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_2", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "GreaterThanOrEqual", + "triggerName": "rating", + "compareTo": 2.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_3", - "autoplay": true, - "segment": "star_3", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_4", - "autoplay": true, - "segment": "star_4", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_5", - "autoplay": true, - "segment": "star_5", - "transitions": [], - "entry_actions": [] - } - ], - "listeners": [], - "triggers": [ - { - "type": "Numeric", - "name": "rating", - "value": 0.0 + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5.0 + } + ] } - ] -} \ No newline at end of file + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_1", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_2", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_3", + "autoplay": true, + "segment": "star_3", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_4", + "autoplay": true, + "segment": "star_4", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_5", + "autoplay": true, + "segment": "star_5", + "transitions": [], + "entry_actions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0.0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/less_than.json b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/less_than.json index 6629eb89..3d6eb07b 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/less_than.json +++ b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/less_than.json @@ -1,103 +1,100 @@ { - "descriptor": { - "id": "not-equal", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "transitions": [ - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "LessThan", - "triggerName": "rating", - "compareTo": 3.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5.0 - } - ] - } - ] - }, - { - "animationId": "", - "type": "PlaybackState", - "name": "star_1", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entry_actions": [] - }, - { - "animationId": "", - "type": "PlaybackState", - "name": "star_2", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entry_actions": [] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "transitions": [ { - "animationId": "", - "type": "PlaybackState", - "name": "star_3", - "autoplay": true, - "segment": "star_3", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "LessThan", + "triggerName": "rating", + "compareTo": 3.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_4", - "autoplay": true, - "segment": "star_4", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_5", - "autoplay": true, - "segment": "star_5", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5.0 + } + ] } - ], - "listeners": [], - "triggers": [ - { - "type": "Numeric", - "name": "rating", - "value": 0.0 - } - ] -} \ No newline at end of file + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_1", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_2", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_3", + "autoplay": true, + "segment": "star_3", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_4", + "autoplay": true, + "segment": "star_4", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_5", + "autoplay": true, + "segment": "star_5", + "transitions": [], + "entry_actions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0.0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/less_than_equal.json b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/less_than_equal.json index b01d6199..df288c1e 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/guard_tests/less_than_equal.json +++ b/dotlottie-rs/tests/fixtures/statemachines/guard_tests/less_than_equal.json @@ -1,103 +1,100 @@ { - "descriptor": { - "id": "not-equal", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "transitions": [ - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "LessThanOrEqual", - "triggerName": "rating", - "compareTo": 3.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4.0 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5.0 - } - ] - } - ] - }, - { - "animationId": "", - "type": "PlaybackState", - "name": "star_1", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entry_actions": [] - }, - { - "animationId": "", - "type": "PlaybackState", - "name": "star_2", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entry_actions": [] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "transitions": [ { - "animationId": "", - "type": "PlaybackState", - "name": "star_3", - "autoplay": true, - "segment": "star_3", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "LessThanOrEqual", + "triggerName": "rating", + "compareTo": 3.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_4", - "autoplay": true, - "segment": "star_4", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4.0 + } + ] }, { - "animationId": "", - "type": "PlaybackState", - "name": "star_5", - "autoplay": true, - "segment": "star_5", - "transitions": [], - "entry_actions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5.0 + } + ] } - ], - "listeners": [], - "triggers": [ - { - "type": "Numeric", - "name": "rating", - "value": 0.0 - } - ] -} \ No newline at end of file + ] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_1", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_2", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_3", + "autoplay": true, + "segment": "star_3", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_4", + "autoplay": true, + "segment": "star_4", + "transitions": [], + "entry_actions": [] + }, + { + "animation": "", + "type": "PlaybackState", + "name": "star_5", + "autoplay": true, + "segment": "star_5", + "transitions": [], + "entry_actions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0.0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/on_complete.json b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/on_complete.json index f95adb6f..980a7fd4 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/on_complete.json +++ b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/on_complete.json @@ -1,170 +1,167 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "type": "PlaybackState", - "name": "star_1", - "animationId": "", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "star_2", - "animationId": "", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "name": "star_3", - "animationId": "", - "autoplay": true, - "segment": "star_3", - "transitions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "name": "star_4", - "animationId": "", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "name": "star_5", - "animationId": "", - "autoplay": true, - "segment": "star_5", - "transitions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] } - ], - "listeners": [ - { - "type": "OnComplete", - "stateName": "global", - "actions": [ - { - "type": "Increment", - "triggerName": "rating", - "value": 1 - } - ] - }, + ] + }, + { + "type": "PlaybackState", + "name": "star_1", + "animation": "", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_2", + "animation": "", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_3", + "animation": "", + "autoplay": true, + "segment": "star_3", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_4", + "animation": "", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_5", + "animation": "", + "autoplay": true, + "segment": "star_5", + "transitions": [] + } + ], + "listeners": [ + { + "type": "OnComplete", + "stateName": "global", + "actions": [ { - "type": "OnComplete", - "stateName": "star_1", - "actions": [ - { - "type": "Increment", - "triggerName": "rating", - "value": 1 - } - ] - }, + "type": "Increment", + "triggerName": "rating", + "value": 1 + } + ] + }, + { + "type": "OnComplete", + "stateName": "star_1", + "actions": [ { - "type": "OnComplete", - "stateName": "star_2", - "actions": [ - { - "type": "Increment", - "triggerName": "rating", - "value": 1 - } - ] - }, + "type": "Increment", + "triggerName": "rating", + "value": 1 + } + ] + }, + { + "type": "OnComplete", + "stateName": "star_2", + "actions": [ { - "type": "OnComplete", - "stateName": "star_3", - "actions": [ - { - "type": "Increment", - "triggerName": "rating", - "value": 1 - } - ] + "type": "Increment", + "triggerName": "rating", + "value": 1 } - ], - "triggers": [ + ] + }, + { + "type": "OnComplete", + "stateName": "star_3", + "actions": [ { - "type": "Numeric", - "name": "rating", - "value": 0 + "type": "Increment", + "triggerName": "rating", + "value": 1 } - ] -} \ No newline at end of file + ] + } + ], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pigeon_fsm.json b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pigeon_fsm.json index a5a9fe40..42a94464 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pigeon_fsm.json +++ b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pigeon_fsm.json @@ -1,112 +1,109 @@ { - "descriptor": { - "id": "explodingPigeon", - "initial": "pigeonRunning" - }, - "states": [ - { - "type": "PlaybackState", - "name": "pigeonRunning", - "animationId": "", - "loop": true, - "autoplay": true, - "segment": "bird", - "transitions": [ - { - "type": "Transition", - "toState": "explosion", - "guards": [ - { - "type": "Event", - "triggerName": "explode" - } - ] - } - ] - }, + "initial": "pigeonRunning", + "states": [ + { + "type": "PlaybackState", + "name": "pigeonRunning", + "animation": "", + "loop": true, + "autoplay": true, + "segment": "bird", + "transitions": [ { - "type": "PlaybackState", - "name": "explosion", - "animationId": "", - "loop": false, - "autoplay": true, - "segment": "explosion", - "transitions": [ - { - "type": "Transition", - "toState": "feathersFalling", - "guards": [ - { - "type": "Event", - "triggerName": "rainFeathers" - } - ] - } - ] - }, - { - "type": "PlaybackState", - "name": "feathersFalling", - "animationId": "", - "loop": false, - "autoplay": true, - "segment": "feathers", - "transitions": [ - { - "type": "Transition", - "toState": "pigeonRunning", - "guards": [ - { - "type": "Event", - "triggerName": "restart" - } - ] - } - ] + "type": "Transition", + "toState": "explosion", + "guards": [ + { + "type": "Event", + "triggerName": "explode" + } + ] } - ], - "listeners": [ - { - "type": "PointerDown", - "actions": [ - { - "type": "Fire", - "triggerName": "explode" - } - ] - }, + ] + }, + { + "type": "PlaybackState", + "name": "explosion", + "animation": "", + "loop": false, + "autoplay": true, + "segment": "explosion", + "transitions": [ { - "type": "OnComplete", - "stateName": "explosion", - "actions": [ - { - "type": "Fire", - "triggerName": "rainFeathers" - } - ] - }, + "type": "Transition", + "toState": "feathersFalling", + "guards": [ + { + "type": "Event", + "triggerName": "rainFeathers" + } + ] + } + ] + }, + { + "type": "PlaybackState", + "name": "feathersFalling", + "animation": "", + "loop": false, + "autoplay": true, + "segment": "feathers", + "transitions": [ { - "type": "PointerDown", - "actions": [ - { - "type": "Fire", - "triggerName": "restart" - } - ] + "type": "Transition", + "toState": "pigeonRunning", + "guards": [ + { + "type": "Event", + "triggerName": "restart" + } + ] } - ], - "triggers": [ + ] + } + ], + "listeners": [ + { + "type": "PointerDown", + "actions": [ { - "type": "Event", - "name": "explode" - }, + "type": "Fire", + "triggerName": "explode" + } + ] + }, + { + "type": "OnComplete", + "stateName": "explosion", + "actions": [ { - "type": "Event", - "name": "rainFeathers" - }, + "type": "Fire", + "triggerName": "rainFeathers" + } + ] + }, + { + "type": "PointerDown", + "actions": [ { - "type": "Event", - "name": "restart" + "type": "Fire", + "triggerName": "restart" } - ] -} \ No newline at end of file + ] + } + ], + "triggers": [ + { + "type": "Event", + "name": "explode" + }, + { + "type": "Event", + "name": "rainFeathers" + }, + { + "type": "Event", + "name": "restart" + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_down.json b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_down.json index 5f6c74d3..64509f37 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_down.json +++ b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_down.json @@ -1,136 +1,133 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "type": "PlaybackState", - "name": "star_1", - "animationId": "", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "star_2", - "animationId": "", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "name": "star_3", - "animationId": "", - "autoplay": true, - "segment": "star_3", - "transitions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "name": "star_4", - "animationId": "", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "name": "star_5", - "animationId": "", - "autoplay": true, - "segment": "star_5", - "transitions": [] - } - ], - "listeners": [ - { - "type": "PointerDown", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 4 - } - ] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] } - ], - "triggers": [ + ] + }, + { + "type": "PlaybackState", + "name": "star_1", + "animation": "", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_2", + "animation": "", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_3", + "animation": "", + "autoplay": true, + "segment": "star_3", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_4", + "animation": "", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_5", + "animation": "", + "autoplay": true, + "segment": "star_5", + "transitions": [] + } + ], + "listeners": [ + { + "type": "PointerDown", + "actions": [ { - "type": "Numeric", - "name": "rating", - "value": 0 + "type": "SetNumeric", + "triggerName": "rating", + "value": 4 } - ] -} \ No newline at end of file + ] + } + ], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_down_up.json b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_down_up.json index 8ddc5c42..427666f9 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_down_up.json +++ b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_down_up.json @@ -1,222 +1,219 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - }, - { - "type": "Transition", - "toState": "star_6", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 6 - } - ] - }, - { - "type": "Transition", - "toState": "star_6", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 6 - } - ] - } - ] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "star_1", - "animationId": "", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "name": "star_2", - "animationId": "", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "name": "star_3", - "animationId": "", - "autoplay": true, - "segment": "star_3", - "transitions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "name": "star_4", - "animationId": "", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] }, { - "type": "PlaybackState", - "name": "star_5", - "animationId": "", - "autoplay": true, - "segment": "star_5", - "transitions": [] + "type": "Transition", + "toState": "star_6", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 6 + } + ] }, { - "type": "PlaybackState", - "animationId": "", - "name": "star_6", - "autoplay": true, - "transitions": [] + "type": "Transition", + "toState": "star_6", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 6 + } + ] } - ], - "listeners": [ - { - "type": "PointerUp", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 6 - } - ] - }, + ] + }, + { + "type": "PlaybackState", + "name": "star_1", + "animation": "", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_2", + "animation": "", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_3", + "animation": "", + "autoplay": true, + "segment": "star_3", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_4", + "animation": "", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_5", + "animation": "", + "autoplay": true, + "segment": "star_5", + "transitions": [] + }, + { + "type": "PlaybackState", + "animation": "", + "name": "star_6", + "autoplay": true, + "transitions": [] + } + ], + "listeners": [ + { + "type": "PointerUp", + "actions": [ { - "type": "PointerDown", - "layerName": "star1", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 1 - } - ] - }, + "type": "SetNumeric", + "triggerName": "rating", + "value": 6 + } + ] + }, + { + "type": "PointerDown", + "layerName": "star1", + "actions": [ { - "type": "PointerDown", - "layerName": "star2", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 2 - } - ] - }, + "type": "SetNumeric", + "triggerName": "rating", + "value": 1 + } + ] + }, + { + "type": "PointerDown", + "layerName": "star2", + "actions": [ { - "type": "PointerDown", - "layerName": "star3", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 3 - } - ] - }, + "type": "SetNumeric", + "triggerName": "rating", + "value": 2 + } + ] + }, + { + "type": "PointerDown", + "layerName": "star3", + "actions": [ { - "type": "PointerDown", - "layerName": "star4", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 4 - } - ] - }, + "type": "SetNumeric", + "triggerName": "rating", + "value": 3 + } + ] + }, + { + "type": "PointerDown", + "layerName": "star4", + "actions": [ { - "type": "PointerDown", - "layerName": "star5", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 5 - } - ] + "type": "SetNumeric", + "triggerName": "rating", + "value": 4 } - ], - "triggers": [ + ] + }, + { + "type": "PointerDown", + "layerName": "star5", + "actions": [ { - "type": "Numeric", - "name": "rating", - "value": 0 + "type": "SetNumeric", + "triggerName": "rating", + "value": 5 } - ] -} \ No newline at end of file + ] + } + ], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_enter.json b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_enter.json index ddba6181..058ff09c 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_enter.json +++ b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_enter.json @@ -1,202 +1,199 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "star_0", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 0 - } - ] - }, - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "type": "PlaybackState", - "name": "star_0", - "animationId": "", - "autoplay": true, - "segment": "star_0", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_0", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 0 + } + ] }, { - "type": "PlaybackState", - "name": "star_1", - "animationId": "", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "star_2", - "animationId": "", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "name": "star_3", - "animationId": "", - "autoplay": true, - "segment": "star_3", - "transitions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "name": "star_4", - "animationId": "", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "name": "star_5", - "animationId": "", - "autoplay": true, - "segment": "star_5", - "transitions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] } - ], - "listeners": [ - { - "type": "PointerEnter", - "layerName": "star1", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 1 - } - ] - }, + ] + }, + { + "type": "PlaybackState", + "name": "star_0", + "animation": "", + "autoplay": true, + "segment": "star_0", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_1", + "animation": "", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_2", + "animation": "", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_3", + "animation": "", + "autoplay": true, + "segment": "star_3", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_4", + "animation": "", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_5", + "animation": "", + "autoplay": true, + "segment": "star_5", + "transitions": [] + } + ], + "listeners": [ + { + "type": "PointerEnter", + "layerName": "star1", + "actions": [ { - "type": "PointerEnter", - "layerName": "star2", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 2 - } - ] - }, + "type": "SetNumeric", + "triggerName": "rating", + "value": 1 + } + ] + }, + { + "type": "PointerEnter", + "layerName": "star2", + "actions": [ { - "type": "PointerEnter", - "layerName": "star3", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 3 - } - ] - }, + "type": "SetNumeric", + "triggerName": "rating", + "value": 2 + } + ] + }, + { + "type": "PointerEnter", + "layerName": "star3", + "actions": [ { - "type": "PointerEnter", - "layerName": "star4", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 4 - } - ] - }, + "type": "SetNumeric", + "triggerName": "rating", + "value": 3 + } + ] + }, + { + "type": "PointerEnter", + "layerName": "star4", + "actions": [ { - "type": "PointerEnter", - "layerName": "star5", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 5 - } - ] + "type": "SetNumeric", + "triggerName": "rating", + "value": 4 } - ], - "triggers": [ + ] + }, + { + "type": "PointerEnter", + "layerName": "star5", + "actions": [ { - "type": "Numeric", - "name": "rating", - "value": 0 + "type": "SetNumeric", + "triggerName": "rating", + "value": 5 } - ] -} \ No newline at end of file + ] + } + ], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_exit.json b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_exit.json index b5800820..40783fa1 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_exit.json +++ b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_exit.json @@ -1,257 +1,254 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "star_0", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 0 - } - ] - }, - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - } - ] - }, - { - "type": "PlaybackState", - "name": "star_0", - "animationId": "", - "autoplay": true, - "segment": "star_0", - "transitions": [], - "entryActions": [] + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ + { + "type": "Transition", + "toState": "star_0", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 0 + } + ] }, { - "type": "PlaybackState", - "name": "star_1", - "animationId": "", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "star_2", - "animationId": "", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "name": "star_3", - "animationId": "", - "autoplay": true, - "segment": "star_3", - "transitions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "name": "star_4", - "animationId": "", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "name": "star_5", - "animationId": "", - "autoplay": true, - "segment": "star_5", - "transitions": [] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] } - ], - "listeners": [ - { - "type": "PointerEnter", - "layerName": "star1", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 1 - } - ] - }, - { - "type": "PointerExit", - "layerName": "star1", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 0 - } - ] - }, - { - "type": "PointerEnter", - "layerName": "star2", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 2 - } - ] - }, - { - "type": "PointerExit", - "layerName": "star2", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 0 - } - ] - }, - { - "type": "PointerEnter", - "layerName": "star3", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 3 - } - ] - }, - { - "type": "PointerExit", - "layerName": "star3", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 0 - } - ] - }, - { - "type": "PointerEnter", - "layerName": "star4", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 4 - } - ] - }, - { - "type": "PointerExit", - "layerName": "star4", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 0 - } - ] - }, - { - "type": "PointerEnter", - "layerName": "star5", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 5 - } - ] - }, - { - "type": "PointerExit", - "layerName": "star5", - "actions": [ - { - "type": "SetNumeric", - "triggerName": "rating", - "value": 0 - } - ] + ] + }, + { + "type": "PlaybackState", + "name": "star_0", + "animation": "", + "autoplay": true, + "segment": "star_0", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_1", + "animation": "", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_2", + "animation": "", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_3", + "animation": "", + "autoplay": true, + "segment": "star_3", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_4", + "animation": "", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_5", + "animation": "", + "autoplay": true, + "segment": "star_5", + "transitions": [] + } + ], + "listeners": [ + { + "type": "PointerEnter", + "layerName": "star1", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 1 } - ], - "triggers": [ - { - "type": "Numeric", - "name": "rating", - "value": 0 + ] + }, + { + "type": "PointerExit", + "layerName": "star1", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 0 + } + ] + }, + { + "type": "PointerEnter", + "layerName": "star2", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 2 + } + ] + }, + { + "type": "PointerExit", + "layerName": "star2", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 0 + } + ] + }, + { + "type": "PointerEnter", + "layerName": "star3", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 3 + } + ] + }, + { + "type": "PointerExit", + "layerName": "star3", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 0 + } + ] + }, + { + "type": "PointerEnter", + "layerName": "star4", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 4 + } + ] + }, + { + "type": "PointerExit", + "layerName": "star4", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 0 + } + ] + }, + { + "type": "PointerEnter", + "layerName": "star5", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 5 + } + ] + }, + { + "type": "PointerExit", + "layerName": "star5", + "actions": [ + { + "type": "SetNumeric", + "triggerName": "rating", + "value": 0 } - ] -} \ No newline at end of file + ] + } + ], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_move.json b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_move.json index 5eb084cc..3fa573a6 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_move.json +++ b/dotlottie-rs/tests/fixtures/statemachines/listener_tests/pointer_move.json @@ -1,135 +1,132 @@ { - "descriptor": { - "id": "star-rating", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "star_1", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "star_2", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 2 - } - ] - }, - { - "type": "Transition", - "toState": "star_3", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 3 - } - ] - }, - { - "type": "Transition", - "toState": "star_4", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 4 - } - ] - }, - { - "type": "Transition", - "toState": "star_5", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "rating", - "compareTo": 5 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "type": "PlaybackState", - "name": "star_1", - "animationId": "", - "autoplay": true, - "segment": "star_1", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_1", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "star_2", - "animationId": "", - "autoplay": true, - "segment": "star_2", - "transitions": [], - "entryActions": [] + "type": "Transition", + "toState": "star_2", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 2 + } + ] }, { - "type": "PlaybackState", - "name": "star_3", - "animationId": "", - "autoplay": true, - "segment": "star_3", - "transitions": [] + "type": "Transition", + "toState": "star_3", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 3 + } + ] }, { - "type": "PlaybackState", - "name": "star_4", - "animationId": "", - "autoplay": true, - "segment": "star_4", - "transitions": [] + "type": "Transition", + "toState": "star_4", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 4 + } + ] }, { - "type": "PlaybackState", - "name": "star_5", - "animationId": "", - "autoplay": true, - "segment": "star_5", - "transitions": [] - } - ], - "listeners": [ - { - "type": "PointerMove", - "actions": [ - { - "type": "Increment", - "triggerName": "rating" - } - ] + "type": "Transition", + "toState": "star_5", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "rating", + "compareTo": 5 + } + ] } - ], - "triggers": [ + ] + }, + { + "type": "PlaybackState", + "name": "star_1", + "animation": "", + "autoplay": true, + "segment": "star_1", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_2", + "animation": "", + "autoplay": true, + "segment": "star_2", + "transitions": [], + "entryActions": [] + }, + { + "type": "PlaybackState", + "name": "star_3", + "animation": "", + "autoplay": true, + "segment": "star_3", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_4", + "animation": "", + "autoplay": true, + "segment": "star_4", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "star_5", + "animation": "", + "autoplay": true, + "segment": "star_5", + "transitions": [] + } + ], + "listeners": [ + { + "type": "PointerMove", + "actions": [ { - "type": "Numeric", - "name": "rating", - "value": 0 + "type": "Increment", + "triggerName": "rating" } - ] -} \ No newline at end of file + ] + } + ], + "triggers": [ + { + "type": "Numeric", + "name": "rating", + "value": 0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_global_and_guardless.json b/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_global_and_guardless.json index c8f102fe..37847bf5 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_global_and_guardless.json +++ b/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_global_and_guardless.json @@ -1,93 +1,90 @@ { - "descriptor": { - "id": "no-guards", - "initial": "global" - }, - "states": [ - { - "type": "GlobalState", - "name": "global", - "loop": true, - "autoplay": true, - "animationId": "cowboy", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Numeric", - "triggerName": "Rating", - "conditionType": "Equal", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Numeric", - "triggerName": "Rating", - "conditionType": "Equal", - "compareTo": 2 - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "type": "GlobalState", + "name": "global", + "loop": true, + "autoplay": true, + "animation": "cowboy", + "transitions": [ { - "type": "PlaybackState", - "name": "a", - "loop": true, - "autoplay": true, - "animationId": "astonished", - "transitions": [ - { - "type": "Transition", - "toState": "c", - "guards": [] - } - ] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Numeric", + "triggerName": "Rating", + "conditionType": "Equal", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "b", - "autoplay": true, - "loop": true, - "animationId": "blush", - "transitions": [] - }, - { - "type": "PlaybackState", - "name": "c", - "autoplay": true, - "loop": true, - "animationId": "crying", - "transitions": [ - { - "type": "Transition", - "toState": "d", - "guards": [] - } - ] - }, + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Numeric", + "triggerName": "Rating", + "conditionType": "Equal", + "compareTo": 2 + } + ] + } + ] + }, + { + "type": "PlaybackState", + "name": "a", + "loop": true, + "autoplay": true, + "animation": "astonished", + "transitions": [ { - "type": "PlaybackState", - "name": "d", - "autoplay": true, - "loop": true, - "animationId": "devil", - "transitions": [] + "type": "Transition", + "toState": "c", + "guards": [] } - ], - "listeners": [], - "triggers": [ + ] + }, + { + "type": "PlaybackState", + "name": "b", + "autoplay": true, + "loop": true, + "animation": "blush", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "c", + "autoplay": true, + "loop": true, + "animation": "crying", + "transitions": [ { - "type": "Numeric", - "name": "Rating", - "value": 0.0 + "type": "Transition", + "toState": "d", + "guards": [] } - ] -} \ No newline at end of file + ] + }, + { + "type": "PlaybackState", + "name": "d", + "autoplay": true, + "loop": true, + "animation": "devil", + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "Rating", + "value": 0.0 + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_guarded_and_guardless.json b/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_guarded_and_guardless.json index c8e33878..55354bcc 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_guarded_and_guardless.json +++ b/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_guarded_and_guardless.json @@ -1,119 +1,116 @@ { - "descriptor": { - "id": "no-guards", - "initial": "a" - }, - "states": [ - { - "type": "PlaybackState", - "name": "a", - "loop": true, - "autoplay": true, - "animationId": "anger", - "transitions": [ - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Event", - "triggerName": "Step" - } - ] - } - ] - }, - { - "type": "PlaybackState", - "name": "b", - "loop": true, - "autoplay": true, - "animationId": "astonished", - "transitions": [ - { - "type": "Transition", - "toState": "c" - }, - { - "type": "Transition", - "toState": "f", - "guards": [ - { - "type": "Numeric", - "triggerName": "r", - "conditionType": "Equal", - "compareTo": 1 - } - ] - } - ] - }, + "initial": "a", + "states": [ + { + "type": "PlaybackState", + "name": "a", + "loop": true, + "autoplay": true, + "animation": "anger", + "transitions": [ { - "type": "PlaybackState", - "name": "c", - "autoplay": true, - "loop": true, - "animationId": "blush", - "transitions": [ - { - "type": "Transition", - "toState": "d" - } - ] - }, + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Event", + "triggerName": "Step" + } + ] + } + ] + }, + { + "type": "PlaybackState", + "name": "b", + "loop": true, + "autoplay": true, + "animation": "astonished", + "transitions": [ { - "type": "PlaybackState", - "name": "d", - "autoplay": true, - "loop": true, - "animationId": "clowns", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Numeric", - "triggerName": "r", - "conditionType": "Equal", - "compareTo": 1.0 - } - ] - } - ] + "type": "Transition", + "toState": "c" }, { - "type": "PlaybackState", - "name": "f", - "autoplay": true, - "loop": true, - "animationId": "cool", - "transitions": [ - { - "type": "Transition", - "toState": "g" - } - ] - }, + "type": "Transition", + "toState": "f", + "guards": [ + { + "type": "Numeric", + "triggerName": "r", + "conditionType": "Equal", + "compareTo": 1 + } + ] + } + ] + }, + { + "type": "PlaybackState", + "name": "c", + "autoplay": true, + "loop": true, + "animation": "blush", + "transitions": [ { - "type": "PlaybackState", - "name": "g", - "autoplay": true, - "loop": true, - "animationId": "confused", - "transitions": [] + "type": "Transition", + "toState": "d" } - ], - "listeners": [], - "triggers": [ + ] + }, + { + "type": "PlaybackState", + "name": "d", + "autoplay": true, + "loop": true, + "animation": "clowns", + "transitions": [ { - "type": "Numeric", - "name": "r", - "value": 2.0 - }, + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Numeric", + "triggerName": "r", + "conditionType": "Equal", + "compareTo": 1.0 + } + ] + } + ] + }, + { + "type": "PlaybackState", + "name": "f", + "autoplay": true, + "loop": true, + "animation": "cool", + "transitions": [ { - "type": "Event", - "name": "Step" + "type": "Transition", + "toState": "g" } - ] -} \ No newline at end of file + ] + }, + { + "type": "PlaybackState", + "name": "g", + "autoplay": true, + "loop": true, + "animation": "confused", + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "r", + "value": 2.0 + }, + { + "type": "Event", + "name": "Step" + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_guardless_and_event.json b/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_guardless_and_event.json index ca124c9b..0056a104 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_guardless_and_event.json +++ b/dotlottie-rs/tests/fixtures/statemachines/sanity_tests/test_guardless_and_event.json @@ -1,101 +1,98 @@ { - "descriptor": { - "id": "guardless_and_event", - "initial": "global" - }, - "states": [ - { - "type": "GlobalState", - "name": "global", - "loop": true, - "autoplay": true, - "animationId": "smirk", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Numeric", - "triggerName": "Rating", - "conditionType": "Equal", - "compareTo": 1 - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Numeric", - "triggerName": "Rating", - "conditionType": "Equal", - "compareTo": 2 - } - ] - } - ] - }, - { - "type": "PlaybackState", - "name": "a", - "loop": true, - "autoplay": true, - "animationId": "astonished", - "transitions": [ - { - "type": "Transition", - "toState": "d", - "guards": [ - { - "type": "Event", - "triggerName": "Step" - } - ] - }, - { - "type": "Transition", - "toState": "c", - "guards": [] - } - ] - }, - { - "type": "PlaybackState", - "name": "b", - "autoplay": true, - "loop": true, - "animationId": "blush", - "transitions": [] - }, + "initial": "global", + "states": [ + { + "type": "GlobalState", + "name": "global", + "loop": true, + "autoplay": true, + "animation": "smirk", + "transitions": [ { - "type": "PlaybackState", - "name": "c", - "autoplay": true, - "loop": true, - "animationId": "crying", - "transitions": [] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Numeric", + "triggerName": "Rating", + "conditionType": "Equal", + "compareTo": 1 + } + ] }, { - "type": "PlaybackState", - "name": "d", - "autoplay": true, - "loop": true, - "animationId": "devil", - "transitions": [] + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Numeric", + "triggerName": "Rating", + "conditionType": "Equal", + "compareTo": 2 + } + ] } - ], - "listeners": [], - "triggers": [ + ] + }, + { + "type": "PlaybackState", + "name": "a", + "loop": true, + "autoplay": true, + "animation": "astonished", + "transitions": [ { - "type": "Numeric", - "name": "Rating", - "value": 0.0 + "type": "Transition", + "toState": "d", + "guards": [ + { + "type": "Event", + "triggerName": "Step" + } + ] }, { - "type": "Event", - "name": "Step" + "type": "Transition", + "toState": "c", + "guards": [] } - ] + ] + }, + { + "type": "PlaybackState", + "name": "b", + "autoplay": true, + "loop": true, + "animation": "blush", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "c", + "autoplay": true, + "loop": true, + "animation": "crying", + "transitions": [] + }, + { + "type": "PlaybackState", + "name": "d", + "autoplay": true, + "loop": true, + "animation": "devil", + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Numeric", + "name": "Rating", + "value": 0.0 + }, + { + "type": "Event", + "name": "Step" + } + ] } diff --git a/dotlottie-rs/tests/fixtures/statemachines/security_tests/compare_to.json b/dotlottie-rs/tests/fixtures/statemachines/security_tests/compare_to.json index fbaca751..2aaada49 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/security_tests/compare_to.json +++ b/dotlottie-rs/tests/fixtures/statemachines/security_tests/compare_to.json @@ -1,85 +1,82 @@ { - "descriptor": { - "id": "compareTo", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Boolean", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": "$ATriggerName" - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Numeric", - "conditionType": "Equal", - "triggerName": "OnOffSwitch", - "compareTo": "$ATriggerName" - } - ] - }, - { - "type": "Transition", - "toState": "c", - "guards": [ - { - "type": "String", - "triggerName": "$ATriggerName" - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "name": "a", - "type": "PlaybackState", - "animationId": "", - "transitions": [], - "entryActions": [ - { - "type": "Fire", - "triggerName": "Step" - } - ] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Boolean", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": "$ATriggerName" + } + ] }, { - "name": "b", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Numeric", + "conditionType": "Equal", + "triggerName": "OnOffSwitch", + "compareTo": "$ATriggerName" + } + ] }, { - "name": "c", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "c", + "guards": [ + { + "type": "String", + "triggerName": "$ATriggerName" + } + ] } - ], - "listeners": [], - "triggers": [ - { - "type": "Boolean", - "name": "OnOffSwitch", - "value": false - }, + ] + }, + { + "name": "a", + "type": "PlaybackState", + "animation": "", + "transitions": [], + "entryActions": [ { - "type": "Event", - "name": "Step" + "type": "Fire", + "triggerName": "Step" } - ] -} \ No newline at end of file + ] + }, + { + "name": "b", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "c", + "type": "PlaybackState", + "animation": "", + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Boolean", + "name": "OnOffSwitch", + "value": false + }, + { + "type": "Event", + "name": "Step" + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/security_tests/event_guards.json b/dotlottie-rs/tests/fixtures/statemachines/security_tests/event_guards.json index 3f45dd63..85678518 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/security_tests/event_guards.json +++ b/dotlottie-rs/tests/fixtures/statemachines/security_tests/event_guards.json @@ -1,79 +1,76 @@ { - "descriptor": { - "id": "compareTo", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [ - { - "type": "Event", - "triggerName": "DoesntExist" - } - ] - }, - { - "type": "Transition", - "toState": "b", - "guards": [ - { - "type": "Boolean", - "triggerName": "OnOffSwitch", - "conditionType": "Equal", - "compareTo": true - } - ] - }, - { - "type": "Transition", - "toState": "c", - "guards": [ - { - "type": "Boolean", - "triggerName": "OnOffSwitch", - "conditionType": "Equal", - "compareTo": false - } - ] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "name": "a", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "a", + "guards": [ + { + "type": "Event", + "triggerName": "DoesntExist" + } + ] }, { - "name": "b", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "b", + "guards": [ + { + "type": "Boolean", + "triggerName": "OnOffSwitch", + "conditionType": "Equal", + "compareTo": true + } + ] }, { - "name": "c", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "c", + "guards": [ + { + "type": "Boolean", + "triggerName": "OnOffSwitch", + "conditionType": "Equal", + "compareTo": false + } + ] } - ], - "listeners": [], - "triggers": [ - { - "type": "Boolean", - "name": "OnOffSwitch", - "value": false - }, - { - "type": "Event", - "name": "Step" - } - ] -} \ No newline at end of file + ] + }, + { + "name": "a", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "b", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "c", + "type": "PlaybackState", + "animation": "", + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Boolean", + "name": "OnOffSwitch", + "value": false + }, + { + "type": "Event", + "name": "Step" + } + ] +} diff --git a/dotlottie-rs/tests/fixtures/statemachines/security_tests/guardless_transitions.json b/dotlottie-rs/tests/fixtures/statemachines/security_tests/guardless_transitions.json index 2279aea1..e3e5d46f 100644 --- a/dotlottie-rs/tests/fixtures/statemachines/security_tests/guardless_transitions.json +++ b/dotlottie-rs/tests/fixtures/statemachines/security_tests/guardless_transitions.json @@ -1,60 +1,57 @@ { - "descriptor": { - "id": "compareTo", - "initial": "global" - }, - "states": [ - { - "name": "global", - "type": "GlobalState", - "animationId": "", - "transitions": [ - { - "type": "Transition", - "toState": "a", - "guards": [] - }, - { - "type": "Transition", - "toState": "b", - "guards": [] - }, - { - "type": "Transition", - "toState": "c", - "guards": [] - } - ] - }, + "initial": "global", + "states": [ + { + "name": "global", + "type": "GlobalState", + "animation": "", + "transitions": [ { - "name": "a", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "a", + "guards": [] }, { - "name": "b", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "b", + "guards": [] }, { - "name": "c", - "type": "PlaybackState", - "animationId": "", - "transitions": [] + "type": "Transition", + "toState": "c", + "guards": [] } - ], - "listeners": [], - "triggers": [ - { - "type": "Boolean", - "name": "OnOffSwitch", - "value": false - }, - { - "type": "Event", - "name": "Step" - } - ] -} \ No newline at end of file + ] + }, + { + "name": "a", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "b", + "type": "PlaybackState", + "animation": "", + "transitions": [] + }, + { + "name": "c", + "type": "PlaybackState", + "animation": "", + "transitions": [] + } + ], + "listeners": [], + "triggers": [ + { + "type": "Boolean", + "name": "OnOffSwitch", + "value": false + }, + { + "type": "Event", + "name": "Step" + } + ] +} diff --git a/examples/demo-state-machine/src/bin/new-format/new-format.rs b/examples/demo-state-machine/src/bin/new-format/new-format.rs index 57062acb..862b4def 100644 --- a/examples/demo-state-machine/src/bin/new-format/new-format.rs +++ b/examples/demo-state-machine/src/bin/new-format/new-format.rs @@ -1,5 +1,5 @@ use dotlottie_rs::events::Event; -use dotlottie_rs::{Config, DotLottiePlayer}; +use dotlottie_rs::{Config, DotLottiePlayer, StateMachineObserver}; use minifb::{Key, MouseButton, Window, WindowOptions}; use std::fs::{self, File}; use std::io::Read; @@ -9,8 +9,8 @@ use std::time::Instant; pub const WIDTH: usize = 500; pub const HEIGHT: usize = 500; -pub const STATE_MACHINE_NAME: &str = "rating"; -pub const ANIMATION_NAME: &str = "star_marked"; +pub const STATE_MACHINE_NAME: &str = "pigeon_with_listeners"; +pub const ANIMATION_NAME: &str = "pigeon"; struct Timer { last_update: Instant, @@ -18,6 +18,26 @@ struct Timer { first: bool, } +struct DummyObserver; + +impl StateMachineObserver for DummyObserver { + fn on_transition(&self, previous_state: String, new_state: String) { + println!("on_transition2: {} -> {}", previous_state, new_state); + } + + fn on_state_entered(&self, entering_state: String) { + println!("on_state_entered2: {}", entering_state); + } + + fn on_state_exit(&self, leaving_state: String) { + println!("on_state_exit2: {}", leaving_state); + } + + fn on_custom_event(&self, message: String) { + println!("custom_event2: {}", message); + } +} + impl Timer { fn new() -> Self { Self { @@ -53,11 +73,12 @@ fn main() { panic!("{}", e); }); + let observer: Arc = Arc::new(DummyObserver {}); + let lottie_player: DotLottiePlayer = DotLottiePlayer::new(Config { background_color: 0xffffffff, ..Config::default() }); - let mut markers = File::open(format!( "./src/bin/shared/animations/{}.lottie", ANIMATION_NAME @@ -87,6 +108,8 @@ fn main() { let s = lottie_player.state_machine_start(); + lottie_player.state_machine_subscribe(observer.clone()); + println!("Start state machine -> {}", s); println!("is_playing: {}", lottie_player.is_playing()); @@ -116,7 +139,7 @@ fn main() { } if mx >= 0.0 && mx <= WIDTH as f32 && my >= 0.0 && my <= HEIGHT as f32 { - println!("Sending pointer enter"); + // println!("Sending pointer enter"); if !entered { let event = Event::PointerEnter { x: mx, y: my }; @@ -125,7 +148,7 @@ fn main() { } entered = true; } else { - println!("Sending pointer Exit"); + // println!("Sending pointer Exit"); if entered { let event = Event::PointerExit { x: mx, y: my }; @@ -155,7 +178,7 @@ fn main() { let p = &mut *locked_player.write().unwrap(); let _m = p.state_machine_post_event(&event); } else { - println!("Sending pointer move {} {}", mx, my); + // println!("Sending pointer move {} {}", mx, my); let event = Event::PointerMove { x: mx, y: my }; let p = &mut *locked_player.write().unwrap(); let _m = p.state_machine_post_event(&event);