Sfoglia il codice sorgente

Add basic SDL keyboard implementation

Patrick-Christopher Mattulat 5 giorni fa
parent
commit
0fa6a362fd
38 ha cambiato i file con 644 aggiunte e 31 eliminazioni
  1. 11 0
      CMakeLists.txt
  2. 10 7
      README.md
  3. 1 0
      cmake/ls-atlantis-cycle-tests.cmake
  4. 1 0
      cmake/ls-atlantis-factory-tests.cmake
  5. 2 0
      cmake/ls-atlantis-factory.cmake
  6. 37 0
      cmake/ls-atlantis-input-tests.cmake
  7. 24 0
      cmake/ls-atlantis-input.cmake
  8. 1 0
      cmake/ls-atlantis-interface.cmake
  9. 4 1
      include/cycle/Engine.hpp
  10. 4 0
      include/cycle/EngineRuntimeData.hpp
  11. 32 0
      include/factory/KeyboardFactory.hpp
  12. 18 0
      include/glossary/KeyboardKeys.hpp
  13. 1 1
      include/glossary/StatusCodes.hpp
  14. 1 1
      include/glossary/WindowApiTypes.hpp
  15. 37 0
      include/input/KeyStatus.hpp
  16. 18 0
      include/input/KeyboardKeyMap.hpp
  17. 34 0
      include/input/SdlKeyboard.hpp
  18. 4 3
      include/interface/AStatusCode.hpp
  19. 28 0
      include/interface/IKeyboard.hpp
  20. 1 1
      output/BasicSdlWindowExample.cpp
  21. 25 1
      source/cycle/Engine.cpp
  22. 12 0
      source/cycle/EngineRuntimeData.cpp
  23. 50 0
      source/factory/KeyboardFactory.cpp
  24. 47 0
      source/input/KeyStatus.cpp
  25. 47 0
      source/input/SdlKeyboard.cpp
  26. 6 5
      source/interface/AStatusCode.cpp
  27. 12 0
      source/interface/IKeyboard.cpp
  28. 1 1
      source/window/SdlWindowApi.cpp
  29. 16 0
      test/cycle/EngineRuntimeDataTest.cpp
  30. 29 0
      test/cycle/mock/KeyboardMock.cpp
  31. 27 0
      test/cycle/mock/KeyboardMock.hpp
  32. 30 0
      test/factory/KeyboardFactoryTest.cpp
  33. 62 0
      test/input/KeyStatusTest.cpp
  34. 2 1
      test/interface/mock/StatusCodeMock.cpp
  35. 2 2
      test/messaging/StatusCodeOkTest.cpp
  36. 2 2
      test/messaging/StatusCodeWindowApiLoadingFailedTest.cpp
  37. 2 2
      test/messaging/StatusCodeWindowCreationFailedTest.cpp
  38. 3 3
      test/window/SdlWindowApiTest.cpp

+ 11 - 0
CMakeLists.txt

@@ -15,6 +15,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
 
 set(MODULE_NAME_CYCLE ls-atlantis-cycle)
 set(MODULE_NAME_FACTORY ls-atlantis-factory)
+set(MODULE_NAME_INPUT ls-atlantis-input)
 set(MODULE_NAME_INTERFACE ls-atlantis-interface)
 set(MODULE_NAME_MESSAGING ls-atlantis-messaging)
 set(MODULE_NAME_WINDOW ls-atlantis-window)
@@ -49,6 +50,15 @@ endif ()
 include(cmake/ls-atlantis-interface.cmake)
 include(cmake/ls-atlantis-interface-tests.cmake)
 
+################################################################
+################################################################
+# Module: Input
+################################################################
+################################################################
+
+include(cmake/ls-atlantis-input.cmake)
+include(cmake/ls-atlantis-input-tests.cmake)
+
 ################################################################
 ################################################################
 # Module: Messaging
