mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
core/sys/wasm/js: improve gamepad API
1. Properly set `id` and `mapping` on the `get_gamepad_state` result 2. Increase `id` limit to 96 bytes, connecting my DualShock 4 made it crash 3. If an `id` or `mapping` is longer than the limits, slice it and add `...`
This commit is contained in:
@@ -189,7 +189,7 @@ Key_Location :: enum u8 {
|
||||
KEYBOARD_MAX_KEY_SIZE :: 32
|
||||
KEYBOARD_MAX_CODE_SIZE :: 32
|
||||
|
||||
GAMEPAD_MAX_ID_SIZE :: 64
|
||||
GAMEPAD_MAX_ID_SIZE :: 96
|
||||
GAMEPAD_MAX_MAPPING_SIZE :: 64
|
||||
|
||||
GAMEPAD_MAX_BUTTONS :: 64
|
||||
@@ -384,7 +384,14 @@ get_gamepad_state :: proc "contextless" (index: int, s: ^Gamepad_State) -> bool
|
||||
if s == nil {
|
||||
return false
|
||||
}
|
||||
return _get_gamepad_state(index, s)
|
||||
|
||||
if !_get_gamepad_state(index, s) {
|
||||
return false
|
||||
}
|
||||
|
||||
s.id = string(s._id_buf[:s._id_len])
|
||||
s.mapping = string(s._mapping_buf[:s._mapping_len])
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -415,4 +422,4 @@ do_event_callback :: proc(user_data: rawptr, callback: proc(e: Event)) {
|
||||
|
||||
callback(event)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user