# animation/animator (vanilla-engine 0.4.0)

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

애니메이터. (상태 기계로 스프라이트 클립을 고르고 섞는다)
- 원본 animation/animator.js 를 옮긴 것이다. 상태(클립, 속도, 되풀이), 매개변수(실수, 정수, 참 거짓, 트리거),
  전이(조건 목록, 종료 시각, 섞는 시간, 어느 상태에서나 넘어가는 전이), 매 프레임 tick 의 전이 판정과 크로스페이드 가중치가 원본과 같다.
- 처음 더한 상태에서 시작한다. play 로 아무 상태로나 바로 옮길 수 있다. 전이의 from, to 는 Animator 상태 목록의 번호이고 from 이 None 이면 어느 상태에서나(Any State) 넘어간다.
- tick 차례: 상태 시간을 흘린다(섞는 중이면 두 상태 모두) → 섞는 중이면 섞는 시간을 다 채웠을 때 다음 상태로 넘어간다
  → 섞는 중이 아니면 어느 상태에서나 넘어가는 전이, 지금 상태에서 나가는 전이 차례로 넣은 순서대로 보고 처음 맞는 하나를 탄다.
  섞는 동안에는 새 전이를 보지 않는다. 조건으로 쓴 트리거는 그 전이가 타면 풀린다.
- 종료 시각은 나가는 상태의 정규화 시간이다. 그 시각을 지나는 갱신에서만 넘어갈 수 있고, 되풀이하는 상태에서 1 보다 작은 종료 시각은 바퀴마다 본다.
- 원본과 다른 점:
  - 원본 getStates / get_transitions 는 List 를, 러스트 판은 조각(&`[..]`)을 돌려준다. 원본 getParameters 의 사전은 get_parameters 가 이름과 AnimatorParameter 목록(넣은 차례)으로 돌려준다.
  - 원본 조건은 { parameterName, mode, threshold } 객체이고 러스트 판은 같은 필드의 AnimationCondition 이다. 원본 AnimationConditionMode 의 글 값은 열거 값이다.
  - 정수 매개변수는 i32, 실수와 기준 값은 원본 수처럼 f64 다. 정수를 기준 값과 견줄 때는 f64 로 바꿔 견준다.

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

전이 조건. (원본 { parameterName, mode, threshold })
- AnimationTransition::add_condition 이 만들어 넣고 get_conditions 로 읽는다. Animator::is_condition_satisfied 가 지금 매개변수로 본다.

예제: 전이에 넣은 조건을 읽어 애니메이터로 보기

```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): 견줄 매개변수 이름.
  - returns String
- `pub mode: AnimationConditionMode` (field, since 0.4.0): 견주는 법.
  - returns AnimationConditionMode
- `pub threshold: f64` (field, since 0.4.0): 기준 값. (Greater, Less, Equals, NotEqual 에서 쓴다)
  - returns f64

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

애니메이션 상태. (클립 하나를 속도와 되풀이 여부로 튼다)
- 상태 시간은 들어온 뒤 흐른 초에 속도를 곱해 쌓은 것이다. 정규화 시간은 상태 시간을 클립 길이로 나눈 것이다. (1 이면 한 바퀴)
- 되풀이는 set_loop 로 정하지 않으면(None) 클립의 is_loop 를 따른다.
- 클립이 없거나 길이가 0 이면 정규화 시간은 시간이 흐르기 전 0, 흐른 뒤 1 이다.

예제: 상태에 클립 달고 시간에 맞는 프레임 보기

```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): 생성. (클립 없음, 속도 1, 되풀이는 클립을 따름)
  - returns AnimationState: 클립이 없고 속도가 1 인 상태. (길이 0, 되풀이하지 않음)
- `pub fn set_clip(&mut self, clip: Option<AnimationClip>)` (method, since 0.3.2): 클립 설정.
  - `clip` Option<AnimationClip>: 이 상태에서 쓸 클립. (None 이면 비운다)
- `pub fn get_clip(&self) -> Option<&AnimationClip>` (method, since 0.3.2): 클립 반환.
  - returns Option<&AnimationClip>: 이 상태의 클립. 없으면 None.
- `pub fn set_speed(&mut self, speed: f64)` (method, since 0.4.0): 재생 속도 설정.
  - `speed` f64: 재생 속도. (기본 1, 2 면 두 배로 빠르고 0 이면 멈춘다)
