Making anonymous mappings work

This commit is contained in:
Brad Davis 2015-10-12 17:59:01 -07:00
parent f77878ee79
commit 58d3578fb1
9 changed files with 47 additions and 8 deletions

View file

@ -1,5 +1,9 @@
#include "Mapping.h"
namespace controller {
Mapping::Mapping(const QString& name ) : _name(name) {
}
}

View file

@ -27,7 +27,10 @@ namespace controller {
using Map = std::map<Endpoint::Pointer, Route::List>;
using Pointer = std::shared_ptr<Mapping>;
Mapping(const QString& name);
Map _channelMappings;
const QString _name;
void parse(const QString& json);
QString serialize();

View file

@ -158,7 +158,7 @@ namespace controller {
qCWarning(controllers) << "Refusing to recreate mapping named " << mappingName;
}
qDebug() << "Creating new Mapping " << mappingName;
Mapping::Pointer mapping = std::make_shared<Mapping>();
auto mapping = std::make_shared<Mapping>(mappingName);
_mappingsByName[mappingName] = mapping;
return new MappingBuilderProxy(*this, mapping);
}

View file

@ -39,7 +39,7 @@ namespace controller {
Q_INVOKABLE float getValue(const int& source);
Q_INVOKABLE void update();
Q_INVOKABLE QObject* newMapping(const QString& mappingName);
Q_INVOKABLE QObject* newMapping(const QString& mappingName = QUuid::createUuid().toString());
Q_INVOKABLE void enableMapping(const QString& mappingName, bool enable = true);
Q_INVOKABLE void disableMapping(const QString& mappingName) {
enableMapping(mappingName, false);

View file

@ -41,4 +41,9 @@ QObject* MappingBuilderProxy::join(const QJSValue& source1, const QJSValue& sour
return from(_parent.compositeEndpointFor(source1Endpoint, source2Endpoint));
}
QObject* MappingBuilderProxy::enable(bool enable) {
_parent.enableMapping(_mapping->_name, enable);
return this;
}
}

View file

@ -30,8 +30,10 @@ public:
Q_INVOKABLE QObject* from(const QJSValue& source);
Q_INVOKABLE QObject* from(const QScriptValue& source);
Q_INVOKABLE QObject* join(const QJSValue& source1, const QJSValue& source2);
Q_INVOKABLE QObject* enable(bool enable = true);
Q_INVOKABLE QObject* disable() { return enable(false); }
protected:
QObject* from(const Endpoint::Pointer& source);

View file

@ -2,7 +2,7 @@
set(TARGET_NAME controllers-test)
# This is not a testcase -- just set it up as a regular hifi project
setup_hifi_project(Script)
setup_hifi_project(Script Qml)
set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/")
# link in the shared libraries

View file

@ -11,7 +11,7 @@ Column {
property var xbox: NewControllers.Hardware.X360Controller1
property var actions: NewControllers.Actions
property var standard: NewControllers.Standard
property string mappingName: "TestMapping"
property var testMapping: null
spacing: 12
@ -55,7 +55,7 @@ Column {
Button {
text: "Build Mapping"
onClicked: {
var mapping = NewControllers.newMapping(root.mappingName);
var mapping = NewControllers.newMapping();
// Inverting a value
mapping.from(xbox.RY).invert().to(standard.RY);
// Assigning a value from a function
@ -63,17 +63,22 @@ Column {
// Constrainting a value to -1, 0, or 1, with a deadzone
mapping.from(xbox.LY).deadZone(0.5).constrainToInteger().to(standard.LY);
mapping.join(standard.LB, standard.RB).pulse(0.5).to(actions.Yaw);
mapping.from(actions.Yaw).clamp(0, 1).invert().to(actions.YAW_RIGHT);
mapping.from(actions.Yaw).clamp(-1, 0).to(actions.YAW_LEFT);
testMapping = mapping;
enabled = false
text = "Built"
}
}
Button {
text: "Enable Mapping"
onClicked: NewControllers.enableMapping(root.mappingName)
onClicked: root.testMapping.enable()
}
Button {
text: "Disable Mapping"
onClicked: NewControllers.disableMapping(root.mappingName)
onClicked: root.testMapping.disable()
}
}
@ -85,6 +90,7 @@ Column {
Row {
spacing: 8
ScrollingGraph {
controlId: NewControllers.Actions.Yaw
label: "Yaw"
@ -92,6 +98,22 @@ Column {
max: 3.0
size: 128
}
ScrollingGraph {
controlId: NewControllers.Actions.YAW_LEFT
label: "Yaw Left"
min: -3.0
max: 3.0
size: 128
}
ScrollingGraph {
controlId: NewControllers.Actions.YAW_RIGHT
label: "Yaw Right"
min: -3.0
max: 3.0
size: 128
}
}
}

View file

@ -82,6 +82,9 @@ public:
int main(int argc, char** argv) {
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
for (auto path : qApp->libraryPaths()) {
qDebug() << path;
}
{