# animation/animator (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/animation/animator/

Animator. (Picks and blends sprite clips with a state machine)
- A port of the original animation/animator.js. States (clip, speed, loop), parameters (float, integer, boolean, trigger),
  transitions (condition list, exit time, blend time, transitions from any state), the transition check in each frame's tick, and the crossfade weights match the original.
- It starts in the first added state. play moves to any state immediately. A transition's from and to are indices in the Animator state list, and a None from moves from any state (Any State).
- tick order: advance the state time (both states while blending) → while blending, move to the next state once the blend time is filled
  → when not blending, check transitions from any state, then transitions leaving the current state, each in the order added, and take the first one that holds.
  No new transition is checked while blending. A trigger used as a condition is cleared when that transition is taken.
- The exit time is the normalized time of the leaving state. The transition can only happen on the update that passes that time, and for a looping state an exit time below 1 is checked every cycle.
- Differences from the original:
  - The original getStates / get_transitions return a List, the Rust version returns a slice (&`[..]`). The dictionary of the original getParameters is returned by get_parameters as a list of names and AnimatorParameter (in insertion order).
  - An original condition is a { parameterName, mode, threshold } object, the Rust version is an AnimationCondition with the same fields. The string values of the original AnimationConditionMode are enum values.
  - Integer parameters are i32, floats and thresholds are f64 like the original numbers. An integer is converted to f64 when compared with a threshold.

## AnimationCondition (struct) (Clone, Debug, PartialEq)

Transition condition. (Original { parameterName, mode, threshold })
- AnimationTransition::add_condition creates and adds it, get_conditions reads it. Animator::is_condition_satisfied checks it with the current parameters.

Example: Read a condition added to a transition and check it with an animator

```rust
use vanilla::{AnimationCondition, AnimationConditionMode, AnimationTransition, Animator};

let mut transition = AnimationTransition::new();
transition.add_condition("speed", AnimationConditionMode::Greater, 0.5);
let condition = &transition.get_conditions()[0];
assert_eq!(condition.parameter_name, "speed");
assert_eq!(condition.mode, AnimationConditionMode::Greater);
assert_eq!(condition.threshold, 0.5);

let mut animator = Animator::new();
assert!(!animator.is_condition_satisfied(condition));
animator.set_float("speed", 1.0);
assert!(animator.is_condition_satisfied(condition));
let slow = AnimationCondition { parameter_name: String::from("speed"), mode: AnimationConditionMode::Less, threshold: 0.5 };
assert!(!animator.is_condition_satisfied(&slow));
```

- `pub parameter_name: String` (field, since 0.4.0): Name of the parameter to compare.
  - returns String
- `pub mode: AnimationConditionMode` (field, since 0.4.0): How to compare.
  - returns AnimationConditionMode
- `pub threshold: f64` (field, since 0.4.0): Threshold. (Used by Greater, Less, Equals, NotEqual)
  - returns f64

## AnimationState (struct) (Clone, Debug, PartialEq, Default)

Animation state. (Plays one clip with a speed and a loop flag)
- The state time is the seconds since entering, multiplied by the speed and accumulated. The normalized time is the state time divided by the clip length. (1 is one cycle)
- If the loop is not set with set_loop (None), it follows the clip's is_loop.
- With no clip or a zero length, the normalized time is 0 before any time passes and 1 after.

Example: Attach a clip to a state and look up the frame for a time

```rust
use vanilla::{AnimationState, Rect};
use vanilla::resource::animationclip::AnimationClip;

let mut clip = AnimationClip::new();
clip.set_frames(vec![Rect::create(0.0, 0.0, 32.0, 32.0), Rect::create(32.0, 0.0, 32.0, 32.0)]);
clip.set_duration(0.5);
clip.set_loop(false);
let mut state = AnimationState::new();
state.set_clip(Some(clip));
state.set_speed(2.0);
assert!(!state.is_loop());
state.set_loop(Some(true));
assert!(state.is_loop());
assert_eq!(state.get_normalized_time(0.75), 1.5);
assert_eq!(state.get_frame_index(0.75), Some(1));
```