- `pub fn get_speed(&self) -> f64` (method, since 0.4.0): 재생 속도 반환.
  - returns f64: 재생 속도. (기본 1)
- `pub fn set_loop(&mut self, is_loop: Option<bool>)` (method, since 0.4.0): 되풀이 여부 설정.
  - `is_loop` Option<bool>: 되풀이하면 참. (None 이면 클립의 is_loop 를 따른다, 기본 None)
- `pub fn is_loop(&self) -> bool` (method, since 0.4.0): 되풀이 여부 반환.
  - returns bool: 되풀이하면 참. (set_loop 로 정하지 않았으면 클립의 is_loop, 클립도 없으면 거짓)
- `pub fn get_duration(&self) -> f64` (method, since 0.4.0): 한 바퀴 길이 반환.
  - returns f64: 클립의 지속 시간. (초, 클립이 없으면 0)
- `pub fn get_normalized_time(&self, time: f64) -> f64` (method, since 0.4.0): 정규화 시간 반환.
  - `time` f64: 상태 시간. (초, 속도를 곱해 쌓은 것)
  - returns f64: 상태 시간을 한 바퀴 길이로 나눈 것. (1 이면 한 바퀴, 되풀이하면 1 을 넘어 쌓인다. 길이가 0 이면 시간이 흐르기 전 0, 흐른 뒤 1)
- `pub fn get_frame_index(&self, time: f64) -> Option<usize>` (method, since 0.4.0): 프레임 번호 반환.
  - `time` f64: 상태 시간. (초, 속도를 곱해 쌓은 것)
  - returns Option<usize>: 그 시간에 보일 클립 프레임의 번호. (0 부터, 되풀이하면 바퀴마다 처음부터, 아니면 끝 프레임에 머문다. 길이가 0 이면 0)
클립이나 프레임이 없으면 None.

  예제: 되풀이하는 상태와 끝에 머무는 상태

  ```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)

애니메이션 전이. (조건이 맞으면 대상 상태로 넘어가는 상태 사이의 연결, 상태는 Animator 상태 목록 번호)
- from 이 None 이면 어느 상태에서나(Any State) 넘어간다. to 가 None 이거나 상태 목록 밖이면 쓰지 않는다.
- 종료 시각(exit_time)은 나가는 상태의 정규화 시간이다. 정해 두면 그 시각을 지나는 갱신에서만 넘어갈 수 있다.
  되풀이하는 상태에서 1 보다 작은 종료 시각은 바퀴마다 본다. (0.5 면 1.5, 2.5 에서도) 그 밖은 한 번만 본다.
- 조건은 모두 맞아야 한다. 종료 시각도 조건도 없는 전이는 쓰지 않는다.
- 섞는 시간(duration, 초)이 0 보다 크면 그동안 두 상태가 함께 흐르며 가중치가 선형으로 옮겨 간다. (크로스페이드)
- 어느 상태에서나 넘어가는 전이가 지금 상태로 가는 경우는 can_transition_to_self 가 참일 때만 탄다. (기본 참, 다시 처음부터 튼다)

예제: 걷기에서 달리기로 가는 전이

```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): 생성. (어느 상태에서나, 들어가는 상태 없음, 종료 시각 없음, 섞는 시간 0, 지금 상태로도 감)
  - returns AnimationTransition: 조건이 없는 빈 전이. (들어가는 상태를 정하고 종료 시각이나 조건을 넣어야 쓰인다)
- `pub fn set_from(&mut self, from: Option<usize>)` (method, since 0.3.2): 나가는 상태 설정. (Animator::add_state 가 돌려준 번호)
  - `from` Option<usize>: 나가는 상태의 번호. (None 이면 어느 상태에서나, 기본 None)
- `pub fn get_from(&self) -> Option<usize>` (method, since 0.3.2): 나가는 상태 반환.
  - returns Option<usize>: 나가는 상태의 번호. 어느 상태에서나 넘어가면 None.
- `pub fn set_to(&mut self, to: Option<usize>)` (method, since 0.3.2): 들어가는 상태 설정. (Animator::add_state 가 돌려준 번호)
  - `to` Option<usize>: 들어가는 상태의 번호. (None 이면 비우고, 빈 전이는 쓰지 않는다)
