Prevent inserting the same key multiple times into an input action

This commit is contained in:
2023-10-17 19:54:32 +02:00
parent 5b404efa74
commit aa7eade85e
2 changed files with 26 additions and 0 deletions

View File

@@ -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);
}
};

View File

@@ -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);
}
};
}