# core/gamepadmanager (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/gamepadmanager/

게임패드 관리자.
- 원본 core/gamepadmanager.js 를 옮겼다. 공개 이름(GamepadButtonCode, GamepadAnalogStickCode, GamepadTriggerCode,
  connect, disconnect, set_callback, update_all_gamepads, is_button_pressed, get_button_value, get_axis_value,
  get_all_connected_gamepads, get_connected_gamepad_count, get_connected_gamepad)과 갱신 규칙은 원본 그대로다.
  (값은 소수점 둘째 자리로 반올림, 축은 0.01 넘게 바뀔 때만 받기, 아날로그 값은 0 보다 클 때만 알리기, 로그 문구)
- 원본은 navigator.getGamepads() 를 읽는다. 웹(wasm32)은 원본처럼 navigator.getGamepads() 를 직접 읽어 브라우저가 주는 버튼과 축을 모두 받고,
  연결과 해제는 원본 engine.js 처럼 gamepadconnected / gamepaddisconnected 로 받는다.
  데스크탑은 gilrs 가 OS 입력(윈도우는 Windows.Gaming.Input)을 읽고, 원본과 같은 W3C Standard Gamepad 꼴
  (버튼 0~16, 축 0~3, 축 Y 는 아래가 양수)의 Gamepad 목록으로 바꾼 뒤 같은 규칙을 돌린다.
- 원본과 다른 점:
  - gilrs 기본 필터(데드존, 떨림 거르기)는 끈다. 브라우저처럼 날값을 받고, 데드존은 원본처럼 게임이 건다.
  - 아날로그 버튼(트리거)의 눌림은 크로미엄과 같이 값이 30/255 를 넘을 때다. (gilrs 기본은 0.75 에 눌림, 0.65 에 뗌)
  - 축(햇 스위치)으로 오는 십자키는 버튼 12~15 로 바꾼다. (브라우저가 하는 일)
  - 데스크탑의 버튼은 표준 17개 뒤에 gilrs 가 표준 버튼으로 잇지 못한 단추(매핑에 없는 단추, gilrs 의 C, Z)를, 축은 표준 4개 뒤에
    매핑에 없는 축을 처음 움직인 차례로 붙인다. gilrs 가 장치의 단추 목록을 내주지 않고 한 번이라도 움직인 단추만 알려서, 그 단추를 처음 누른 뒤에야 생긴다.
    버튼이나 축 수가 늘면 그 패드의 상태 칸도 늘린다.
  - 플레이스테이션 패드(소니 054c 의 듀얼쇼크4 05c4, 09cc, 0ba0 와 듀얼센스 0ce6, 0df2, 0e5f)는 크롬(device/gamepad 의 MapperDualshock4, MapperDualSense)처럼
    버튼 18개이고 원시 단추 13번(HID 단추 14)이 TOUCHPAD(17)다. 누르기 전에도 늘 있고, 그 밖의 단추(듀얼센스 마이크 단추)와 축은 붙이지 않는다.
    gilrs 가 SDL 매핑의 touchpad:b13 을 이름 없는 단추(Button::Unknown, misc1 과 같은 이름)로 잇기만 해서, 그 단추의 원시 코드를 플랫폼마다 정해 찾는다.
    (맥 IOKit 단추 쪽의 쓰임 14, 윈도우 Windows.Gaming.Input 의 단추 13번, 리눅스 hid-generic 의 BTN_GAMEPAD + 13)
    리눅스의 hid-sony(커널 4.10 부터), hid-playstation(5.12 부터) 드라이버는 터치패드를 따로 장치로 내고 bcdHID 에 0x8000 을 붙인다.
    그때는 크롬(MapperPs4Ps5)처럼 버튼 17개다. (gilrs 의 uuid 13, 14번째 바이트가 그 판 번호다)
    맥 GameController 의 GCDualSenseGamepad.touchpadButton 도 있지만, GameController 는 패드의 제조사, 제품 번호를 내주지 않아 gilrs 패드와 짝짓지 못해 쓰지 않는다.
  - Gamepad.index 는 데스크탑에서는 gilrs 의 GamepadId 번호다. (처음 붙은 순서로 0 부터, 브라우저 index 와 같은 쓰임) 웹은 브라우저 index 다.
  - Gamepad.id 는 웹에서는 브라우저 id 그대로, 데스크탑에서는 크롬 꼴 "이름 (STANDARD GAMEPAD Vendor: 054c Product: 0ce6)" 로 만든다.
  - 콜백의 button 값은 bool 대신 1.0(눌림) / 0.0(뗌) 이다.
  - gilrs(웹은 연결 리스너)는 처음 부를 때(갱신, 진동, 패드 목록 읽기) 만든다. (부르지 않는 엔진과 시험에서는 장치를 열지 않는다)
