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:
Laytan Laats
2025-03-12 18:32:51 +01:00
parent d3b1aaad18
commit d349c96071
2 changed files with 46 additions and 11 deletions
+10 -3
View File
@@ -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)
}
}
}