- `pub fn get_to(&self) -> Option<usize>` (method, since 0.3.2): 들어가는 상태 반환.
  - returns Option<usize>: 들어가는 상태의 번호. 정하지 않았으면 None.
- `pub fn set_exit_time(&mut self, exit_time: Option<f64>)` (method, since 0.4.0): 종료 시각 설정.
  - `exit_time` Option<f64>: 나가는 상태의 정규화 시간. (1 이면 한 바퀴 끝, None 이면 종료 시각 없이 조건만 본다, 기본 None)
- `pub fn get_exit_time(&self) -> Option<f64>` (method, since 0.4.0): 종료 시각 반환.
  - returns Option<f64>: 종료 시각. (정규화 시간, 없으면 None)
- `pub fn set_duration(&mut self, duration: f64)` (method, since 0.4.0): 섞는 시간 설정.
  - `duration` f64: 두 상태를 섞는 시간. (초, 0 이하이면 바로 넘어간다, 기본 0)
- `pub fn get_duration(&self) -> f64` (method, since 0.4.0): 섞는 시간 반환.
  - returns f64: 섞는 시간. (초)
- `pub fn set_can_transition_to_self(&mut self, can_transition_to_self: bool)` (method, since 0.4.0): 지금 상태로 가는 것을 허락할지 설정.
  - `can_transition_to_self` bool: 참이면 어느 상태에서나 넘어가는 전이가 지금 상태로도 간다. (기본 참, from 이 정해진 전이에는 쓰지 않는다)
- `pub fn can_transition_to_self(&self) -> bool` (method, since 0.4.0): 지금 상태로 가는 것을 허락하는지 반환.
  - returns bool: 어느 상태에서나 넘어가는 전이가 지금 상태로도 가면 참.
- `pub fn add_condition(&mut self, parameter_name: &str, mode: AnimationConditionMode, threshold: f64)` (method, since 0.4.0): 조건 추가.
  - `parameter_name` &str: 견줄 매개변수 이름.
  - `mode` AnimationConditionMode: 견주는 법.
  - `threshold` f64: 기준 값. (Greater, Less, Equals, NotEqual 에서 쓴다, 원본 기본 0)
- `pub fn get_conditions(&self) -> &[AnimationCondition]` (method, since 0.4.0): 조건 목록 반환.
  - returns &[AnimationCondition]: 넣은 차례의 조건 목록.
- `pub fn is_exit_time_reached(&self, state: &AnimationState, previous_time: f64, current_time: f64) -> bool` (method, since 0.4.0): 종료 시각을 지났는지 반환.
  - `state` &AnimationState: 나가는 상태.
  - `previous_time` f64: 이번 갱신 앞의 상태 시간. (초)
  - `current_time` f64: 이번 갱신 뒤의 상태 시간. (초)
  - returns bool: 종료 시각이 없거나, 이번 갱신에서 종료 시각을 지났으면 참. (길이가 0 인 상태는 들어온 뒤 첫 갱신에서 지난다)

  예제: 되풀이하는 상태에서 바퀴마다 보는 종료 시각

  ```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)

애니메이터. (상태 기계로 스프라이트 클립을 고르고 섞는다)
- 매개변수는 실수(set_float), 정수(set_integer), 참 거짓(set_bool), 트리거(set_trigger) 넷이다. 같은 이름을 다른 종류로 넣으면 종류째 바꾼다.
  트리거는 그 트리거를 조건으로 쓴 전이가 타면 풀린다. (reset_trigger 로 직접 풀 수도 있다)
- 섞는 중의 가중치: 다음 상태가 get_transition_weight(섞은 시간 / 섞는 시간), 지금 상태가 1 - 그 값이다.
- 고른 프레임은 get_current_frame, get_next_frame 으로 꺼낸다. (클립 프레임 목록의 영역)

예제: 속도로 걷기와 달리기를 오가는 애니메이터

```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);
```

예제: 트리거로 어느 상태에서나(Any State) 넘어가는 피격과 종료 시각으로 돌아오기

```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): 생성. (상태 없음)
  - returns Animator: 상태, 전이, 매개변수가 없는 애니메이터. (지금 상태가 None 이라 tick 이 아무것도 하지 않는다)
