Keys.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef KEYS_H
  2. #define KEYS_H
  3. #include <iostream>
  4. #include <array>
  5. #include "common/utils/Types.h"
  6. class Keys final
  7. {
  8. public:
  9. class Key final
  10. {
  11. public:
  12. friend class Keys;
  13. bool isDown() const;
  14. bool isReleased() const;
  15. u32 getDownTime() const;
  16. private:
  17. Key() = default;
  18. Key(const Key&) = delete;
  19. Key(Key&&) = delete;
  20. Key& operator=(const Key&) = delete;
  21. Key& operator=(Key&&) = delete;
  22. int glfwKey;
  23. bool down;
  24. bool shouldRelease;
  25. u32 downTime;
  26. };
  27. private:
  28. Key keys[6];
  29. public:
  30. Keys();
  31. const Key& left;
  32. const Key& right;
  33. const Key& up;
  34. const Key& down;
  35. const Key& jump;
  36. const Key& sneak;
  37. void release(int key);
  38. void press(int key);
  39. void tick();
  40. private:
  41. Keys(const Keys&) = delete;
  42. Keys& operator=(const Keys&) = delete;
  43. Keys(Key&&) = delete;
  44. Keys& operator=(Keys&&) = delete;
  45. };
  46. std::ostream& operator<<(std::ostream& os, const Keys::Key& k);
  47. #endif