- get_all_connected_gamepads / get_connected_gamepad 는 원본 navigator.getGamepads() 처럼 부를 때 그 자리에서 읽은 사본을 돌려준다(&self). (데스크탑은 gilrs 사건을 비워 지금 상태,
  그 사이의 연결과 해제는 다음 갱신이 받는다) update_all_gamepads_with_list 로 목록을 넣은 관리자(시험, 다른 입력원)는 넣은 목록을 돌려준다.
  - 더한 것: set_log_enabled (로그 켜고 끄기),
    update_all_gamepads_with_list (gilrs 없이 목록을 넣는 길. 시험이나 다른 입력원)
  - 배터리 정보는 원본에 없어 옮기지 않는다.
  - 단추와 축이 바뀔 때마다 찍는 로그는 원본처럼 set_input_log_enabled 로 켜고, 기본은 끔이다. set_log_enabled 는 연결과 해제를 포함한 모든 로그의 큰 스위치다.
  - GamepadKind, read_gamepad_kind: 패드 이름으로 종류(엑스박스, 플레이스테이션, 닌텐도, 그 밖)를 가른다. get_active_gamepad_id 는 마지막 갱신에 단추를 누르거나 축을 크게 기울인 패드다.
  - vibrate(strong_magnitude, weak_magnitude, seconds): 연결된 패드를 모두 떤다.
    데스크탑은 gilrs force feedback(리눅스 evdev, 윈도우 XInput 과 Windows.Gaming.Input)으로 떨고, gilrs 가 진동을 대지 않는 macOS 는
    플랫폼 층(platform/desktop/gamepadhaptics.rs)이 GameController 와 CoreHaptics 로 gilrs 패드와 짝인 컨트롤러를 떤다. (macOS 는 길이나 세기가 0 이면 앞 진동을 멈춘다)
    그래서 gilrs 를 진동을 켠 채 만든다. (데스크탑에서 gilrs 의 진동 스레드 하나가 돈다) 웹은 원본처럼 navigator.getGamepads() 의 vibrationActuator 에 dual-rumble 을 건다.
    첫 갱신(tick) 전에 불러도 그 자리에서 gilrs 를 만들어 떤다. (원본처럼)

## GamepadAnalogStickCode (struct)

게임패드 아날로그 스틱 식별자. (W3C Standard Gamepad 매핑 규격)
- 값은 Gamepad.axes 의 번호이고 get_axis_value 의 axis_index 로 쓴다.

예제: 왼쪽 스틱 축 읽기

```rust
use vanilla::{Gamepad, GamepadAnalogStickCode, GamepadManager};

let mut gamepad_manager = GamepadManager::new();
gamepad_manager.set_log_enabled(false);
let mut gamepad = Gamepad::create(0, "Test Pad");
gamepad.axes[GamepadAnalogStickCode::LEFT_X] = 0.75;
gamepad.axes[GamepadAnalogStickCode::LEFT_Y] = -1.0;
gamepad_manager.update_all_gamepads_with_list(vec![Some(gamepad)]);
assert_eq!(gamepad_manager.get_axis_value(0, GamepadAnalogStickCode::LEFT_X), 0.75);
assert_eq!(gamepad_manager.get_axis_value(0, GamepadAnalogStickCode::LEFT_Y), -1.0);
assert_eq!(gamepad_manager.get_axis_value(0, GamepadAnalogStickCode::RIGHT_X), 0.0);
```