- `pub fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): 갱신.
  - `time_delta` f64: 지난 프레임부터의 시간. (초, 상태마다 속도를 곱해 흘린다)
- `pub fn play(&mut self, state_index: usize)` (method, since 0.4.0): 상태 바로 틀기. (섞지 않고 처음부터)
  - `state_index` usize: 틀 상태의 번호. (add_state 가 돌려준 것, 목록 밖이면 무시한다)

  예제: 섞는 중에도 바로 옮기고, 목록 밖 번호는 무시

  ```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): 탈 전이 찾기.
  - `previous_time` f64: 이번 갱신 앞의 지금 상태 시간. (초, 종료 시각을 지났는지 볼 때 쓴다)
  - returns Option<usize>: 처음 맞는 전이의 번호. (어느 상태에서나 넘어가는 전이를 먼저, 그다음 지금 상태에서 나가는 전이를 넣은 순서대로 본다)
섞는 중이거나 없으면 None.
- `pub fn start_transition(&mut self, transition_index: usize)` (method, since 0.4.0): 전이 타기. (조건과 종료 시각은 보지 않는다)
  - `transition_index` usize: 탈 전이의 번호. (add_transition 이 돌려준 것, 목록 밖이거나 들어가는 상태가 목록 밖이면 무시한다)
- `pub fn is_condition_satisfied(&self, condition: &AnimationCondition) -> bool` (method, since 0.4.0): 조건이 맞는지 반환.
  - `condition` &AnimationCondition: 볼 조건. (AnimationTransition::get_conditions 의 요소)
  - returns bool: 지금 매개변수로 조건이 맞으면 참. (매개변수가 없거나 견줄 수 없는 종류면 거짓)
- `pub fn set_float(&mut self, name: &str, value: f64)` (method, since 0.4.0): 실수 매개변수 설정.
  - `name` &str: 매개변수 이름.
  - `value` f64: 값. (같은 이름이 있으면 종류째 바꾼다)

  예제: 종류별 매개변수 넣고 읽기

  ```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): 실수 매개변수 반환.
  - `name` &str: 매개변수 이름.
  - returns f64: 값. (없거나 실수가 아니면 0)
- `pub fn set_integer(&mut self, name: &str, value: i32)` (method, since 0.4.0): 정수 매개변수 설정.
  - `name` &str: 매개변수 이름.
  - `value` i32: 값. (같은 이름이 있으면 종류째 바꾼다)
- `pub fn get_integer(&self, name: &str) -> i32` (method, since 0.4.0): 정수 매개변수 반환.
  - `name` &str: 매개변수 이름.
  - returns i32: 값. (없거나 정수가 아니면 0)
- `pub fn set_bool(&mut self, name: &str, value: bool)` (method, since 0.4.0): 참 거짓 매개변수 설정.
  - `name` &str: 매개변수 이름.
  - `value` bool: 값. (같은 이름이 있으면 종류째 바꾼다)
- `pub fn get_bool(&self, name: &str) -> bool` (method, since 0.4.0): 참 거짓 매개변수 반환.
  - `name` &str: 매개변수 이름.
  - returns bool: 값. (없거나 참 거짓이 아니면 거짓)
- `pub fn set_trigger(&mut self, name: &str)` (method, since 0.4.0): 트리거 걸기. (그 트리거를 조건으로 쓴 전이가 타면 풀린다)
  - `name` &str: 매개변수 이름. (같은 이름이 있으면 종류째 바꾼다)
- `pub fn reset_trigger(&mut self, name: &str)` (method, since 0.4.0): 트리거 풀기.
  - `name` &str: 매개변수 이름. (같은 이름이 있으면 종류째 바꾼다)
- `pub fn get_trigger(&self, name: &str) -> bool` (method, since 0.4.0): 트리거가 걸려 있는지 반환.
  - `name` &str: 매개변수 이름.
  - returns bool: 걸려 있으면 참. (없거나 트리거가 아니면 거짓)
- `pub fn get_parameters(&self) -> Vec<(&str, AnimatorParameter)>` (method, since 0.4.0): 모든 매개변수 반환. (원본 getParameters 의 사전, 처음 넣은 차례)
  - returns Vec<(&str, AnimatorParameter)>: 이름과 매개변수(종류와 값) 목록. (처음 넣은 차례, 같은 이름을 다시 넣어도 자리는 그대로)

  예제: 넣은 차례로 이름과 값 보기

  ```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): 상태 더하기. (처음 더한 상태에서 시작한다)
  - `state` AnimationState: 더할 상태.
  - returns usize: 더한 상태의 번호. (0 부터)
