From aa7eade85ed8dc6b74a6ac46b180b88c56d26c1b Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Tue, 17 Oct 2023 19:54:32 +0200 Subject: [PATCH] Prevent inserting the same key multiple times into an input action --- openVulkanoCpp/Input/InputAction.hpp | 16 ++++++++++++++++ openVulkanoCpp/Input/InputKey.hpp | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/openVulkanoCpp/Input/InputAction.hpp b/openVulkanoCpp/Input/InputAction.hpp index 7e97e35..b4b1ab9 100644 --- a/openVulkanoCpp/Input/InputAction.hpp +++ b/openVulkanoCpp/Input/InputAction.hpp @@ -53,11 +53,27 @@ namespace OpenVulkano::Input void BindKey(InputKey key, float scale = 1) { + for (auto& binding : keys) + { + if (binding.key == key) + { + binding.scale = scale; + return; + } + } keys.emplace_back(key, scale); } void BindAxisButtons(InputKey keyPositive, InputKey keyNegative, float scale = 1) { + for (auto& binding : axisButtons) + { + if (binding.positive == keyPositive && binding.negative == keyNegative) + { + binding.scale = scale; + return; + } + } axisButtons.emplace_back(keyPositive, keyNegative, scale); } }; diff --git a/openVulkanoCpp/Input/InputKey.hpp b/openVulkanoCpp/Input/InputKey.hpp index 90743da..d74df4c 100644 --- a/openVulkanoCpp/Input/InputKey.hpp +++ b/openVulkanoCpp/Input/InputKey.hpp @@ -309,5 +309,15 @@ namespace OpenVulkano::Input [[nodiscard]] InputType GetInputType() const { return type; } [[nodiscard]] int16_t GetInputKey() const { return key; } + + bool operator==(const InputKey& other) + { + return deviceType == other.deviceType && type == other.type && key == other.key; + } + + bool operator!=(const InputKey& other) + { + return !(*this == other); + } }; }