diff --git a/examples/controllers/controllerMappings.js b/examples/controllers/controllerMappings.js index e4ef0270ab..959dc1b0ca 100644 --- a/examples/controllers/controllerMappings.js +++ b/examples/controllers/controllerMappings.js @@ -14,7 +14,7 @@ myFirstMapping = function() { return { - "name": "example mapping from Standard to actions", + "name": "example", "channels": [ { "from": "Keyboard.A", "filters": [ { @@ -56,6 +56,8 @@ print('myFirstMappingJSON' + JSON.stringify(myFirstMappingJSON)); var mapping = Controller.parseMapping(JSON.stringify(myFirstMappingJSON)); +Controller.enableMapping("example"); + Object.keys(Controller.Standard).forEach(function (input) { print("Controller.Standard." + input + ":" + Controller.Standard[input]); }); diff --git a/libraries/controllers/src/controllers/ScriptingInterface.cpp b/libraries/controllers/src/controllers/ScriptingInterface.cpp index d0c40fe3c0..e91e627f16 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.cpp +++ b/libraries/controllers/src/controllers/ScriptingInterface.cpp @@ -94,6 +94,25 @@ namespace controller { Endpoint::Pointer _second; }; + class ActionEndpoint : public Endpoint { + public: + ActionEndpoint(const UserInputMapper::Input& id = UserInputMapper::Input(-1)) + : Endpoint(id) { + } + + virtual float value() override { return _currentValue; } + virtual void apply(float newValue, float oldValue, const Pointer& source) override { + + _currentValue = newValue; + if (!(_id == UserInputMapper::Input::INVALID_INPUT)) { + auto userInputMapper = DependencyManager::get(); + userInputMapper->setActionState(UserInputMapper::Action(_id.getChannel()), newValue); + } + } + + private: + float _currentValue{ 0.0f }; + }; QRegularExpression ScriptingInterface::SANITIZE_NAME_EXPRESSION{ "[\\(\\)\\.\\s]" }; @@ -139,7 +158,8 @@ namespace controller { // Create the endpoints // FIXME action endpoints need to accumulate values, and have them cleared at each frame - _endpoints[actionInput] = std::make_shared(); + // _endpoints[actionInput] = std::make_shared(); + _endpoints[actionInput] = std::make_shared(); } updateMaps(); @@ -171,6 +191,7 @@ namespace controller { _mappingsByName[mapping->_name] = mapping; + return mappingBuilder; } else { qDebug() << "Mapping json Document is not an object" << endl; } diff --git a/libraries/controllers/src/controllers/UserInputMapper.h b/libraries/controllers/src/controllers/UserInputMapper.h index c795442296..117fd163bf 100644 --- a/libraries/controllers/src/controllers/UserInputMapper.h +++ b/libraries/controllers/src/controllers/UserInputMapper.h @@ -214,6 +214,8 @@ public: QVector getActionNames() const; void assignDefaulActionScales(); + void setActionState(Action action, float value) { _actionStates[action] = value; } + // Add input channel to the mapper and check that all the used channels are registered. // Return true if theinput channel is created correctly, false either bool addInputChannel(Action action, const Input& input, float scale = 1.0f);