Prevent inserting the same key multiple times into an input action
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user