@@ -103,6 +113,7 @@ add_custom_target(ls-atlantis-tests
     DEPENDS
         ${MODULE_NAME_CYCLE}-tests
         ${MODULE_NAME_FACTORY}-tests
+        ${MODULE_NAME_INPUT}-tests
         ${MODULE_NAME_INTERFACE}-tests
         ${MODULE_NAME_MESSAGING}-tests
         ${MODULE_NAME_WINDOW}-tests

+ 10 - 7
README.md

@@ -21,7 +21,7 @@ conan install . --output-folder=cmake-build-release --build=missing -o "*:shared
 -DCMAKE_CONFIGURATION_TYPES=Release -DCMAKE_TOOLCHAIN_FILE=cmake-build-release/conan_toolchain.cmake
 ```
 5. For the CMake Default Toolchain use __Generator__ Visual Studio for each CMake profile.
-6. For ls-std dependency downloag the recipes repository and navigate to the version __conanfile.py__. Then run:
+6. For ls-std dependency download the recipes repository and navigate to the version __conanfile.py__. Then run:
 ```shell
 conan create . -o "ls-std/*:shared=True" -s build_type=Debug
 conan create . -o "ls-std/*:shared=True" -s build_type=Release
@@ -31,12 +31,15 @@ conan create . -o "ls-std/*:shared=True" -s build_type=Release
 
 In Process: It contains the following modules:
 
-| Name                  | Description                                                                                                                                                                                                                                         |
-|-----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| ls-atlantis-cycle     | This module provides functionalities like engine setup, game loop logic and engine run time information.                                                                                                                                            |
-| ls-atlantis-factory   | This module provides factories for building interface implementations.                                                                                                                                                                              |
-| ls-atlantis-interface | __Consumer:__ This module provides all interfaces all other engine modules can implement. This would avoid circular dependencies through out the project. This module can be imported. This module must not import any library dependencies itself. |
-| ls-atlantis-window    | This module provides functionalities for window creation and handling.                                                                                                                                                                              |
+| Name                  | Description                                                                                                                                                                                                                                                          |
+|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| ls-atlantis-cycle     | This module provides functionalities like engine setup, game loop logic and engine run time information.                                                                                                                                                             |
+| ls-atlantis-factory   | This module provides factories for building interface implementations.                                                                                                                                                                                               |
+| ls-atlantis-glossary  | __Consumer:__ This module provides library constants and lists, which can be shared among project modules. This would avoid circular dependencies through out the project. This module can be imported. This module must not import any library dependencies itself. |
+| ls-atlantis-input     | This module provides functionalities for handling input devices, such as keyboard, mouse & joystick.                                                                                                                                                                 |
+| ls-atlantis-interface | __Consumer:__ This module provides all interfaces all other engine modules can implement. This would avoid circular dependencies through out the project. This module can be imported. This module must not import any library dependencies itself.                  |
+| ls-atlantis-message   | This module provides all messaging functionalities and status code implementations.                                                                                                                                                                                  |
+| ls-atlantis-window    | This module provides functionalities for window creation and handling.                                                                                                                                                                                               |
 
 ## Dependencies
 

+ 1 - 0
cmake/ls-atlantis-cycle-tests.cmake

@@ -9,6 +9,7 @@
 ################################
 
 set(ATLANTIS_CYCLE_TEST_SOURCES
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/mock/KeyboardMock.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/mock/WindowApiMock.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/EngineParameterTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/cycle/EngineRuntimeDataTest.cpp

+ 1 - 0
cmake/ls-atlantis-factory-tests.cmake

@@ -9,6 +9,7 @@
 ################################
 
 set(ATLANTIS_FACTORY_TEST_SOURCES
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/factory/KeyboardFactoryTest.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/test/factory/WindowApiFactoryTest.cpp
 )
 

+ 2 - 0
cmake/ls-atlantis-factory.cmake

@@ -9,6 +9,7 @@
 ################################
 
 set(ATLANTIS_FACTORY_SOURCES
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/factory/KeyboardFactory.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/factory/WindowApiFactory.cpp
 )
 
@@ -19,5 +20,6 @@ set(ATLANTIS_FACTORY_SOURCES
 add_library(${MODULE_NAME_FACTORY} SHARED ${ATLANTIS_FACTORY_SOURCES})
 
 target_link_libraries(${MODULE_NAME_FACTORY} PUBLIC
+    ${MODULE_NAME_INPUT}
     ${MODULE_NAME_WINDOW}
 )

+ 37 - 0
cmake/ls-atlantis-input-tests.cmake

@@ -0,0 +1,37 @@
+################################################################
+################################################################
+# Module-Test: Input
+################################################################
+################################################################
+
+################################
+# Test Files: Input Module
+################################
+
+set(ATLANTIS_INPUT_TEST_SOURCES
+        ${CMAKE_CURRENT_SOURCE_DIR}/test/input/KeyStatusTest.cpp
+)
+
+################################
+# Test Case Creation: Input Module
+################################
+
+add_executable(${MODULE_NAME_INPUT}-tests ${ATLANTIS_INPUT_TEST_SOURCES})
+
+target_link_libraries(${MODULE_NAME_INPUT}-tests PRIVATE
+    ${MODULE_NAME_INPUT}
+    GTest::gtest_main
+)
+
+gtest_discover_tests(${MODULE_NAME_INPUT}-tests DISCOVERY_MODE PRE_TEST)
+
+if (WIN32)
+    add_custom_command(TARGET ${MODULE_NAME_INPUT}-tests POST_BUILD
+        COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${MODULE_NAME_INPUT}-tests>
+            $<TARGET_RUNTIME_DLLS:${MODULE_NAME_INPUT}-tests>
+        COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${MODULE_NAME_INPUT}-tests>
+            "$<$<CONFIG:Debug>:${LS_STD_DLLS_DEBUG}>"
+            "$<$<CONFIG:Release>:${LS_STD_DLLS_RELEASE}>"
+        COMMAND_EXPAND_LISTS
+    )
+endif ()

+ 24 - 0
cmake/ls-atlantis-input.cmake

@@ -0,0 +1,24 @@
+################################################################
+################################################################
+# Module: Input
+################################################################
+################################################################
+
+################################
+# Source Files: Input Module
+################################
+
+set(ATLANTIS_INPUT_SOURCES
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/input/KeyStatus.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/input/SdlKeyboard.cpp
+)
+
+################################
+# Library Creation: Input Module
+################################
+
+add_library(${MODULE_NAME_INPUT} SHARED ${ATLANTIS_INPUT_SOURCES})
+
+target_link_libraries(${MODULE_NAME_INPUT} PUBLIC
+    ${MODULE_NAME_INTERFACE}
+)

+ 1 - 0
cmake/ls-atlantis-interface.cmake

@@ -10,6 +10,7 @@
 
 set(ATLANTIS_INTERFACE_SOURCES
         ${CMAKE_CURRENT_SOURCE_DIR}/source/interface/AStatusCode.cpp
+        ${CMAKE_CURRENT_SOURCE_DIR}/source/interface/IKeyboard.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/interface/ISdlApi.cpp
         ${CMAKE_CURRENT_SOURCE_DIR}/source/interface/IWindowApi.cpp
 )

+ 4 - 1
include/cycle/Engine.hpp

@@ -22,12 +22,15 @@ namespace ls::atlantis::cycle
       ~Engine();
 
       [[nodiscard]] ::std::shared_ptr<ls::atlantis::cycle::EngineRuntimeData> getData() const;
-      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> init();
+      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> init() const;
 
     private:
 
       ::std::shared_ptr<ls::atlantis::cycle::EngineRuntimeData> data{};
       ls::atlantis::cycle::EngineParameter parameter{};
+
+      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> _initKeyboard() const;
+      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::AStatusCode> _initWindowApi() const;
   };
 }
 

+ 4 - 0
include/cycle/EngineRuntimeData.hpp

@@ -7,6 +7,7 @@
 #define LS_ATLANTIS_ENGINE_CYCLE_ENGINE_RUNTIME_DATA_HPP
 
 #include <Export.hpp>
+#include <interface/IKeyboard.hpp>
 #include <interface/IWindowApi.hpp>
 #include <memory>
 
@@ -19,11 +20,14 @@ namespace ls::atlantis::cycle
       EngineRuntimeData();
       ~EngineRuntimeData();
 
+      [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> getKeyboard() const;
       [[nodiscard]] ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> getWindowApi() const;
+      void setKeyboard(const ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> &_keyboard);
       void setWindowApi(const ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> &_windowApi);
 
     private:
 
+      ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> keyboard{};
       ::std::shared_ptr<ls::atlantis::interfaces::IWindowApi> windowApi{};
   };
 }