- `pub fn new() -> AnimationState` (constructor, since 0.3.2): Create. (No clip, speed 1, loop follows the clip)
  - returns AnimationState: A state with no clip and speed 1. (Length 0, does not loop)
- `pub fn set_clip(&mut self, clip: Option<AnimationClip>)` (method, since 0.3.2): Sets the clip.
  - `clip` Option<AnimationClip>: Clip to use in this state. (None clears it)
- `pub fn get_clip(&self) -> Option<&AnimationClip>` (method, since 0.3.2): Returns the clip.
  - returns Option<&AnimationClip>: Clip of this state. None when there is none.
- `pub fn set_speed(&mut self, speed: f64)` (method, since 0.4.0): Sets the playback speed.
  - `speed` f64: Playback speed. (Default 1, 2 plays twice as fast and 0 stops)
- `pub fn get_speed(&self) -> f64` (method, since 0.4.0): Get the playback speed.
  - returns f64: Playback speed. (Default 1)
- `pub fn set_loop(&mut self, is_loop: Option<bool>)` (method, since 0.4.0): Set whether it loops.
  - `is_loop` Option<bool>: True to loop. (None follows the clip's is_loop, default None)
- `pub fn is_loop(&self) -> bool` (method, since 0.4.0): Get whether it loops.
  - returns bool: True if it loops. (The clip's is_loop when not set with set_loop, false when there is no clip either)
- `pub fn get_duration(&self) -> f64` (method, since 0.4.0): Get the length of one cycle.
  - returns f64: Duration of the clip. (Seconds, 0 when there is no clip)
- `pub fn get_normalized_time(&self, time: f64) -> f64` (method, since 0.4.0): Get the normalized time.
  - `time` f64: State time. (Seconds, accumulated with the speed applied)
  - returns f64: State time divided by the length of one cycle. (1 is one cycle, a looping state keeps accumulating past 1. With a zero length, 0 before any time passes and 1 after)
- `pub fn get_frame_index(&self, time: f64) -> Option<usize>` (method, since 0.4.0): Get the frame index.
  - `time` f64: State time. (Seconds, accumulated with the speed applied)
  - returns Option<usize>: Index of the clip frame shown at that time. (From 0, a looping state restarts every cycle, otherwise it stays on the last frame. 0 for a zero length)
None when there is no clip or no frames.

  Example: A looping state and a state that stays at the end

  ```rust
  use vanilla::{AnimationState, Rect};
  use vanilla::resource::animationclip::AnimationClip;
  
  let mut clip = AnimationClip::new();
  clip.set_frames(vec![Rect::create(0.0, 0.0, 16.0, 16.0), Rect::create(16.0, 0.0, 16.0, 16.0), Rect::create(32.0, 0.0, 16.0, 16.0), Rect::create(48.0, 0.0, 16.0, 16.0)]);
  clip.set_duration(1.0);
  let mut state = AnimationState::new();
  assert_eq!(state.get_frame_index(0.5), None);
  state.set_clip(Some(clip));
  state.set_loop(Some(true));
  assert_eq!(state.get_frame_index(0.5), Some(2));
  assert_eq!(state.get_frame_index(1.25), Some(1));
  state.set_loop(Some(false));
  assert_eq!(state.get_frame_index(1.25), Some(3));
  ```

## AnimationTransition (struct) (Clone, Debug, PartialEq, Default)

Animation transition. (A link between states that moves to the target state when its conditions hold, states are indices in the Animator state list)
- With a None from, it moves from any state (Any State). A transition whose to is None or outside the state list is not used.
- The exit time (exit_time) is the normalized time of the leaving state. When set, the transition can only happen on the update that passes that time.
  For a looping state, an exit time below 1 is checked every cycle (0.5 also at 1.5, 2.5). Otherwise it is checked only once.
- All conditions must hold. A transition with neither an exit time nor conditions is not used.
- If the blend time (duration, seconds) is above 0, both states run together for that time while the weight moves linearly. (Crossfade)
- A transition from any state that leads to the current state is taken only when can_transition_to_self is true. (Default true, the state restarts from the beginning)

Example: Transition from walking to running

```rust
use vanilla::{AnimationConditionMode, AnimationState, AnimationTransition, Animator};

let mut animator = Animator::new();
let walk_index = animator.add_state(AnimationState::new());
let run_index = animator.add_state(AnimationState::new());
let mut transition = AnimationTransition::new();
assert_eq!(transition.get_from(), None);
transition.set_from(Some(walk_index));
transition.set_to(Some(run_index));
transition.set_duration(0.2);
transition.add_condition("speed", AnimationConditionMode::Greater, 3.0);
let transition_index = animator.add_transition(transition);

let transition = &animator.get_transitions()[transition_index];
assert_eq!(transition.get_from(), Some(0));
assert_eq!(transition.get_to(), Some(1));
assert_eq!(transition.get_exit_time(), None);
assert_eq!(transition.get_duration(), 0.2);
assert!(transition.can_transition_to_self());
assert_eq!(transition.get_conditions()[0].mode, AnimationConditionMode::Greater);
```

- `pub fn new() -> AnimationTransition` (constructor, since 0.3.2): Create. (From any state, no entering state, no exit time, blend time 0, may lead to the current state)
  - returns AnimationTransition: An empty transition with no conditions. (It is used once the entering state is set and an exit time or a condition is added)
- `pub fn set_from(&mut self, from: Option<usize>)` (method, since 0.3.2): Set the leaving state. (The index returned by Animator::add_state)
  - `from` Option<usize>: Index of the leaving state. (None means any state, default None)
- `pub fn get_from(&self) -> Option<usize>` (method, since 0.3.2): Get the leaving state.
  - returns Option<usize>: Index of the leaving state. None when it moves from any state.
- `pub fn set_to(&mut self, to: Option<usize>)` (method, since 0.3.2): Set the entering state. (The index returned by Animator::add_state)
  - `to` Option<usize>: Index of the entering state. (None clears it, an empty transition is not used)
- `pub fn get_to(&self) -> Option<usize>` (method, since 0.3.2): Get the entering state.
  - returns Option<usize>: Index of the entering state. None when not set.
- `pub fn set_exit_time(&mut self, exit_time: Option<f64>)` (method, since 0.4.0): Set the exit time.
  - `exit_time` Option<f64>: Normalized time of the leaving state. (1 is the end of one cycle, None checks only the conditions without an exit time, default None)
- `pub fn get_exit_time(&self) -> Option<f64>` (method, since 0.4.0): Get the exit time.
  - returns Option<f64>: Exit time. (Normalized time, None when there is none)
- `pub fn set_duration(&mut self, duration: f64)` (method, since 0.4.0): Set the blend time.
  - `duration` f64: Time to blend the two states. (Seconds, 0 or less moves immediately, default 0)
- `pub fn get_duration(&self) -> f64` (method, since 0.4.0): Get the blend time.
  - returns f64: Blend time. (Seconds)
- `pub fn set_can_transition_to_self(&mut self, can_transition_to_self: bool)` (method, since 0.4.0): Set whether moving to the current state is allowed.
  - `can_transition_to_self` bool: True lets a transition from any state also lead to the current state. (Default true, not used by transitions with a set from)
- `pub fn can_transition_to_self(&self) -> bool` (method, since 0.4.0): Get whether moving to the current state is allowed.
  - returns bool: True if a transition from any state also leads to the current state.
- `pub fn add_condition(&mut self, parameter_name: &str, mode: AnimationConditionMode, threshold: f64)` (method, since 0.4.0): Add a condition.
  - `parameter_name` &str: Name of the parameter to compare.
  - `mode` AnimationConditionMode: How to compare.
  - `threshold` f64: Threshold. (Used by Greater, Less, Equals, NotEqual, original default 0)
- `pub fn get_conditions(&self) -> &[AnimationCondition]` (method, since 0.4.0): Get the condition list.
  - returns &[AnimationCondition]: Conditions in the order they were added.
- `pub fn is_exit_time_reached(&self, state: &AnimationState, previous_time: f64, current_time: f64) -> bool` (method, since 0.4.0): Get whether the exit time was passed.
  - `state` &AnimationState: Leaving state.
  - `previous_time` f64: State time before this update. (Seconds)
  - `current_time` f64: State time after this update. (Seconds)
  - returns bool: True if there is no exit time, or this update passed the exit time. (A zero-length state passes it on the first update after entering)

  Example: An exit time checked every cycle in a looping state

  ```rust
  use vanilla::{AnimationState, AnimationTransition, Rect};
  use vanilla::resource::animationclip::AnimationClip;
  
  let mut clip = AnimationClip::new();
  clip.set_frames(vec![Rect::create(0.0, 0.0, 32.0, 32.0)]);
  clip.set_duration(2.0);
  clip.set_loop(true);
  let mut state = AnimationState::new();
  state.set_clip(Some(clip));
  
  let mut transition = AnimationTransition::new();
  assert!(transition.is_exit_time_reached(&state, 0.0, 0.5));
  transition.set_exit_time(Some(0.5));
  assert!(!transition.is_exit_time_reached(&state, 0.0, 0.5));
  assert!(transition.is_exit_time_reached(&state, 0.5, 1.5));
  assert!(transition.is_exit_time_reached(&state, 2.5, 3.5));
  state.set_loop(Some(false));
  assert!(!transition.is_exit_time_reached(&state, 2.5, 3.5));
  ```

## Animator (struct) (Default)

Animator. (Picks and blends sprite clips with a state machine)
- There are four parameter kinds: float (set_float), integer (set_integer), boolean (set_bool), and trigger (set_trigger). Setting the same name with another kind replaces the kind.
  A trigger is cleared when a transition that uses it as a condition is taken. (reset_trigger also clears it)
- Weights while blending: the next state gets get_transition_weight (blended time / blend time) and the current state gets 1 minus that.
- The chosen frames come from get_current_frame and get_next_frame. (Rects of the clip frame list)

Example: Animator that switches between walking and running by speed

```rust
use vanilla::{AnimationConditionMode, AnimationState, AnimationTransition, Animator, Rect};
use vanilla::resource::animationclip::AnimationClip;

let mut walk_clip = AnimationClip::new();
walk_clip.set_frames(vec![Rect::create(0.0, 0.0, 32.0, 32.0), Rect::create(32.0, 0.0, 32.0, 32.0)]);
walk_clip.set_duration(1.0);
walk_clip.set_loop(true);
let mut run_clip = AnimationClip::new();
run_clip.set_frames(vec![Rect::create(0.0, 32.0, 32.0, 32.0), Rect::create(32.0, 32.0, 32.0, 32.0)]);
run_clip.set_duration(0.5);
run_clip.set_loop(true);

let mut animator = Animator::new();
let mut walk_state = AnimationState::new();
walk_state.set_clip(Some(walk_clip));
let mut run_state = AnimationState::new();
run_state.set_clip(Some(run_clip));
let walk_index = animator.add_state(walk_state);
let run_index = animator.add_state(run_state);
let mut to_run = AnimationTransition::new();
to_run.set_from(Some(walk_index));
to_run.set_to(Some(run_index));
to_run.set_duration(0.25);
to_run.add_condition("speed", AnimationConditionMode::Greater, 3.0);
animator.add_transition(to_run);
let mut to_walk = AnimationTransition::new();
to_walk.set_from(Some(run_index));
to_walk.set_to(Some(walk_index));
to_walk.add_condition("speed", AnimationConditionMode::Less, 1.0);
animator.add_transition(to_walk);

animator.set_float("speed", 5.0);
animator.tick(0.125);
assert_eq!(animator.get_current_state_index(), Some(walk_index));
assert_eq!(animator.get_next_state_index(), Some(run_index));
assert_eq!(animator.get_transition_weight(), 0.0);
animator.tick(0.125);
assert_eq!(animator.get_next_state_index(), Some(run_index));
assert_eq!(animator.get_transition_weight(), 0.5);
animator.tick(0.125);
let frame = animator.get_current_frame().expect("frame");
assert_eq!(animator.get_current_state_index(), Some(run_index));
assert!(!animator.is_in_transition());
assert_eq!(frame.position.y, 32.0);
```

Example: A trigger-driven hit from any state (Any State), returning by exit time

```rust
use vanilla::{AnimationConditionMode, AnimationState, AnimationTransition, Animator, Rect};
use vanilla::resource::animationclip::AnimationClip;

fn create_state(duration: f64, is_loop: bool) -> AnimationState {
	let mut clip = AnimationClip::new();
	clip.set_frames(vec![Rect::create(0.0, 0.0, 32.0, 32.0), Rect::create(32.0, 0.0, 32.0, 32.0)]);
	clip.set_duration(duration);
	clip.set_loop(is_loop);
	let mut state = AnimationState::new();
	state.set_clip(Some(clip));
	state
}

let mut animator = Animator::new();
let idle_index = animator.add_state(create_state(1.0, true));
let run_index = animator.add_state(create_state(0.5, true));
let hit_index = animator.add_state(create_state(0.5, false));
let mut to_run = AnimationTransition::new();
to_run.set_from(Some(idle_index));
to_run.set_to(Some(run_index));
to_run.add_condition("isRunning", AnimationConditionMode::If, 0.0);
animator.add_transition(to_run);
let mut any_to_hit = AnimationTransition::new();
any_to_hit.set_to(Some(hit_index));
any_to_hit.set_can_transition_to_self(false);
any_to_hit.add_condition("hit", AnimationConditionMode::If, 0.0);
animator.add_transition(any_to_hit);
let mut hit_to_idle = AnimationTransition::new();
hit_to_idle.set_from(Some(hit_index));
hit_to_idle.set_to(Some(idle_index));
hit_to_idle.set_exit_time(Some(1.0));
animator.add_transition(hit_to_idle);

animator.set_bool("isRunning", true);
animator.tick(0.1);
assert_eq!(animator.get_current_state_index(), Some(run_index));
animator.set_trigger("hit");
animator.tick(0.1);
assert_eq!(animator.get_current_state_index(), Some(hit_index));
assert!(!animator.get_trigger("hit"));

animator.set_trigger("hit");
animator.tick(0.1);
assert_eq!(animator.get_current_state_index(), Some(hit_index));
assert!(animator.get_trigger("hit"));
animator.reset_trigger("hit");
animator.set_bool("isRunning", false);
animator.tick(0.5);
assert_eq!(animator.get_current_state_index(), Some(idle_index));
```

- `pub fn new() -> Animator` (constructor, since 0.3.2): Create. (No states)
  - returns Animator: An animator with no states, transitions, or parameters. (The current state is None, so tick does nothing)
- `pub fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): Update.
  - `time_delta` f64: Time since the last frame. (Seconds, each state applies its speed)
- `pub fn play(&mut self, state_index: usize)` (method, since 0.4.0): Play a state immediately. (From the beginning, without blending)
  - `state_index` usize: Index of the state to play. (Returned by add_state, ignored when outside the list)

  Example: Moves immediately even while blending, and ignores an index outside the list

  ```rust
  use vanilla::{AnimationConditionMode, AnimationState, AnimationTransition, Animator};
  
  let mut animator = Animator::new();
  let idle_index = animator.add_state(AnimationState::new());
  let jump_index = animator.add_state(AnimationState::new());
  let mut transition = AnimationTransition::new();
  transition.set_from(Some(idle_index));
  transition.set_to(Some(jump_index));
  transition.set_duration(0.5);
  transition.add_condition("jump", AnimationConditionMode::If, 0.0);
  animator.add_transition(transition);
  animator.set_trigger("jump");
  animator.tick(0.1);
  assert!(animator.is_in_transition());
  
  animator.play(idle_index);
  assert_eq!(animator.get_current_state_index(), Some(idle_index));
  assert!(!animator.is_in_transition());
  assert_eq!(animator.get_current_normalized_time(), 0.0);
  animator.play(99);
  assert_eq!(animator.get_current_state_index(), Some(idle_index));
  ```

- `pub fn find_transition(&self, previous_time: f64) -> Option<usize>` (method, since 0.4.0): Find the transition to take.
  - `previous_time` f64: Current state time before this update. (Seconds, used to check whether the exit time was passed)
  - returns Option<usize>: Index of the first transition that holds. (Transitions from any state are checked first, then transitions leaving the current state, each in the order added)
None while blending or when none holds.
- `pub fn start_transition(&mut self, transition_index: usize)` (method, since 0.4.0): Take a transition. (Conditions and exit time are not checked)
  - `transition_index` usize: Index of the transition to take. (Returned by add_transition, ignored when outside the list or when the entering state is outside the list)
- `pub fn is_condition_satisfied(&self, condition: &AnimationCondition) -> bool` (method, since 0.4.0): Get whether a condition holds.
  - `condition` &AnimationCondition: Condition to check. (An entry of AnimationTransition::get_conditions)
  - returns bool: True if the condition holds with the current parameters. (False when the parameter is missing or its kind cannot be compared)
- `pub fn set_float(&mut self, name: &str, value: f64)` (method, since 0.4.0): Set a float parameter.
  - `name` &str: Parameter name.
  - `value` f64: Value. (Replaces the kind when the same name exists)

  Example: Set and read parameters of each kind

  ```rust
  use vanilla::Animator;
  
  let mut animator = Animator::new();
  animator.set_float("speed", 1.5);
  animator.set_integer("combo", 3);
  animator.set_bool("isGrounded", true);
  animator.set_trigger("jump");
  assert_eq!(animator.get_float("speed"), 1.5);
  assert_eq!(animator.get_integer("combo"), 3);
  assert!(animator.get_bool("isGrounded"));
  assert!(animator.get_trigger("jump"));
  
  assert_eq!(animator.get_float("combo"), 0.0);
  assert_eq!(animator.get_float("missing"), 0.0);
  animator.set_bool("speed", false);
  assert_eq!(animator.get_float("speed"), 0.0);
  animator.reset_trigger("jump");
  assert!(!animator.get_trigger("jump"));
  ```

- `pub fn get_float(&self, name: &str) -> f64` (method, since 0.4.0): Get a float parameter.
  - `name` &str: Parameter name.
  - returns f64: Value. (0 when missing or not a float)
- `pub fn set_integer(&mut self, name: &str, value: i32)` (method, since 0.4.0): Set an integer parameter.
  - `name` &str: Parameter name.
  - `value` i32: Value. (Replaces the kind when the same name exists)
- `pub fn get_integer(&self, name: &str) -> i32` (method, since 0.4.0): Get an integer parameter.
  - `name` &str: Parameter name.
  - returns i32: Value. (0 when missing or not an integer)
- `pub fn set_bool(&mut self, name: &str, value: bool)` (method, since 0.4.0): Set a boolean parameter.
  - `name` &str: Parameter name.
  - `value` bool: Value. (Replaces the kind when the same name exists)
- `pub fn get_bool(&self, name: &str) -> bool` (method, since 0.4.0): Get a boolean parameter.
  - `name` &str: Parameter name.
  - returns bool: Value. (False when missing or not a boolean)
- `pub fn set_trigger(&mut self, name: &str)` (method, since 0.4.0): Set a trigger. (Cleared when a transition that uses it as a condition is taken)
  - `name` &str: Parameter name. (Replaces the kind when the same name exists)
- `pub fn reset_trigger(&mut self, name: &str)` (method, since 0.4.0): Clear a trigger.
  - `name` &str: Parameter name. (Replaces the kind when the same name exists)
- `pub fn get_trigger(&self, name: &str) -> bool` (method, since 0.4.0): Get whether a trigger is set.
  - `name` &str: Parameter name.
  - returns bool: True if set. (False when missing or not a trigger)
- `pub fn get_parameters(&self) -> Vec<(&str, AnimatorParameter)>` (method, since 0.4.0): Returns all parameters. (the dictionary of the original getParameters, in first insertion order)
  - returns Vec<(&str, AnimatorParameter)>: List of names and parameters (kind and value). (in first insertion order, setting the same name again keeps its place)

  Example: See names and values in insertion order

  ```rust
  use vanilla::{Animator, AnimatorParameter};
  
  let mut animator = Animator::new();
  animator.set_float("speed", 1.5);
  animator.set_trigger("jump");
  animator.set_bool("speed", true);
  assert_eq!(animator.get_parameters(), vec![("speed", AnimatorParameter::Bool(true)), ("jump", AnimatorParameter::Trigger(true))]);
  ```

- `pub fn add_state(&mut self, state: AnimationState) -> usize` (method, since 0.3.2): Add a state. (It starts in the first added state)
  - `state` AnimationState: State to add.
  - returns usize: Index of the added state. (From 0)
- `pub fn get_states(&self) -> &[AnimationState]` (method, since 0.3.2): Returns the state list.
  - returns &[AnimationState]: State list.
- `pub fn add_transition(&mut self, transition: AnimationTransition) -> usize` (method, since 0.3.2): Add a transition.
  - `transition` AnimationTransition: Transition to add.
  - returns usize: Index of the added transition. (From 0)
- `pub fn get_transitions(&self) -> &[AnimationTransition]` (method, since 0.3.2): Get the transition list.
  - returns &[AnimationTransition]: Transition list.
- `pub fn get_current_state_index(&self) -> Option<usize>` (method, since 0.4.0): Get the current state.
  - returns Option<usize>: Index of the current state. (The leaving state while blending) None when there are no states.
- `pub fn get_current_normalized_time(&self) -> f64` (method, since 0.4.0): Get the normalized time of the current state.
  - returns f64: Current state time divided by the length of one cycle. (0 when there are no states)
- `pub fn get_current_frame(&self) -> Option<&Rect>` (method, since 0.4.0): Get the frame of the current state.
  - returns Option<&Rect>: Rect of the clip frame shown at the current state time. None when there is no state, clip, or frame.
- `pub fn is_in_transition(&self) -> bool` (method, since 0.4.0): Get whether it is blending.
  - returns bool: True while blending two states.
- `pub fn get_next_state_index(&self) -> Option<usize>` (method, since 0.4.0): Get the state being blended in.
  - returns Option<usize>: Index of the entering state. None when not blending.
- `pub fn get_next_normalized_time(&self) -> f64` (method, since 0.4.0): Get the normalized time of the entering state.
  - returns f64: Entering state time divided by the length of one cycle. (0 when not blending)
- `pub fn get_next_frame(&self) -> Option<&Rect>` (method, since 0.4.0): Get the frame of the entering state.
  - returns Option<&Rect>: Rect of the clip frame shown at the entering state time. None when not blending or when there is no clip or frame.
- `pub fn get_transition_weight(&self) -> f64` (method, since 0.4.0): Get the weight of the entering state. (Crossfade)
  - returns f64: Blended time / blend time. (0 to 1, the current state's weight is 1 minus this, 0 when not blending)

  Example: A crossfade blending two states over 0.5 seconds

  ```rust
  use vanilla::{AnimationConditionMode, AnimationState, AnimationTransition, Animator, Rect};
  use vanilla::resource::animationclip::AnimationClip;
  
  let mut animator = Animator::new();
  let walk_index = animator.add_state(AnimationState::new());
  let mut run_clip = AnimationClip::new();
  run_clip.set_frames(vec![Rect::create(0.0, 32.0, 32.0, 32.0), Rect::create(32.0, 32.0, 32.0, 32.0)]);
  run_clip.set_duration(1.0);
  run_clip.set_loop(true);
  let mut run_state = AnimationState::new();
  run_state.set_clip(Some(run_clip));
  let run_index = animator.add_state(run_state);
  let mut transition = AnimationTransition::new();
  transition.set_from(Some(walk_index));
  transition.set_to(Some(run_index));
  transition.set_duration(0.5);
  transition.add_condition("speed", AnimationConditionMode::Greater, 1.0);
  animator.add_transition(transition);
  
  animator.set_float("speed", 2.0);
  animator.tick(0.1);
  assert!(animator.is_in_transition());
  assert_eq!(animator.get_transition_weight(), 0.0);
  animator.tick(0.25);
  let next_weight = animator.get_transition_weight();
  assert_eq!(next_weight, 0.5);
  assert_eq!(1.0 - next_weight, 0.5);
  assert_eq!(animator.get_next_normalized_time(), 0.25);
  assert_eq!(animator.get_next_frame().map(|frame| frame.position.x), Some(0.0));
  animator.tick(0.25);
  assert_eq!(animator.get_current_state_index(), Some(run_index));
  assert_eq!(animator.get_transition_weight(), 0.0);
  assert_eq!(animator.get_current_frame().map(|frame| frame.position.x), Some(32.0));
  ```

## AnimationConditionMode (enum) (Clone, Copy, Debug, PartialEq, Eq)

How a transition condition compares.
- If and IfNot look at boolean parameters. (If also looks at whether a trigger is set)
- Greater, Less, Equals, NotEqual compare float and integer parameters with the threshold.
- A missing parameter or a kind that cannot be compared (Greater on a boolean and so on) does not hold.

Example: What each comparison mode gives for the parameters

```rust
use vanilla::{AnimationCondition, AnimationConditionMode, Animator};

let mut animator = Animator::new();
animator.set_integer("combo", 3);
animator.set_bool("isGrounded", false);
animator.set_trigger("jump");
let check = |parameter_name: &str, mode: AnimationConditionMode, threshold: f64| {
	animator.is_condition_satisfied(&AnimationCondition { parameter_name: parameter_name.to_string(), mode, threshold })
};
assert!(check("jump", AnimationConditionMode::If, 0.0));
assert!(check("isGrounded", AnimationConditionMode::IfNot, 0.0));
assert!(check("combo", AnimationConditionMode::Greater, 2.0));
assert!(!check("combo", AnimationConditionMode::Less, 3.0));
assert!(check("combo", AnimationConditionMode::Equals, 3.0));
assert!(!check("combo", AnimationConditionMode::NotEqual, 3.0));
assert!(!check("isGrounded", AnimationConditionMode::Greater, 0.0));
assert!(!check("missing", AnimationConditionMode::If, 0.0));
```

- `If`: The boolean parameter is true or the trigger is set.
- `IfNot`: The boolean parameter is false.
- `Greater`: The number parameter is greater than the threshold.
- `Less`: The number parameter is less than the threshold.
- `Equals`: The number parameter equals the threshold.
- `NotEqual`: The number parameter differs from the threshold.

## AnimatorParameter (enum) (Clone, Copy, Debug, PartialEq)

Animator parameter. (the original { type, value }, for a trigger whether it is set, returned by Animator::get_parameters)

Example: Read the kind and value

```rust
use vanilla::{Animator, AnimatorParameter};

let mut animator = Animator::new();
animator.set_integer("combo", 2);
assert_eq!(animator.get_parameters(), vec![("combo", AnimatorParameter::Int(2))]);
```

- `Float` = `Float(f64)`: Float. (the original type "float")
- `Int` = `Int(i32)`: Integer. (the original type "int")
- `Bool` = `Bool(bool)`: Boolean. (the original type "bool")
- `Trigger` = `Trigger(bool)`: Trigger. (the original type "trigger", the value is whether it is set)
