Keys.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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[10];
  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. const Key& camLeft;
  38. const Key& camRight;
  39. const Key& camUp;
  40. const Key& camDown;
  41. void release(int key);
  42. void press(int key);
  43. void tick();
  44. private:
  45. Keys(const Keys&) = delete;
  46. Keys& operator=(const Keys&) = delete;
  47. Keys(Key&&) = delete;
  48. Keys& operator=(Keys&&) = delete;
  49. };
  50. std::ostream& operator<<(std::ostream& os, const Keys::Key& k);
  51. #endif