diff --git a/examples/xbox.js b/examples/xbox.js index 9190ee23ac..603e0dbf56 100644 --- a/examples/xbox.js +++ b/examples/xbox.js @@ -10,8 +10,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -joysticks = Joysticks.availableJoystickNames; +gamepad = Joysticks.joystickWithName("Wireless 360 Controller"); -for (i = 0; i < joysticks.length; i++) { - print("Joystick " + i + " is " + joysticks[i]); -} \ No newline at end of file +function reportAxisValue(axis, newValue, oldValue) { + print("The value for axis " + axis + " has changed to " + newValue + ". It was " + oldValue); +} + +gamepad.axisValueChanged.connect(reportAxisValue); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c49a1e234a..25f2bd6817 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3766,6 +3766,14 @@ void Application::saveScripts() { _settings->endArray(); } +QScriptValue joystickToScriptValue(QScriptEngine *engine, Joystick* const &in) { + return engine->newQObject(in); +} + +void joystickFromScriptValue(const QScriptValue &object, Joystick* &out) { + out = qobject_cast(object.toQObject()); +} + ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUserLoaded, bool loadScriptFromEditor, bool activateMainWindow) { QUrl scriptUrl(scriptFilename); @@ -3850,6 +3858,7 @@ ScriptEngine* Application::loadScript(const QString& scriptFilename, bool isUser scriptEngine->registerGlobalObject("AvatarManager", &_avatarManager); scriptEngine->registerGlobalObject("Joysticks", &JoystickScriptingInterface::getInstance()); + qScriptRegisterMetaType(scriptEngine, joystickToScriptValue, joystickFromScriptValue); #ifdef HAVE_RTMIDI scriptEngine->registerGlobalObject("MIDI", &MIDIManager::getInstance());