- `pub const LEFT_X: usize = 0` (static, since 0.3.2): 왼쪽 스틱 가로 축. (-1 왼쪽 ~ 1 오른쪽)
  - returns usize
- `pub const LEFT_Y: usize = 1` (static, since 0.3.2): 왼쪽 스틱 세로 축. (-1 위 ~ 1 아래)
  - returns usize
- `pub const RIGHT_X: usize = 2` (static, since 0.3.2): 오른쪽 스틱 가로 축. (-1 왼쪽 ~ 1 오른쪽)
  - returns usize
- `pub const RIGHT_Y: usize = 3` (static, since 0.3.2): 오른쪽 스틱 세로 축. (-1 위 ~ 1 아래)
  - returns usize

## GamepadTriggerCode (struct)

게임패드 트리거 식별자. (W3C Standard Gamepad 매핑 규격)
- 값은 버튼 번호다. (GamepadButtonCode::L2, R2 와 같다) 아날로그 값은 get_button_value 로 읽는다.

예제: 오른쪽 트리거를 반쯤 당긴 값 읽기

```rust
use vanilla::{Gamepad, GamepadButton, GamepadButtonCode, GamepadManager, GamepadTriggerCode};

let mut gamepad_manager = GamepadManager::new();
gamepad_manager.set_log_enabled(false);
let mut gamepad = Gamepad::create(0, "Test Pad");
gamepad.buttons[GamepadTriggerCode::R2] = GamepadButton { pressed: true, value: 0.5 };
gamepad_manager.update_all_gamepads_with_list(vec![Some(gamepad)]);
assert!(gamepad_manager.is_button_pressed(0, GamepadTriggerCode::R2));
assert_eq!(gamepad_manager.get_button_value(0, GamepadTriggerCode::R2), 0.5);
assert_eq!(GamepadTriggerCode::L2, GamepadButtonCode::L2);
```

- `pub const L2: usize = 6` (static, since 0.3.2): 왼쪽 트리거. (버튼 6번, 값 0 ~ 1)
  - returns usize
- `pub const R2: usize = 7` (static, since 0.3.2): 오른쪽 트리거. (버튼 7번, 값 0 ~ 1)
  - returns usize

## GamepadButtonCode (struct)

게임패드 버튼 식별자. (W3C Standard Gamepad 매핑 규격)
- 값은 Gamepad.buttons 의 번호이고 is_button_pressed 들의 button_index 로 쓴다. 앞면 버튼은 자리로 정한다. (아래 0, 오른쪽 1, 왼쪽 2, 위 3)

예제: 두 번 갱신하며 방금 눌림과 눌린 채 가르기

```rust
use vanilla::{Gamepad, GamepadButton, GamepadButtonCode, GamepadManager};

let mut gamepad_manager = GamepadManager::new();
gamepad_manager.set_log_enabled(false);
let mut gamepad = Gamepad::create(0, "Test Pad");
gamepad.buttons[GamepadButtonCode::A_CROSS] = GamepadButton { pressed: true, value: 1.0 };
gamepad_manager.update_all_gamepads_with_list(vec![Some(gamepad.clone())]);
assert!(gamepad_manager.is_button_just_pressed(0, GamepadButtonCode::A_CROSS));
gamepad_manager.update_all_gamepads_with_list(vec![Some(gamepad)]);
assert!(gamepad_manager.is_button_pressed(0, GamepadButtonCode::A_CROSS));
assert!(!gamepad_manager.is_button_just_pressed(0, GamepadButtonCode::A_CROSS));
assert!(!gamepad_manager.is_button_pressed(0, GamepadButtonCode::B_CIRCLE));
```

- `pub const A_CROSS: usize = 0` (static, since 0.3.2): 앞면 버튼.
  - returns usize
- `pub const B_CIRCLE: usize = 1` (static, since 0.3.2): 앞면 오른쪽 버튼. (엑스박스 B, 플레이스테이션 동그라미)
  - returns usize
