From c626ce58092cff0aafd2feb4c3b3570b80595399 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Thu, 26 Feb 2015 00:41:59 +0100 Subject: [PATCH] Do not fail to evaluate an expression if some input is missing My keyboard layout does not have Alt_R but ISO_Level3_Shift. As a consequence any control expression containing Alt_R fails to evaluate completely and is unusable. This modification replace the missing term of the expression by a dummy expression which always evaluate to 0. This way, the keybinding can work even if some keys are not available. --- .../ControllerInterface/ExpressionParser.cpp | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp b/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp index 8c9060e69c..b49d4b8dce 100644 --- a/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp +++ b/Source/Core/InputCommon/ControllerInterface/ExpressionParser.cpp @@ -219,6 +219,33 @@ public: virtual operator std::string() { return ""; } }; +class DummyExpression : public ExpressionNode +{ +public: + std::string name; + + DummyExpression(const std::string& name_) : name(name_) {} + + ControlState GetValue() override + { + return 0.0; + } + + void SetValue(ControlState value) override + { + } + + int CountNumControls() override + { + return 0; + } + + operator std::string() override + { + return "`" + name + "`"; + } +}; + class ControlExpression : public ExpressionNode { public: @@ -416,7 +443,10 @@ private: { Device::Control *control = finder.FindControl(tok.qualifier); if (control == nullptr) - return EXPRESSION_PARSE_NO_DEVICE; + { + *expr_out = new DummyExpression(tok.qualifier); + return EXPRESSION_PARSE_SUCCESS; + } *expr_out = new ControlExpression(tok.qualifier, control); return EXPRESSION_PARSE_SUCCESS;