Merge pull request #6255 from samcake/controllers

Controllers : Adding support for  'NOT' ito the conditional endpoint
This commit is contained in:
Brad Davis 2015-11-02 16:03:52 -08:00
commit 5d957e6535
3 changed files with 48 additions and 9 deletions

View file

@ -26,6 +26,7 @@
#include "Logging.h"
#include "impl/conditionals/AndConditional.h"
#include "impl/conditionals/NotConditional.h"
#include "impl/conditionals/EndpointConditional.h"
#include "impl/conditionals/ScriptConditional.h"
@ -826,13 +827,31 @@ Conditional::Pointer UserInputMapper::parseConditional(const QJsonValue& value)
return std::make_shared<AndConditional>(children);
} else if (value.isString()) {
// Support "when" : "GamePad.RB"
auto input = findDeviceInput(value.toString());
auto conditionalToken = value.toString();
// Detect for modifier case (Not...)
QString conditionalModifier;
const QString JSON_CONDITIONAL_MODIFIER_NOT("!");
if (conditionalToken.startsWith(JSON_CONDITIONAL_MODIFIER_NOT)) {
conditionalModifier = JSON_CONDITIONAL_MODIFIER_NOT;
conditionalToken = conditionalToken.right(conditionalToken.size() - conditionalModifier.size());
}
auto input = findDeviceInput(conditionalToken);
auto endpoint = endpointFor(input);
if (!endpoint) {
return Conditional::Pointer();
}
auto conditional = std::make_shared<EndpointConditional>(endpoint);
return std::make_shared<EndpointConditional>(endpoint);
if (!conditionalModifier.isEmpty()) {
if (conditionalModifier == JSON_CONDITIONAL_MODIFIER_NOT) {
return std::make_shared<NotConditional>(conditional);
}
}
// Default and conditional behavior
return conditional;
}
return Conditional::parse(value);

View file

@ -6,10 +6,16 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// NOTE: we don't need to include this header unless/until we add additional symbols.
// By removing this header we prevent these warnings on windows:
//
// warning LNK4221: This object file does not define any previously undefined public symbols,
// so it will not be used by any link operation that consumes this library
//
//#include "NotConditional.h"
#include "NotConditional.h"
using namespace controller;
bool NotConditional::satisfied() {
if (_operand) {
return (!_operand->satisfied());
} else {
return false;
}
}

View file

@ -12,5 +12,19 @@
#include "../Conditional.h"
namespace controller {
class NotConditional : public Conditional {
public:
using Pointer = std::shared_ptr<NotConditional>;
NotConditional(Conditional::Pointer operand) : _operand(operand) { }
virtual bool satisfied() override;
private:
Conditional::Pointer _operand;
};
}
#endif