+ 32 - 0
include/factory/KeyboardFactory.hpp

@@ -0,0 +1,32 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_FACTORY_KEYBOARD_FACTORY_HPP
+#define LS_ATLANTIS_ENGINE_FACTORY_KEYBOARD_FACTORY_HPP
+
+#include <Export.hpp>
+#include <glossary/WindowApiTypes.hpp>
+#include <input/KeyboardKeyMap.hpp>
+#include <interface/IKeyboard.hpp>
+#include <memory>
+
+namespace ls::atlantis::factory
+{
+  class LS_ATLANTIS_DYNAMIC_GOAL KeyboardFactory
+  {
+    public:
+
+      KeyboardFactory();
+      ~KeyboardFactory();
+
+      [[nodiscard]] static ::std::shared_ptr<ls::atlantis::interfaces::IKeyboard> build(const ls::atlantis::glossary::WindowApiTypes &_windowApis);
+
+    private:
+
+      [[nodiscard]] static ls::atlantis::input::KeyboardKeyMap _generateKeyMap();
+  };
+}
+
+#endif

+ 18 - 0
include/glossary/KeyboardKeys.hpp

@@ -0,0 +1,18 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_GLOSSARY_KEYBOARD_KEYS_HPP
+#define LS_ATLANTIS_ENGINE_GLOSSARY_KEYBOARD_KEYS_HPP
+
+namespace ls::atlantis::glossary
+{
+  enum class KeyboardKeys
+  {
+    NONE_SELECTED = 0,
+    ESCAPE = 1
+  };
+}
+
+#endif

+ 1 - 1
include/glossary/StatusCodes.hpp