- `pub fn get_states(&self) -> &[AnimationState]` (method, since 0.3.2): 상태 목록 반환.
  - returns &[AnimationState]: 상태 목록.
- `pub fn add_transition(&mut self, transition: AnimationTransition) -> usize` (method, since 0.3.2): 전이 더하기.
  - `transition` AnimationTransition: 더할 전이.
  - returns usize: 더한 전이의 번호. (0 부터)
- `pub fn get_transitions(&self) -> &[AnimationTransition]` (method, since 0.3.2): 전이 목록 반환.
  - returns &[AnimationTransition]: 전이 목록.
- `pub fn get_current_state_index(&self) -> Option<usize>` (method, since 0.4.0): 지금 상태 반환.
  - returns Option<usize>: 지금 상태의 번호. (섞는 중이면 나가는 상태) 상태가 없으면 None.
- `pub fn get_current_normalized_time(&self) -> f64` (method, since 0.4.0): 지금 상태의 정규화 시간 반환.
  - returns f64: 지금 상태 시간을 한 바퀴 길이로 나눈 것. (상태가 없으면 0)
- `pub fn get_current_frame(&self) -> Option<&Rect>` (method, since 0.4.0): 지금 상태의 프레임 반환.
  - returns Option<&Rect>: 지금 상태 시간에 보일 클립 프레임의 영역. 상태나 클립이나 프레임이 없으면 None.
- `pub fn is_in_transition(&self) -> bool` (method, since 0.4.0): 섞는 중인지 반환.
  - returns bool: 두 상태를 섞는 중이면 참.
- `pub fn get_next_state_index(&self) -> Option<usize>` (method, since 0.4.0): 섞으며 들어가는 상태 반환.
  - returns Option<usize>: 들어가는 상태의 번호. 섞는 중이 아니면 None.
- `pub fn get_next_normalized_time(&self) -> f64` (method, since 0.4.0): 들어가는 상태의 정규화 시간 반환.
  - returns f64: 들어가는 상태 시간을 한 바퀴 길이로 나눈 것. (섞는 중이 아니면 0)
- `pub fn get_next_frame(&self) -> Option<&Rect>` (method, since 0.4.0): 들어가는 상태의 프레임 반환.
  - returns Option<&Rect>: 들어가는 상태 시간에 보일 클립 프레임의 영역. 섞는 중이 아니거나 클립이나 프레임이 없으면 None.
- `pub fn get_transition_weight(&self) -> f64` (method, since 0.4.0): 들어가는 상태의 가중치 반환. (크로스페이드)
  - returns f64: 섞은 시간 / 섞는 시간. (0 ~ 1, 지금 상태의 가중치는 1 - 이 값, 섞는 중이 아니면 0)

  예제: 0.5 초 동안 두 상태를 섞는 크로스페이드

  ```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)

전이 조건의 견주는 법.
- If, IfNot 은 참 거짓 매개변수를 본다. (If 는 트리거가 걸려 있는 것도 본다)
- Greater, Less, Equals, NotEqual 은 실수와 정수 매개변수를 기준 값과 견준다.
- 매개변수가 없거나 견줄 수 없는 종류면(참 거짓에 Greater 같은) 맞지 않은 것이다.

예제: 견주는 법마다 매개변수를 보는 결과

```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`: 참 거짓 매개변수가 참이거나 트리거가 걸려 있다.
- `IfNot`: 참 거짓 매개변수가 거짓이다.
- `Greater`: 수 매개변수가 기준 값보다 크다.
- `Less`: 수 매개변수가 기준 값보다 작다.
- `Equals`: 수 매개변수가 기준 값과 같다.
- `NotEqual`: 수 매개변수가 기준 값과 다르다.

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

애니메이터 매개변수. (원본 { type, value }, 트리거는 걸려 있는지, Animator::get_parameters 가 돌려준다)

예제: 종류와 값 꺼내기

```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)`: 실수. (원본 type "float")
- `Int` = `Int(i32)`: 정수. (원본 type "int")
- `Bool` = `Bool(bool)`: 참 거짓. (원본 type "bool")
- `Trigger` = `Trigger(bool)`: 트리거. (원본 type "trigger", 값은 걸려 있는지)
