Add convenience getters

This commit is contained in:
Georg Hagen
2025-08-21 23:56:11 +02:00
parent 19e85b86c9
commit 64459b7a93
2 changed files with 50 additions and 7 deletions

View File

@@ -61,7 +61,7 @@ namespace OpenVulkano::Input
return value; return value;
} }
bool InputManager::GetButton(InputAction* action) const bool InputManager::GetButton(const InputAction* action) const
{ {
const std::vector<InputDevice*>& testDevices = action->GetDevices().empty() ? devices : action->GetDevices(); const std::vector<InputDevice*>& testDevices = action->GetDevices().empty() ? devices : action->GetDevices();
for (const InputDevice* device : testDevices) for (const InputDevice* device : testDevices)
@@ -75,7 +75,7 @@ namespace OpenVulkano::Input
return false; return false;
} }
bool InputManager::GetButtonDown(InputAction* action) const bool InputManager::GetButtonDown(const InputAction* action) const
{ {
const std::vector<InputDevice*>& testDevices = action->GetDevices().empty() ? devices : action->GetDevices(); const std::vector<InputDevice*>& testDevices = action->GetDevices().empty() ? devices : action->GetDevices();
for (const InputDevice* device : testDevices) for (const InputDevice* device : testDevices)
@@ -92,6 +92,23 @@ namespace OpenVulkano::Input
return false; return false;
} }
bool InputManager::GetButtonUp(const InputAction* action) const
{
const std::vector<InputDevice*>& testDevices = action->GetDevices().empty() ? devices : action->GetDevices();
for (const InputDevice* device : testDevices)
{
for (const KeyBinding binding : action->GetKeys())
{
if (binding.key.GetInputDeviceType() != device->GetType())
{
continue;
}
return device->GetButtonUp(binding.key);
}
}
return false;
}
bool InputManager::GetButton(InputKey key) const bool InputManager::GetButton(InputKey key) const
{ {
for(const InputDevice* device : devices) for(const InputDevice* device : devices)
@@ -102,6 +119,26 @@ namespace OpenVulkano::Input
return false; return false;
} }
bool InputManager::GetButtonUp(InputKey key) const
{
for(const InputDevice* device : devices)
{
if (key.GetInputDeviceType() != device->GetType()) continue;
return device->GetButtonUp(key);
}
return false;
}
bool InputManager::GetButtonDown(InputKey key) const
{
for(const InputDevice* device : devices)
{
if (key.GetInputDeviceType() != device->GetType()) continue;
return device->GetButtonDown(key);
}
return false;
}
InputDevice* InputManager::GetDevice(InputDeviceType type) const InputDevice* InputManager::GetDevice(InputDeviceType type) const
{ {
if (type == InputDeviceType::UNKNOWN) if (type == InputDeviceType::UNKNOWN)

View File

@@ -35,16 +35,22 @@ namespace OpenVulkano::Input
[[nodiscard]] InputAction* GetAction(const std::string& actionName); [[nodiscard]] InputAction* GetAction(const std::string& actionName);
[[nodiscard]] float GetAxis(const InputAction& action) const { return GetAxis(&action); }
[[nodiscard]] float GetAxis(const InputAction* action) const; [[nodiscard]] float GetAxis(const InputAction* action) const;
[[nodiscard]] float GetAxis(InputKey key) const; [[nodiscard]] float GetAxis(InputKey key) const;
[[nodiscard]] bool GetButton(InputAction* action) const; [[nodiscard]] bool GetButton(const InputAction& action) const { return GetButton(&action); }
[[nodiscard]] bool GetButton(const InputAction* action) const;
[[nodiscard]] bool GetButtonDown(InputAction* action) const;
[[nodiscard]] bool GetButton(InputKey key) const; [[nodiscard]] bool GetButton(InputKey key) const;
[[nodiscard]] bool GetButtonUp(const InputAction& action) const { return GetButtonUp(&action); }
[[nodiscard]] bool GetButtonUp(const InputAction* action) const;
[[nodiscard]] bool GetButtonUp(InputKey key) const;
[[nodiscard]] bool GetButtonDown(const InputAction& action) const { return GetButtonDown(&action); }
[[nodiscard]] bool GetButtonDown(const InputAction* action) const;
[[nodiscard]] bool GetButtonDown(InputKey key) const;
[[nodiscard]] InputDevice* GetDevice(InputDeviceType type) const; [[nodiscard]] InputDevice* GetDevice(InputDeviceType type) const;
[[nodiscard]] std::vector<InputDevice*> GetDevices(InputDeviceType type) const; [[nodiscard]] std::vector<InputDevice*> GetDevices(InputDeviceType type) const;