- `pub const X_SQUARE: usize = 2` (static, since 0.3.2): 앞면 왼쪽 버튼. (엑스박스 X, 플레이스테이션 네모)
  - returns usize
- `pub const Y_TRIANGLE: usize = 3` (static, since 0.3.2): 앞면 위쪽 버튼. (엑스박스 Y, 플레이스테이션 세모)
  - returns usize
- `pub const L1: usize = 4` (static, since 0.3.2): 범퍼.
  - returns usize
- `pub const R1: usize = 5` (static, since 0.3.2): 오른쪽 범퍼.
  - returns usize
- `pub const L2: usize = 6` (static, since 0.3.2): 트리거. (버튼으로도 인식됨)
  - returns usize
- `pub const R2: usize = 7` (static, since 0.3.2): 오른쪽 트리거. (값 0 ~ 1)
  - returns usize
- `pub const SHARE_VIEW: usize = 8` (static, since 0.3.2): 시스템.
  - returns usize
- `pub const OPTIONS_MENU: usize = 9` (static, since 0.3.2): 오른쪽 시스템 버튼. (엑스박스 메뉴, 플레이스테이션 옵션)
  - returns usize
- `pub const L3: usize = 10` (static, since 0.3.2): 스틱 누름.
  - returns usize
- `pub const R3: usize = 11` (static, since 0.3.2): 오른쪽 스틱 누름.
  - returns usize
- `pub const DPAD_UP: usize = 12` (static, since 0.3.2): 십자키.
  - returns usize
- `pub const DPAD_DOWN: usize = 13` (static, since 0.3.2): 십자키 아래.
  - returns usize
- `pub const DPAD_LEFT: usize = 14` (static, since 0.3.2): 십자키 왼쪽.
  - returns usize
- `pub const DPAD_RIGHT: usize = 15` (static, since 0.3.2): 십자키 오른쪽.
  - returns usize
- `pub const HOME_PS: usize = 16` (static, since 0.3.2): 가운데.
  - returns usize
- `pub const TOUCHPAD: usize = 17` (static, since 0.3.2): 플레이스테이션 터치패드 누름. (표준 17개 뒤의 버튼, 듀얼쇼크4와 듀얼센스만)
  - returns usize

## GamepadInputCallback (type)

입력 콜백. (gamepad_index, input_type, input_index, value)

```rust
pub type GamepadInputCallback = Box<dyn FnMut(usize, GamepadInputType, usize, f64)>
```

## GamepadButton (struct) (Clone, Copy, Debug, PartialEq)

게임패드 버튼 하나. (W3C GamepadButton)

예제: 패드 사본의 버튼 바꾸기

```rust
use vanilla::{Gamepad, GamepadButton, GamepadButtonCode};

let mut gamepad = Gamepad::create(0, "Test Pad");
assert!(!gamepad.buttons[GamepadButtonCode::L2].pressed);
gamepad.buttons[GamepadButtonCode::L2] = GamepadButton { pressed: true, value: 0.4 };
assert_eq!(gamepad.buttons[GamepadButtonCode::L2].value, 0.4);
```

- `pub pressed: bool` (field, since 0.3.2): 눌렸는지.
  - returns bool
- `pub value: f64` (field, since 0.3.2): 값. (0.0 ~ 1.0, 트리거는 아날로그)
  - returns f64

## Gamepad (struct) (Clone, Debug, PartialEq, GamepadElementReader)

게임패드 하나의 사본. (W3C Gamepad, navigator.getGamepads() 가 주는 것과 같은 꼴)

예제: 패드를 만들어 연결된 패드 목록에서 읽기

```rust
use vanilla::{read_gamepad_kind, Gamepad, GamepadKind, GamepadManager};

let gamepad = Gamepad::create(1, "Xbox Wireless Controller");
assert_eq!(gamepad.buttons.len(), 17);
assert_eq!(gamepad.axes.len(), 4);
assert!(gamepad.connected);
assert_eq!(read_gamepad_kind(&gamepad.id), GamepadKind::Xbox);

let mut gamepad_manager = GamepadManager::new();
gamepad_manager.set_log_enabled(false);
gamepad_manager.update_all_gamepads_with_list(vec![None, Some(gamepad)]);
let connected_gamepad = gamepad_manager.get_connected_gamepad(0);
assert_eq!(connected_gamepad.map(|gamepad| gamepad.index), Some(1));
```

