mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-13 03:52:45 +02:00
implement StandardController and expose it to JS as Controller.Standard.*
This commit is contained in:
parent
83bf8c8742
commit
0986f86c34
4 changed files with 48 additions and 3 deletions
|
@ -11,14 +11,19 @@
|
|||
|
||||
// Assumes you only have the default keyboard connected
|
||||
|
||||
|
||||
Object.keys(Controller.Standard).forEach(function (input) {
|
||||
print("Controller.Standard." + input + ":" + Controller.Standard[input]);
|
||||
});
|
||||
|
||||
Object.keys(Controller.Hardware).forEach(function (deviceName) {
|
||||
Object.keys(Controller.Hardware[deviceName]).forEach(function (input) {
|
||||
print(deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]);
|
||||
print("Controller.Hardware." + deviceName + "." + input + ":" + Controller.Hardware[deviceName][input]);
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(Controller.Actions).forEach(function (actionName) {
|
||||
print(actionName + ":" + Controller.Actions[actionName]);
|
||||
print("Controller.Actions." + actionName + ":" + Controller.Actions[actionName]);
|
||||
});
|
||||
|
||||
// Resets every device to its default key bindings:
|
||||
|
|
|
@ -391,6 +391,19 @@ QString ControllerScriptingInterface::sanatizeName(const QString& name) {
|
|||
|
||||
void ControllerScriptingInterface::wireUpControllers(ScriptEngine* engine) {
|
||||
|
||||
// Controller.Standard.*
|
||||
auto standardDevice = DependencyManager::get<UserInputMapper>()->getStandardDevice();
|
||||
if (standardDevice) {
|
||||
auto deviceName = sanatizeName(standardDevice->getName());
|
||||
auto deviceInputs = standardDevice->getAvailabeInputs();
|
||||
for (const auto& inputMapping : deviceInputs) {
|
||||
auto input = inputMapping.first;
|
||||
auto inputName = sanatizeName(inputMapping.second);
|
||||
QString deviceInputName{ "Controller." + deviceName + "." + inputName };
|
||||
engine->registerValue(deviceInputName, input.getID());
|
||||
}
|
||||
}
|
||||
|
||||
// Controller.Hardware.*
|
||||
auto devices = DependencyManager::get<UserInputMapper>()->getDevices();
|
||||
for(const auto& deviceMapping : devices) {
|
||||
|
|
|
@ -10,13 +10,20 @@
|
|||
//
|
||||
|
||||
#include "UserInputMapper.h"
|
||||
#include "StandardController.h"
|
||||
|
||||
// Default contruct allocate the poutput size with the current hardcoded action channels
|
||||
UserInputMapper::UserInputMapper() {
|
||||
registerStandardDevice();
|
||||
assignDefaulActionScales();
|
||||
createActionNames();
|
||||
}
|
||||
|
||||
UserInputMapper::~UserInputMapper() {
|
||||
delete _standardController;
|
||||
}
|
||||
|
||||
|
||||
bool UserInputMapper::registerDevice(uint16 deviceID, const DeviceProxy::Pointer& proxy){
|
||||
proxy->_name += " (" + QString::number(deviceID) + ")";
|
||||
_registeredDevices[deviceID] = proxy;
|
||||
|
@ -322,3 +329,11 @@ void UserInputMapper::createActionNames() {
|
|||
_actionNames[CONTEXT_MENU] = "CONTEXT_MENU";
|
||||
_actionNames[TOGGLE_MUTE] = "TOGGLE_MUTE";
|
||||
}
|
||||
|
||||
void UserInputMapper::registerStandardDevice() {
|
||||
_standardController = new StandardController;
|
||||
_standardController->registerToUserInputMapper(*this);
|
||||
|
||||
//mapper.registerDevice(_deviceID, proxy);
|
||||
//_standardDevice = proxy;
|
||||
}
|
|
@ -19,13 +19,16 @@
|
|||
#include <memory>
|
||||
#include <DependencyManager.h>
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
|
||||
class StandardController;
|
||||
|
||||
class UserInputMapper : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
SINGLETON_DEPENDENCY
|
||||
Q_ENUMS(Action)
|
||||
public:
|
||||
~UserInputMapper();
|
||||
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint32;
|
||||
|
||||
|
@ -123,6 +126,7 @@ public:
|
|||
// GetFreeDeviceID should be called before registering a device to use an ID not used by a different device.
|
||||
uint16 getFreeDeviceID() { return _nextFreeDeviceID++; }
|
||||
bool registerDevice(uint16 deviceID, const DeviceProxy::Pointer& device);
|
||||
bool registerStandardDevice(const DeviceProxy::Pointer& device) { _standardDevice = device; return true; }
|
||||
DeviceProxy::Pointer getDeviceProxy(const Input& input);
|
||||
QString getDeviceName(uint16 deviceID);
|
||||
QVector<InputPair> getAvailableInputs(uint16 deviceID) { return _registeredDevices[deviceID]->getAvailabeInputs(); }
|
||||
|
@ -238,11 +242,19 @@ public:
|
|||
typedef std::map<int, DeviceProxy::Pointer> DevicesMap;
|
||||
DevicesMap getDevices() { return _registeredDevices; }
|
||||
|
||||
uint16 getStandardDeviceID() const { return _standardDeviceID; }
|
||||
DeviceProxy::Pointer getStandardDevice() { return _standardDevice; }
|
||||
|
||||
signals:
|
||||
void actionEvent(int action, float state);
|
||||
|
||||
|
||||
protected:
|
||||
void registerStandardDevice();
|
||||
uint16 _standardDeviceID = 0;
|
||||
DeviceProxy::Pointer _standardDevice;
|
||||
StandardController* _standardController = nullptr;
|
||||
|
||||
DevicesMap _registeredDevices;
|
||||
uint16 _nextFreeDeviceID = 1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue