| 130 | } |
| 131 | |
| 132 | void InputManager::configure(vili::node& config) |
| 133 | { |
| 134 | std::vector<std::string> alreadyInFile; |
| 135 | for (auto& [contextName, context] : config.items()) |
| 136 | { |
| 137 | for (auto& [actionName, condition] : context.items()) |
| 138 | { |
| 139 | if (!this->actionExists(actionName)) |
| 140 | { |
| 141 | m_allActions.push_back( |
| 142 | std::make_unique<InputAction>(t_actions.get(), actionName)); |
| 143 | } |
| 144 | else if (!Utils::Vector::contains(actionName, alreadyInFile)) |
| 145 | { |
| 146 | this->getAction(actionName).clearConditions(); |
| 147 | } |
| 148 | auto inputCondition |
| 149 | = [this](InputManager* inputManager, const std::string& action, |
| 150 | vili::node& condition) { |
| 151 | InputCondition actionCondition; |
| 152 | InputCombination combination; |
| 153 | try |
| 154 | { |
| 155 | combination = this->makeCombination(condition); |
| 156 | } |
| 157 | catch (const Exception& e) |
| 158 | { |
| 159 | throw Exceptions::InvalidInputCombinationCode( |
| 160 | action, condition, EXC_INFO) |
| 161 | .nest(e); |
| 162 | } |
| 163 | |
| 164 | actionCondition.setCombination(combination); |
| 165 | Debug::Log->debug( |
| 166 | "<InputManager> Associated Key '{0}' for Action '{1}'", |
| 167 | condition, action); |
| 168 | inputManager->getAction(action).addCondition(actionCondition); |
| 169 | }; |
| 170 | if (condition.is_primitive()) |
| 171 | { |
| 172 | inputCondition(this, actionName, condition); |
| 173 | } |
| 174 | else if (condition.is<vili::array>()) |
| 175 | { |
| 176 | for (vili::node& singleCondition : condition) |
| 177 | { |
| 178 | inputCondition(this, actionName, singleCondition); |
| 179 | } |
| 180 | } |
| 181 | this->getAction(actionName).addContext(contextName); |
| 182 | alreadyInFile.push_back(actionName); |
| 183 | } |
| 184 | } |
| 185 | // Add Context keys in real time <REVISION> |
| 186 | } |
| 187 | |
| 188 | void InputManager::clearContexts() |
| 189 | { |
no test coverage detected