- `pub index: usize` (field, since 0.3.2): 하드웨어 식별 번호. (is_button_pressed 들의 gamepad_index)
  - returns usize
- `pub id: String` (field, since 0.3.2): 장치 이름.
  - returns String
- `pub connected: bool` (field, since 0.3.2): 연결되어 있는지.
  - returns bool
- `pub buttons: Vec<GamepadButton>` (field, since 0.3.2): 버튼 목록. (GamepadButtonCode 순서)
  - returns Vec<GamepadButton>
- `pub axes: Vec<f64>` (field, since 0.3.2): 축 목록. (GamepadAnalogStickCode 순서, -1.0 ~ 1.0)
  - returns Vec<f64>
- `pub fn create(index: usize, id: &str) -> Gamepad` (static, since 0.3.2): 생성. (버튼 17개는 뗀 상태, 축 4개는 0)
  - `index` usize: 하드웨어 식별 번호. (update_all_gamepads_with_list 에 넘기는 목록의 번호와 같게)
  - `id` &str: 장치 이름.
  - returns Gamepad: 연결된(connected 가 true) 패드 사본.

## GamepadManager (struct) (Default)

게임패드 관리자.
- InputManager 가 하나 들고 tick 에서 폴링한다. 씬은 engine.get_input_manager().get_gamepad_manager() 로 읽는다. (패드 목록 읽기는 그 자리에서 읽어 get_gamepad_manager_mut)

예제: 콜백으로 버튼 변화 받기

```rust
use std::cell::RefCell;
use std::rc::Rc;
use vanilla::{Gamepad, GamepadButton, GamepadButtonCode, GamepadInputType, GamepadManager};

let event_list = Rc::new(RefCell::new(Vec::new()));
let callback_event_list = event_list.clone();
let mut gamepad_manager = GamepadManager::new();
gamepad_manager.set_log_enabled(false);
gamepad_manager.set_callback(Some(Box::new(move |gamepad_index, input_type, input_index, value| {
	callback_event_list.borrow_mut().push((gamepad_index, input_type, input_index, value));
})));
let mut gamepad = Gamepad::create(0, "Test Pad");
gamepad.buttons[GamepadButtonCode::A_CROSS] = GamepadButton { pressed: true, value: 1.0 };
gamepad_manager.update_all_gamepads_with_list(vec![Some(gamepad)]);
assert_eq!(gamepad_manager.get_connected_gamepad_count(), 1);
assert_eq!(event_list.borrow()[0], (0, GamepadInputType::Button, GamepadButtonCode::A_CROSS, 1.0));
```

예제: 씬에서 첫 패드의 단추와 스틱 읽기

```rust
use vanilla::{Engine, GamepadAnalogStickCode, GamepadButtonCode};

fn read_first_gamepad(engine: &Engine) {
	let mut input_manager = engine.get_input_manager_mut();
	let mut gamepad_manager = input_manager.get_gamepad_manager_mut();
	let gamepad_index = match gamepad_manager.get_connected_gamepad(0) {
		Some(gamepad) => {
			gamepad.index
		}
		None => {
			return;
		}
	};
	if gamepad_manager.is_button_just_pressed(gamepad_index, GamepadButtonCode::A_CROSS) {
		println!("confirm");
	}
	let stick_x = gamepad_manager.get_axis_value(gamepad_index, GamepadAnalogStickCode::LEFT_X);
	println!("{}", stick_x);
}
```

- `pub fn new() -> GamepadManager` (constructor, since 0.3.2): 생성.
  - 로그는 켜고 입력 로그는 끈 채 시작한다. 장치(gilrs)는 처음 부를 때 연다.
  - returns GamepadManager: 연결된 패드가 없는 관리자.
