Scripting: Expose gamepad name to scripts

This commit is contained in:
Vicki Pfau 2023-01-26 21:38:47 -08:00
parent a62a3eb811
commit c0d4e2c347
4 changed files with 12 additions and 0 deletions

View File

@ -220,6 +220,9 @@ struct mScriptTriggerEvent {
struct mScriptGamepad {
unsigned pad;
char visibleName[128];
char internalName[64];
struct mScriptList axes;
struct mScriptList buttons;
struct mScriptList hats;

View File

@ -13,6 +13,7 @@ function readPad()
local buttons = gamepad.buttons
local hats = gamepad.hats
inputBuffer:print(gamepad.visibleName .. "\n")
inputBuffer:print(string.format("%i buttons, %i axes, %i hats\n", #buttons, #axes, #hats))
local sbuttons = {}

View File

@ -21,6 +21,7 @@
#include <mgba/script/input.h>
#include <mgba-util/math.h>
#include <mgba-util/string.h>
using namespace QGBA;
@ -237,6 +238,11 @@ void ScriptingController::updateGamepad() {
detachGamepad();
return;
}
QString name = gamepad->name();
strlcpy(m_gamepad.internalName, name.toUtf8().constData(), sizeof(m_gamepad.internalName));
name = gamepad->visibleName();
strlcpy(m_gamepad.visibleName, name.toUtf8().constData(), sizeof(m_gamepad.visibleName));
attachGamepad();
QList<bool> buttons = gamepad->currentButtons();

View File

@ -95,6 +95,8 @@ mSCRIPT_DEFINE_STRUCT(mScriptGamepadHatEvent)
mSCRIPT_DEFINE_END;
mSCRIPT_DEFINE_STRUCT(mScriptGamepad)
mSCRIPT_DEFINE_STRUCT_MEMBER(mScriptGamepad, CHARP, visibleName)
mSCRIPT_DEFINE_STRUCT_MEMBER(mScriptGamepad, CHARP, internalName)
mSCRIPT_DEFINE_STRUCT_MEMBER(mScriptGamepad, LIST, axes)
mSCRIPT_DEFINE_STRUCT_MEMBER(mScriptGamepad, LIST, buttons)
mSCRIPT_DEFINE_STRUCT_MEMBER(mScriptGamepad, LIST, hats)