@@ -8,7 +8,7 @@
 
 namespace ls::atlantis::glossary
 {
-  enum StatusCodes
+  enum class StatusCodes
   {
     OK = 0,
     WINDOW_API_LOADING_FAILED = 1,

+ 1 - 1
include/glossary/WindowApiTypes.hpp

@@ -8,7 +8,7 @@
 
 namespace ls::atlantis::glossary
 {
-  enum WindowApiTypes
+  enum class WindowApiTypes
   {
     NONE_SELECTED = 0,
     SDL_WINDOW_API = 1

+ 37 - 0
include/input/KeyStatus.hpp

@@ -0,0 +1,37 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_INPUT_KEY_STATUS_HPP
+#define LS_ATLANTIS_ENGINE_INPUT_KEY_STATUS_HPP
+
+#include <Export.hpp>
+#include <glossary/KeyboardKeys.hpp>
+
+namespace ls::atlantis::input
+{
+  class LS_ATLANTIS_DYNAMIC_GOAL KeyStatus
+  {
+    public:
+
+      KeyStatus();
+      explicit KeyStatus(const ls::atlantis::glossary::KeyboardKeys &_key, bool _isFreedValue, bool _isPressedValue);
+      ~KeyStatus();
+
+      [[nodiscard]] ls::atlantis::glossary::KeyboardKeys getKey() const;
+      [[nodiscard]] bool getIsFreedValue() const;
+      [[nodiscard]] bool getIsPressedValue() const;
+      void setIsFreedValue(bool _isFreedValue);
+      void setIsPressedValue(bool _isPressedValue);
+      void setKey(const ls::atlantis::glossary::KeyboardKeys &_key);
+
+    private:
+
+      ls::atlantis::glossary::KeyboardKeys key{};
+      bool isFreedValue{};
+      bool isPressedValue{};
+  };
+}
+
+#endif

+ 18 - 0
include/input/KeyboardKeyMap.hpp

@@ -0,0 +1,18 @@
+/*
+* author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_INPUT_KEYBOARD_KEY_MAP_HPP
+#define LS_ATLANTIS_ENGINE_INPUT_KEYBOARD_KEY_MAP_HPP
+
+#include <glossary/KeyboardKeys.hpp>
+#include <input/KeyStatus.hpp>
+#include <map>
+
+namespace ls::atlantis::input
+{
+  using KeyboardKeyMap = ::std::map<ls::atlantis::glossary::KeyboardKeys, ls::atlantis::input::KeyStatus>;
+}
+
+#endif

+ 34 - 0
include/input/SdlKeyboard.hpp

@@ -0,0 +1,34 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_INPUT_SDL_KEYBOARD_HPP
+#define LS_ATLANTIS_ENGINE_INPUT_SDL_KEYBOARD_HPP
+
+#include <Export.hpp>
+#include <glossary/KeyboardKeys.hpp>
+#include <input/KeyboardKeyMap.hpp>
+#include <interface/IKeyboard.hpp>
+
+namespace ls::atlantis::input
+{
+  class LS_ATLANTIS_DYNAMIC_GOAL SdlKeyboard : public ls::atlantis::interfaces::IKeyboard
+  {
+    public:
+
+      explicit SdlKeyboard(ls::atlantis::input::KeyboardKeyMap _keys);
+      ~SdlKeyboard() override;
+      
+      [[nodiscard]] bool isFreed(const ls::atlantis::glossary::KeyboardKeys &_key) override;
+      [[nodiscard]] bool isPressed(const ls::atlantis::glossary::KeyboardKeys &_key) override;
+      void reset() override;
+      void updateKey(const ls::atlantis::glossary::KeyboardKeys &_key, bool _isFreed, bool _isPressed) override;
+
+    protected:
+
+      ls::atlantis::input::KeyboardKeyMap keys{};
+  };
+}
+
+#endif

+ 4 - 3
include/interface/AStatusCode.hpp

@@ -7,6 +7,7 @@
 #define LS_ATLANTIS_ENGINE_INTERFACE_STATUS_CODE_HPP
 
 #include <Export.hpp>
+#include <glossary/StatusCodes.hpp>
 #include <string>
 #include <vector>
 
@@ -16,18 +17,18 @@ namespace ls::atlantis::interfaces
   {
     public:
 
-      explicit AStatusCode(const uint16_t &_statusId, ::std::string _statusText);
+      explicit AStatusCode(const ls::atlantis::glossary::StatusCodes &_statusCode, ::std::string _statusText);
       virtual ~AStatusCode();
 
       virtual void addHint(const ::std::string &_hint);
+      [[nodiscard]] virtual ls::atlantis::glossary::StatusCodes getCode() const;
       [[nodiscard]] ::std::vector<::std::string> getHints() const;
-      [[nodiscard]] virtual uint16_t getId() const;
       [[nodiscard]] virtual ::std::string getText() const;
 
     private:
 
+      ls::atlantis::glossary::StatusCodes statusCode{};
       ::std::vector<::std::string> statusHints{};
-      uint16_t statusId{};
       ::std::string statusText{};
   };
 }

+ 28 - 0
include/interface/IKeyboard.hpp

@@ -0,0 +1,28 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_INTERFACE_KEYBOARD_HPP
+#define LS_ATLANTIS_ENGINE_INTERFACE_KEYBOARD_HPP
+
+#include <Export.hpp>
+#include <glossary/KeyboardKeys.hpp>
+
+namespace ls::atlantis::interfaces
+{
+  class LS_ATLANTIS_DYNAMIC_GOAL IKeyboard
+  {
+    public:
+
+      IKeyboard();
+      virtual ~IKeyboard();
+
+      virtual bool isFreed(const ls::atlantis::glossary::KeyboardKeys &_key) = 0;
+      virtual bool isPressed(const ls::atlantis::glossary::KeyboardKeys &_key) = 0;
+      virtual void reset() = 0;
+      virtual void updateKey(const ls::atlantis::glossary::KeyboardKeys &_key, bool _isFreed, bool _isPressed) = 0;
+  };
+}
+
+#endif

+ 1 - 1
output/BasicSdlWindowExample.cpp

@@ -27,5 +27,5 @@ int main()
   Engine engine{parameter};
   const shared_ptr<AStatusCode> statusCode = engine.init();
 
-  return statusCode->getId() == StatusCodes::OK ? EXIT_SUCCESS : EXIT_FAILURE;
+  return statusCode->getCode() == StatusCodes::OK ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 25 - 1
source/cycle/Engine.cpp

@@ -4,13 +4,17 @@
  */
 
 #include <cycle/Engine.hpp>
+#include <factory/KeyboardFactory.hpp>
 #include <factory/WindowApiFactory.hpp>
+#include <messaging/StatusCodeOk.hpp>
 
 using ls::atlantis::cycle::Engine;
 using ls::atlantis::cycle::EngineParameter;
 using ls::atlantis::cycle::EngineRuntimeData;
+using ls::atlantis::factory::KeyboardFactory;
 using ls::atlantis::factory::WindowApiFactory;
 using ls::atlantis::interfaces::AStatusCode;
+using ls::atlantis::messaging::StatusCodeOk;
 using ::std::make_shared;
 using ::std::shared_ptr;
 
@@ -26,7 +30,27 @@ shared_ptr<EngineRuntimeData> Engine::getData() const
   return this->data;
 }
 
-shared_ptr<AStatusCode> Engine::init()
+shared_ptr<AStatusCode> Engine::init() const
+{
+  shared_ptr<AStatusCode> result = _initWindowApi();
+
+  if (result->getCode() == StatusCodeOk().getCode())
+  {
+    result = this->_initKeyboard();
+  }
+
+  return result;
+}
+
+shared_ptr<AStatusCode> Engine::_initKeyboard() const
+{
+  const auto keyboard = KeyboardFactory::build(this->parameter.getWindowApiType());
+  this->data->setKeyboard(keyboard);
+
+  return make_shared<StatusCodeOk>();
+}
+
+shared_ptr<AStatusCode> Engine::_initWindowApi() const
 {
   const auto windowApi = WindowApiFactory::build(this->parameter.getWindowApiType());
   this->data->setWindowApi(windowApi);

+ 12 - 0
source/cycle/EngineRuntimeData.cpp

@@ -7,6 +7,7 @@
 #include <ls-std/core/evaluator/NullPointerArgumentEvaluator.hpp>
 
 using ls::atlantis::cycle::EngineRuntimeData;
+using ls::atlantis::interfaces::IKeyboard;
 using ls::atlantis::interfaces::IWindowApi;
 using ls::std::core::NullPointerArgumentEvaluator;
 using ::std::shared_ptr;
@@ -15,11 +16,22 @@ EngineRuntimeData::EngineRuntimeData() = default;
 
 EngineRuntimeData::~EngineRuntimeData() = default;
 
+shared_ptr<IKeyboard> EngineRuntimeData::getKeyboard() const
+{
+  return this->keyboard;
+}
+
 shared_ptr<IWindowApi> EngineRuntimeData::getWindowApi() const
 {
   return this->windowApi;
 }
 
+void EngineRuntimeData::setKeyboard(const shared_ptr<IKeyboard> &_keyboard)
+{
+  NullPointerArgumentEvaluator(_keyboard).evaluate();
+  this->keyboard = _keyboard;
+}
+
 void EngineRuntimeData::setWindowApi(const shared_ptr<IWindowApi> &_windowApi)
 {
   NullPointerArgumentEvaluator(_windowApi).evaluate();

+ 50 - 0
source/factory/KeyboardFactory.cpp

@@ -0,0 +1,50 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <factory/KeyboardFactory.hpp>
+#include <input/SdlKeyboard.hpp>
+#include <ls-std/core/exception/IllegalArgumentException.hpp>
+
+using ls::atlantis::factory::KeyboardFactory;
+using ls::atlantis::glossary::KeyboardKeys;
+using ls::atlantis::glossary::WindowApiTypes;
+using ls::atlantis::input::KeyStatus;
+using ls::atlantis::input::KeyboardKeyMap;
+using ls::atlantis::input::SdlKeyboard;
+using ls::atlantis::interfaces::IKeyboard;
+using ls::std::core::IllegalArgumentException;
+using ::std::make_shared;
+using ::std::shared_ptr;
+
+KeyboardFactory::KeyboardFactory() = default;
+
+KeyboardFactory::~KeyboardFactory() = default;
+
+shared_ptr<IKeyboard> KeyboardFactory::build(const WindowApiTypes &_windowApis)
+{
+  shared_ptr<IKeyboard> keyboard{};
+
+  switch (_windowApis)
+  {
+    case WindowApiTypes::NONE_SELECTED:
+    {
+      throw IllegalArgumentException{};
+    }
+    case WindowApiTypes::SDL_WINDOW_API:
+    {
+      keyboard = make_shared<SdlKeyboard>(KeyboardFactory::_generateKeyMap());
+    } break;
+  }
+
+  return keyboard;
+}
+
+KeyboardKeyMap KeyboardFactory::_generateKeyMap()
+{
+  KeyboardKeyMap keyMap{};
+  keyMap[KeyboardKeys::ESCAPE] = KeyStatus(KeyboardKeys::ESCAPE, false, false);
+
+  return keyMap;
+}

+ 47 - 0
source/input/KeyStatus.cpp

@@ -0,0 +1,47 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <input/KeyStatus.hpp>
+
+using ls::atlantis::glossary::KeyboardKeys;
+using ls::atlantis::input::KeyStatus;
+
+KeyStatus::KeyStatus() : KeyStatus(KeyboardKeys::NONE_SELECTED, false, false)
+{}
+
+KeyStatus::KeyStatus(const KeyboardKeys &_key, const bool _isFreedValue, const bool _isPressedValue) : key(_key), isFreedValue(_isFreedValue), isPressedValue(_isPressedValue)
+{}
+
+KeyStatus::~KeyStatus() = default;
+
+KeyboardKeys KeyStatus::getKey() const
+{
+  return this->key;
+}
+
+bool KeyStatus::getIsFreedValue() const
+{
+  return this->isFreedValue;
+}
+
+bool KeyStatus::getIsPressedValue() const
+{
+  return this->isPressedValue;
+}
+
+void KeyStatus::setIsFreedValue(const bool _isFreedValue)
+{
+  this->isFreedValue = _isFreedValue;
+}
+
+void KeyStatus::setIsPressedValue(const bool _isPressedValue)
+{
+  this->isPressedValue = _isPressedValue;
+}
+
+void KeyStatus::setKey(const KeyboardKeys &_key)
+{
+  this->key = _key;
+}

+ 47 - 0
source/input/SdlKeyboard.cpp

@@ -0,0 +1,47 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <input/SdlKeyboard.hpp>
+#include <utility>
+
+using ls::atlantis::glossary::KeyboardKeys;
+using ls::atlantis::input::KeyboardKeyMap;
+using ls::atlantis::input::KeyStatus;
+using ls::atlantis::input::SdlKeyboard;
+using ::std::move;
+
+SdlKeyboard::SdlKeyboard(KeyboardKeyMap _keys) : keys(::move(_keys))
+{}
+
+SdlKeyboard::~SdlKeyboard() = default;
+
+bool SdlKeyboard::isFreed(const KeyboardKeys &_key)
+{
+  const auto entry = this->keys.find(_key);
+
+  return entry != this->keys.end() && entry->second.getIsFreedValue();
+}
+
+bool SdlKeyboard::isPressed(const KeyboardKeys &_key)
+{
+  const auto entry = this->keys.find(_key);
+
+  return entry != this->keys.end() && entry->second.getIsPressedValue();
+}
+
+void SdlKeyboard::reset()
+{
+  for (auto &[key, status] : this->keys)
+  {
+    status.setIsFreedValue(false);
+    status.setIsPressedValue(false);
+  }
+}
+
+void SdlKeyboard::updateKey(const KeyboardKeys &_key, const bool _isFreed, const bool _isPressed)
+{
+  this->keys[_key].setIsFreedValue(_isFreed);
+  this->keys[_key].setIsPressedValue(_isPressed);
+}

+ 6 - 5
source/interface/AStatusCode.cpp

@@ -6,13 +6,14 @@
 #include <interface/AStatusCode.hpp>
 #include <ls-std/core/evaluator/EmptyStringArgumentEvaluator.hpp>
 
+using ls::atlantis::glossary::StatusCodes;
 using ls::atlantis::interfaces::AStatusCode;
 using ls::std::core::EmptyStringArgumentEvaluator;
 using ::std::move;
 using ::std::string;
 using ::std::vector;
 
-AStatusCode::AStatusCode(const uint16_t &_statusId, string _statusText) : statusId(_statusId), statusText(::move(_statusText))
+AStatusCode::AStatusCode(const StatusCodes &_statusCode, string _statusText) : statusCode(_statusCode), statusText(::move(_statusText))
 {}
 
 AStatusCode::~AStatusCode() = default;
@@ -23,14 +24,14 @@ void AStatusCode::addHint(const string &_hint)
   this->statusHints.push_back(_hint);
 }
 
-vector<string> AStatusCode::getHints() const
+StatusCodes AStatusCode::getCode() const
 {
-  return this->statusHints;
+  return this->statusCode;
 }
 
-uint16_t AStatusCode::getId() const
+vector<string> AStatusCode::getHints() const
 {
-  return this->statusId;
+  return this->statusHints;
 }
 
 string AStatusCode::getText() const

+ 12 - 0
source/interface/IKeyboard.cpp

@@ -0,0 +1,12 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <interface/IKeyboard.hpp>
+
+using ls::atlantis::interfaces::IKeyboard;
+
+IKeyboard::IKeyboard() = default;
+
+IKeyboard::~IKeyboard() = default;

+ 1 - 1
source/window/SdlWindowApi.cpp

@@ -48,7 +48,7 @@ shared_ptr<AStatusCode> SdlWindowApi::init()
 {
   shared_ptr<AStatusCode> statusCode = this->_initApi();
 
-  if (statusCode->getId() == StatusCodeOk{}.getId())
+  if (statusCode->getCode() == StatusCodeOk{}.getCode())
   {
     statusCode = this->_createWindow();
   }

+ 16 - 0
test/cycle/EngineRuntimeDataTest.cpp

@@ -7,9 +7,11 @@
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 #include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <test/cycle/mock/KeyboardMock.hpp>
 #include <test/cycle/mock/WindowApiMock.hpp>
 
 using ls::atlantis::cycle::EngineRuntimeData;
+using ls::atlantis::cycle::test::KeyboardMock;
 using ls::atlantis::cycle::test::WindowApiMock;
 using ls::std::core::IllegalArgumentException;
 using ::std::make_shared;
@@ -25,9 +27,23 @@ namespace
       EngineRuntimeDataTest() = default;
       ~EngineRuntimeDataTest() override = default;
 
+      shared_ptr<KeyboardMock> keyboardMock = make_shared<KeyboardMock>();
       shared_ptr<WindowApiMock> windowApiMock = make_shared<WindowApiMock>();
   };
 
+  TEST_F(EngineRuntimeDataTest, setKeyboard_nullPointer)
+  {
+    ASSERT_THROW(EngineRuntimeData().setKeyboard(nullptr), IllegalArgumentException);
+  }
+
+  TEST_F(EngineRuntimeDataTest, getKeyboard)
+  {
+    EngineRuntimeData engineRuntimeData{};
+    engineRuntimeData.setKeyboard(keyboardMock);
+
+    ASSERT_EQ(keyboardMock, engineRuntimeData.getKeyboard());
+  }
+
   TEST_F(EngineRuntimeDataTest, setWindowApi_nullPointer)
   {
     ASSERT_THROW(EngineRuntimeData().setWindowApi(nullptr), IllegalArgumentException);

+ 29 - 0
test/cycle/mock/KeyboardMock.cpp

@@ -0,0 +1,29 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <test/cycle/mock/KeyboardMock.hpp>
+
+using ls::atlantis::cycle::test::KeyboardMock;
+using ls::atlantis::glossary::KeyboardKeys;
+
+KeyboardMock::KeyboardMock() = default;
+
+KeyboardMock::~KeyboardMock() = default;
+
+bool KeyboardMock::isFreed(const KeyboardKeys &_key)
+{
+  return false;
+}
+
+bool KeyboardMock::isPressed(const KeyboardKeys &_key)
+{
+  return false;
+}
+
+void KeyboardMock::reset()
+{}
+
+void KeyboardMock::updateKey(const KeyboardKeys &_key, bool _isFreed, bool _isPressed)
+{}

+ 27 - 0
test/cycle/mock/KeyboardMock.hpp

@@ -0,0 +1,27 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#ifndef LS_ATLANTIS_ENGINE_CYCLE_TEST_KEYBOARD_MOCK_HPP
+#define LS_ATLANTIS_ENGINE_CYCLE_TEST_KEYBOARD_MOCK_HPP
+
+#include <interface/IKeyboard.hpp>
+
+namespace ls::atlantis::cycle::test
+{
+  class KeyboardMock : public ls::atlantis::interfaces::IKeyboard
+  {
+    public:
+
+      KeyboardMock();
+      ~KeyboardMock() override;
+
+      [[nodiscard]] bool isFreed(const ls::atlantis::glossary::KeyboardKeys &_key) override;
+      [[nodiscard]] bool isPressed(const ls::atlantis::glossary::KeyboardKeys &_key) override;
+      void reset() override;
+      void updateKey(const ls::atlantis::glossary::KeyboardKeys &_key, bool _isFreed, bool _isPressed) override;
+  };
+}
+
+#endif

+ 30 - 0
test/factory/KeyboardFactoryTest.cpp

@@ -0,0 +1,30 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <factory/KeyboardFactory.hpp>
+#include <glossary/WindowApiTypes.hpp>
+#include <gtest/gtest.h>
+#include <ls-std/core/exception/IllegalArgumentException.hpp>
+
+using ls::atlantis::factory::KeyboardFactory;
+using ls::atlantis::glossary::WindowApiTypes;
+using ls::std::core::IllegalArgumentException;
+using ::testing::Test;
+
+namespace
+{
+  class KeyboardFactoryTest : public Test
+  {
+    public:
+
+      KeyboardFactoryTest() = default;
+      ~KeyboardFactoryTest() override = default;
+  };
+
+  TEST_F(KeyboardFactoryTest, build_noneSelected)
+  {
+    ASSERT_THROW(static_cast<void>(KeyboardFactory::build(WindowApiTypes::NONE_SELECTED)), IllegalArgumentException);
+  }
+}

+ 62 - 0
test/input/KeyStatusTest.cpp

@@ -0,0 +1,62 @@
+/*
+ * author: Patrick-Christopher Mattulat
+ * e-mail: webmaster@lynarstudios.com
+ */
+
+#include <glossary/KeyboardKeys.hpp>
+#include <gtest/gtest.h>
+#include <input/KeyStatus.hpp>
+
+using ls::atlantis::glossary::KeyboardKeys;
+using ls::atlantis::input::KeyStatus;
+using ::testing::Test;
+
+namespace
+{
+  class KeyStatusTest : public Test
+  {
+    public:
+
+      KeyStatusTest() = default;
+      ~KeyStatusTest() override = default;
+  };
+
+  TEST_F(KeyStatusTest, getKey_default)
+  {
+    ASSERT_EQ(KeyboardKeys::NONE_SELECTED, KeyStatus().getKey());
+  }
+
+  TEST_F(KeyStatusTest, getIsFreedValue_default)
+  {
+    ASSERT_FALSE(KeyStatus().getIsFreedValue());
+  }
+
+  TEST_F(KeyStatusTest, getIsPressedValue_default)
+  {
+    ASSERT_FALSE(KeyStatus().getIsPressedValue());
+  }
+
+  TEST_F(KeyStatusTest, setKey)
+  {
+    KeyStatus keyStatus{};
+    keyStatus.setKey(KeyboardKeys::ESCAPE);
+
+    ASSERT_EQ(KeyboardKeys::ESCAPE, keyStatus.getKey());
+  }
+
+  TEST_F(KeyStatusTest, setIsFreedValue)
+  {
+    KeyStatus keyStatus{};
+    keyStatus.setIsFreedValue(true);
+
+    ASSERT_TRUE(keyStatus.getIsFreedValue());
+  }
+
+  TEST_F(KeyStatusTest, setIsPressedValue)
+  {
+    KeyStatus keyStatus{};
+    keyStatus.setIsPressedValue(true);
+
+    ASSERT_TRUE(keyStatus.getIsPressedValue());
+  }
+}

+ 2 - 1
test/interface/mock/StatusCodeMock.cpp

@@ -5,10 +5,11 @@
 
 #include <test/interface/mock/StatusCodeMock.hpp>
 
+using ls::atlantis::glossary::StatusCodes;
 using ls::atlantis::interfaces::AStatusCode;
 using ls::atlantis::interfaces::test::StatusCodeMock;
 
-StatusCodeMock::StatusCodeMock() : AStatusCode(0, "mocked a code")
+StatusCodeMock::StatusCodeMock() : AStatusCode(StatusCodes::OK, "mocked a code")
 {}
 
 StatusCodeMock::~StatusCodeMock() = default;

+ 2 - 2
test/messaging/StatusCodeOkTest.cpp

@@ -22,9 +22,9 @@ namespace
       ~StatusCodeOkTest() override = default;
   };
 
-  TEST_F(StatusCodeOkTest, getId)
+  TEST_F(StatusCodeOkTest, getCode)
   {
-    ASSERT_EQ(StatusCodes::OK, StatusCodeOk().getId());
+    ASSERT_EQ(StatusCodes::OK, StatusCodeOk().getCode());
   }
 
   TEST_F(StatusCodeOkTest, getText)

+ 2 - 2
test/messaging/StatusCodeWindowApiLoadingFailedTest.cpp

@@ -22,9 +22,9 @@ namespace
       ~StatusCodeWindowApiLoadingFailedTest() override = default;
   };
 
-  TEST_F(StatusCodeWindowApiLoadingFailedTest, getId)
+  TEST_F(StatusCodeWindowApiLoadingFailedTest, getCode)
   {
-    ASSERT_EQ(StatusCodes::WINDOW_API_LOADING_FAILED, StatusCodeWindowApiLoadingFailed().getId());
+    ASSERT_EQ(StatusCodes::WINDOW_API_LOADING_FAILED, StatusCodeWindowApiLoadingFailed().getCode());
   }
 
   TEST_F(StatusCodeWindowApiLoadingFailedTest, getText)

+ 2 - 2
test/messaging/StatusCodeWindowCreationFailedTest.cpp

@@ -22,9 +22,9 @@ namespace
       ~StatusCodeWindowCreationFailedTest() override = default;
   };
 
-  TEST_F(StatusCodeWindowCreationFailedTest, getId)
+  TEST_F(StatusCodeWindowCreationFailedTest, getCode)
   {
-    ASSERT_EQ(StatusCodes::WINDOW_CREATION_FAILED, StatusCodeWindowCreationFailed().getId());
+    ASSERT_EQ(StatusCodes::WINDOW_CREATION_FAILED, StatusCodeWindowCreationFailed().getCode());
   }
 
   TEST_F(StatusCodeWindowCreationFailedTest, getText)

+ 3 - 3
test/window/SdlWindowApiTest.cpp

@@ -52,7 +52,7 @@ namespace
     EXPECT_CALL(*sdlApiMock, DestroyWindow(fakeWindow));
     EXPECT_CALL(*sdlApiMock, Quit());
 
-    ASSERT_EQ(StatusCodes::OK, SdlWindowApi(sdlApiMock).init()->getId());
+    ASSERT_EQ(StatusCodes::OK, SdlWindowApi(sdlApiMock).init()->getCode());
   }
 
   TEST_F(SdlWindowApiTest, init_failed)
@@ -65,7 +65,7 @@ namespace
 
     const shared_ptr<AStatusCode> statusCode = SdlWindowApi(sdlApiMock).init();
 
-    ASSERT_EQ(StatusCodes::WINDOW_API_LOADING_FAILED, statusCode->getId());
+    ASSERT_EQ(StatusCodes::WINDOW_API_LOADING_FAILED, statusCode->getCode());
     ASSERT_EQ(1, statusCode->getHints().size());
     ASSERT_STREQ(hint.c_str(), statusCode->getHints()[0].c_str());
   }
@@ -81,7 +81,7 @@ namespace
 
     const shared_ptr<AStatusCode> statusCode = SdlWindowApi(sdlApiMock).init();
 
-    ASSERT_EQ(StatusCodes::WINDOW_CREATION_FAILED, statusCode->getId());
+    ASSERT_EQ(StatusCodes::WINDOW_CREATION_FAILED, statusCode->getCode());
     ASSERT_EQ(1, statusCode->getHints().size());
     ASSERT_STREQ(hint.c_str(), statusCode->getHints()[0].c_str());
   }