- `pub fn tick(&mut self, _time_delta: f64)` (method, since 0.3.2): 갱신.
  - update_all_gamepads 를 부른다.
  - `_time_delta` f64: 지난 프레임 뒤로 흐른 초. (쓰지 않는다)
- `pub fn connect(&mut self, gamepad: &Gamepad)` (method, since 0.3.2): 게임패드 연결.
  - 상태 칸을 그 패드의 버튼, 축 수만큼 뗀 상태와 0 으로 만든다. 로그가 켜져 있으면 연결 로그를 낸다.
  - `gamepad` &Gamepad: 붙일 패드. (같은 index 가 이미 붙어 있으면 건너뛴다)
- `pub fn disconnect(&mut self, gamepad: &Gamepad)` (method, since 0.3.2): 게임패드 연결 해제.
  - `gamepad` &Gamepad: 뗄 패드. (index 로 찾는다, 붙어 있지 않으면 건너뛴다)
- `pub fn set_callback(&mut self, callback: Option<GamepadInputCallback>)` (method, since 0.3.2): 콜백 설정. (None 이면 끈다)
  - `callback` Option<GamepadInputCallback>: 갱신 중 입력이 바뀔 때마다 부를 함수. (gamepad_index 는 Gamepad.index, 버튼 눌림은 Button 과 1.0 / 0.0, 아날로그 값은 Value, 축은 Axis)
- `pub fn set_log_enabled(&mut self, is_enabled: bool)` (method, since 0.3.2): 로그 켜고 끄기. (러스트 판에서 더한 것. 기본은 원본처럼 켜짐)
  - `is_enabled` bool: 연결, 해제, 입력 로그를 모두 내려면 true.
- `pub fn set_input_log_enabled(&mut self, is_enabled: bool)` (method, since 0.4.0): 단추와 축이 바뀔 때마다 로그를 낼지. (기본은 끔, set_log_enabled 가 꺼져 있으면 켜도 내지 않는다)
  - `is_enabled` bool: 입력 로그를 내려면 true.
- `pub fn is_input_log_enabled(&self) -> bool` (method, since 0.4.0): 단추와 축이 바뀔 때마다 로그를 내는지.
  - returns bool: 입력 로그를 켰으면 true. (set_log_enabled 는 보지 않는다)
- `pub fn get_active_gamepad_id(&self) -> Option<&str>` (method, since 0.4.0): 마지막 갱신에 단추를 누르거나 축을 0.5 넘게 기울인 패드의 이름. (없으면 None, 마지막으로 쓴 장치를 가릴 때)
  - returns Option<&str>: 그 패드의 Gamepad.id. 마지막 갱신에 새로 누른 단추나 0.5 를 새로 넘긴 축이 없으면 None. (누른 채 두면 다음 갱신에 None)
- `pub fn vibrate(&mut self, strong_magnitude: f64, weak_magnitude: f64, seconds: f64)` (method, since 0.4.0): 연결된 패드를 모두 떨기. (세기는 0 ~ 1, 무거운 모터와 가벼운 모터, 초)
  - 데스크탑은 gilrs force feedback(macOS 는 GameController 와 CoreHaptics), 웹은 Gamepad.vibrationActuator 의 dual-rumble. 진동을 대지 않는 패드는 건너뛴다.
  - `strong_magnitude` f64: 무거운(낮은 주파수) 모터 세기. (0 ~ 1 로 자르고, 수가 아니면 0)
  - `weak_magnitude` f64: 가벼운(높은 주파수) 모터 세기. (0 ~ 1 로 자르고, 수가 아니면 0)
  - `seconds` f64: 떠는 길이. (초, 음수나 수가 아니면 0, 밀리초로 반올림한다)

  예제: 맞았을 때 0.2 초 떨기

  ```rust
  use vanilla::Engine;
  
  fn shake_on_hit(engine: &Engine) {
  	let mut input_manager = engine.get_input_manager_mut();
  	let mut gamepad_manager = input_manager.get_gamepad_manager_mut();
  	gamepad_manager.vibrate(1.0, 0.5, 0.2);
  }
  ```

- `pub fn update_all_gamepads(&mut self)` (method, since 0.3.2): 모든 게임패드 갱신. (gilrs 를 읽어 update_all_gamepads_with_list 로 넘긴다)
- `pub fn update_all_gamepads_with_list(&mut self, gamepad_list: Vec<Option<Gamepad>>)` (method, since 0.3.2): 주어진 목록으로 모든 게임패드 갱신. (원본 updateAllGamepads 의 본문, 목록 번호가 index)
  - gilrs 없이 상태를 넣을 때 쓴다. (시험, 다른 입력원)
  - 목록에 새로 나타난 패드는 붙이고 사라진 패드는 놓는다. 값은 소수점 둘째 자리로 반올림하고 바뀐 것만 콜백에 알린다.
  - `gamepad_list` Vec<Option<Gamepad>>: 패드 목록. (번호가 Gamepad.index, 빈 자리는 None, navigator.getGamepads() 와 같은 꼴)

  예제: 둘째 자리에 패드를 넣었다가 빼기

  ```rust
  use vanilla::{Gamepad, GamepadManager};
  
  let mut gamepad_manager = GamepadManager::new();
  gamepad_manager.set_log_enabled(false);
  let gamepad = Gamepad::create(1, "Second Pad");
  gamepad_manager.update_all_gamepads_with_list(vec![None, Some(gamepad)]);
  assert_eq!(gamepad_manager.get_connected_gamepad_count(), 1);
  assert_eq!(gamepad_manager.get_all_connected_gamepads()[0].id, "Second Pad");
  gamepad_manager.update_all_gamepads_with_list(Vec::new());
  assert_eq!(gamepad_manager.get_connected_gamepad_count(), 0);
  ```

- `pub fn is_button_pressed(&self, gamepad_index: usize, button_index: usize) -> bool` (method, since 0.3.2): 버튼 눌림 상태 반환.
  - `gamepad_index` usize: 패드의 하드웨어 식별 번호. (Gamepad.index, 연결 목록의 순번이 아니다)
  - `button_index` usize: 버튼 번호. (GamepadButtonCode)
  - returns bool: 눌린 채면 true. 패드가 붙어 있지 않거나 버튼 번호가 없으면 false.
- `pub fn is_button_just_pressed(&self, gamepad_index: usize, button_index: usize) -> bool` (method, since 0.3.2): 이번 갱신에 방금 눌린 버튼인지. (원본 isButtonJustPressed, 키보드 is_key_just_pressed 와 같은 쓰임)
  - `gamepad_index` usize: 패드의 하드웨어 식별 번호. (Gamepad.index, 연결 목록의 순번이 아니다)
  - `button_index` usize: 버튼 번호. (GamepadButtonCode)
  - returns bool: 지난 갱신에 떼어 있다가 이번 갱신에 눌렸으면 true. 패드나 버튼이 없으면 false.
- `pub fn is_button_just_released(&self, gamepad_index: usize, button_index: usize) -> bool` (method, since 0.3.2): 이번 갱신에 방금 떼어진 버튼인지. (원본 isButtonJustReleased)
  - `gamepad_index` usize: 패드의 하드웨어 식별 번호. (Gamepad.index, 연결 목록의 순번이 아니다)
  - `button_index` usize: 버튼 번호. (GamepadButtonCode)
  - returns bool: 지난 갱신에 눌려 있다가 이번 갱신에 떼어졌으면 true. 패드나 버튼이 없으면 false.
- `pub fn get_button_value(&self, gamepad_index: usize, button_index: usize) -> f64` (method, since 0.3.2): 버튼/트리거 아날로그 값 반환. (0.0 ~ 1.0)
  - `gamepad_index` usize: 패드의 하드웨어 식별 번호. (Gamepad.index, 연결 목록의 순번이 아니다)
  - `button_index` usize: 버튼 번호. (GamepadButtonCode)
  - returns f64: 소수점 둘째 자리로 반올림한 값. 패드나 버튼이 없으면 0.0.
- `pub fn get_axis_value(&self, gamepad_index: usize, axis_index: usize) -> f64` (method, since 0.3.2): 아날로그 스틱 축 값 반환. (-1.0 ~ 1.0)
  - 0.01 넘게 바뀐 때만 새 값을 받는다. 죽은 구역은 빼지 않는다. (InputActions 가 뺀다)
  - `gamepad_index` usize: 패드의 하드웨어 식별 번호. (Gamepad.index)
  - `axis_index` usize: 축 번호. (GamepadAnalogStickCode, 세로 축은 아래가 양수)
  - returns f64: 소수점 둘째 자리로 반올림한 값. 패드나 축이 없거나 NaN 이면 0.0.
- `pub fn get_all_connected_gamepads(&self) -> Vec<Gamepad>` (method, since 0.3.2): 연결된 모든 게임패드 반환. (원본 navigator.getGamepads() 처럼 그 자리에서 읽은 지금 상태의 사본)
  - returns Vec<Gamepad>: 붙은 차례의 패드 사본 목록. 없으면 빈 목록.
- `pub fn get_connected_gamepad_count(&self) -> usize` (method, since 0.3.2): 연결된 게임패드 수 반환.
  - returns usize: 붙어 있는 패드 수.
- `pub fn get_connected_gamepad(&self, gamepad_index: usize) -> Option<Gamepad>` (method, since 0.3.2): 연결된 게임패드 반환. (gamepad_index 는 연결 목록의 순번, 0 ~ get_connected_gamepad_count() - 1)
  - `gamepad_index` usize: 연결 목록의 순번. (붙은 차례, Gamepad.index 가 아니다)
  - returns Option<Gamepad>: 그 자리에서 읽은 패드의 사본. 순번이 범위를 넘거나 그 패드가 지금 목록에 없으면 None.

## Functions and constants

- `pub fn read_gamepad_kind(gamepad_id: &str) -> GamepadKind` (method, since 0.4.0): 패드 이름으로 종류 가르기. (플레이스테이션 054c, 닌텐도 057e, 엑스박스 045e 와 이름, 모르면 Other)
  - 대소문자를 가리지 않고 플레이스테이션, 닌텐도, 엑스박스 차례로 본다.
  - `gamepad_id` &str: 패드 이름. (Gamepad.id)
  - returns GamepadKind: 이름에 든 제조사 번호나 흔한 이름으로 가른 종류. 맞는 것이 없으면 Other.

  예제: 브라우저와 데스크탑 꼴 이름 가르기

  ```rust
  use vanilla::{read_gamepad_kind, GamepadKind};
  
  let dual_sense_id = "DualSense Wireless Controller (STANDARD GAMEPAD Vendor: 054c Product: 0ce6)";
  assert_eq!(read_gamepad_kind(dual_sense_id), GamepadKind::PlayStation);
  assert_eq!(read_gamepad_kind("Xbox 360 Controller (XInput STANDARD GAMEPAD)"), GamepadKind::Xbox);
  assert_eq!(read_gamepad_kind("Steam Virtual Gamepad"), GamepadKind::Other);
  ```

## GamepadKind (enum) (Clone, Copy, Debug, PartialEq, Eq, Hash)

게임패드 종류. (단추 안내를 그 패드의 표기로 보일 때 쓴다)

- `Xbox`: 엑스박스 패드. (이름에 045e, xbox, xinput, microsoft)
- `PlayStation`: 플레이스테이션 패드. (이름에 054c, playstation, dualshock, dualsense, sony)
- `Nintendo`: 닌텐도 패드. (이름에 057e, nintendo, joy-con, pro controller)
- `Other`: 그 밖. (이름으로 가르지 못한 패드)

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

입력 종류. (원본 콜백의 input_type 문자열 "button" / "value" / "axis")

- `Button`: 눌림 변화. (값은 1.0 눌림, 0.0 뗌)
- `Value`: 버튼 아날로그 값 변화. (0 보다 클 때만 온다)
- `Axis`: 스틱 축 값 변화.
