diff --git a/src/engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.cpp b/src/engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.cpp index 1d41d71..5a253cd 100644 --- a/src/engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.cpp +++ b/src/engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.cpp @@ -2,4 +2,35 @@ // Created by sebastian on 15.02.26. // -#include "GameInputUser.h" \ No newline at end of file +#include "GameInputUser.h" + +#include "../../../../platform/glfw/InputManager.h" + +KeyboardIntent GameInputUser::processKeyboard() { + KeyboardIntent intent; + + if (InputManager::isKeyDown(GLFW_KEY_W)) intent.moveDir.z -= 1.0f; + if (InputManager::isKeyDown(GLFW_KEY_S)) intent.moveDir.z += 1.0f; + if (InputManager::isKeyDown(GLFW_KEY_A)) intent.moveDir.x -= 1.0f; + if (InputManager::isKeyDown(GLFW_KEY_D)) intent.moveDir.x += 1.0f; + + if (InputManager::isKeyPressed(GLFW_KEY_1)) { + intent.buildingType = BuildingType::FOREST_HUT; + } else if (InputManager::isKeyPressed(GLFW_KEY_2)) { + intent.buildingType = BuildingType::STONE_MASON; + } + + if (InputManager::isKeyPressed(GLFW_KEY_KP_ADD)) { + intent.nextTurn = true; + } + + if (InputManager::isKeyPressed(GLFW_KEY_U)) { + intent.toggleUpgrade = true; + } + + if (InputManager::isKeyPressed(GLFW_KEY_ESCAPE)) { + intent.cancelAction = true; + } + + return intent; +} diff --git a/src/engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.h b/src/engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.h index 669aa69..1ff50ba 100644 --- a/src/engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.h +++ b/src/engine/core/inputsOutputs/stateControl/inputUser/GameInputUser.h @@ -7,7 +7,13 @@ #include "../InputUser.h" #include "../../../Application.h" #include "../../../../../game/hexWorld/ecs/systems/TileHighlightSystem.h" - +struct KeyboardIntent { + glm::vec3 moveDir = {0,0,0}; + bool nextTurn = false; + bool toggleUpgrade = false; + bool cancelAction = false; + std::optional buildingType; +}; class GameInputUser : public InputUser { public: @@ -29,6 +35,8 @@ public: highlightSystem.update(em, picker, camera, gameMode); } + + KeyboardIntent processKeyboard(); private: TileHighlightSystem& highlightSystem; EntityManager& em; diff --git a/src/game/GameLayer.cpp b/src/game/GameLayer.cpp index 30c2792..741efc0 100644 --- a/src/game/GameLayer.cpp +++ b/src/game/GameLayer.cpp @@ -90,45 +90,36 @@ void GameLayer::onDetach() void GameLayer::onUpdate() { mousePicker->update(*camera); - //printf("Mouse Ray: %f, %f, %f\n", mousePicker->getCurrentRay().x, mousePicker->getCurrentRay().y, mousePicker->getCurrentRay().z); - glm::vec3 moveDir = glm::vec3(0,0,0); - if (InputManager::isKeyDown(GLFW_KEY_W)) moveDir.z -= 1.0f; - if (InputManager::isKeyDown(GLFW_KEY_S)) moveDir.z += 1.0f; - if (InputManager::isKeyDown(GLFW_KEY_A)) moveDir.x -= 1.0f; - if (InputManager::isKeyDown(GLFW_KEY_D)) moveDir.x += 1.0f; - - if (InputManager::isKeyPressed(GLFW_KEY_1)) { - gameMode->setActiveBuilding(BuildingType::FOREST_HUT); - } else if (InputManager::isKeyPressed(GLFW_KEY_2)) { - gameMode->setActiveBuilding(BuildingType::STONE_MASON); - } - - if (InputManager::isKeyPressed(GLFW_KEY_KP_ADD)) { - turnSystem->nextTurn(*turnState, Application::getInstance().getEventBus()); - } - - if (gameInputUser->isKeyboardEnabled()) { - if (Application::getInstance().keyboard->keyPressEvent(GLFW_KEY_U)) { + KeyboardIntent intent = gameInputUser->processKeyboard(); + + camera->move(intent.moveDir, 0.5f); + + if (intent.buildingType.has_value()) { + gameMode->setActiveBuilding(*intent.buildingType); + } + + if (intent.nextTurn) { + turnSystem->nextTurn(*turnState, Application::getInstance().getEventBus()); + } + + if (intent.toggleUpgrade) { if (gameMode->isUpgradeMode()) { - // Disable upgrade mode in upgrade system UpgradeSystem::disableUpgradeMode(*entityManager, gameMode->getCurrentPlayer(), *gameMode); gameMode->setUpgradeMode(false); } else { UpgradeSystem::enableUpgradeMode(*entityManager, gameMode->getCurrentPlayer(), *gameMode, *turnState); gameMode->setUpgradeMode(true); } - } - if (Application::getInstance().keyboard->keyPressEvent(GLFW_KEY_ESCAPE)) { + if (intent.cancelAction) { gameMode->resetActiveBuilding(); BuildPreviewSystem::disableBuildPreview(*entityManager); } } AnimationSystem::update(*entityManager, EngineTime::totalTime); - camera->move(moveDir, 0.5f); if (gameInputUser->isMouseEnabled()) { tileHighlightSystem->update(*entityManager, *mousePicker, *camera, *gameMode); BuildPreviewSystem::updateBuildPreview(*entityManager, *gameMode, gameMode->getCurrentPlayer(), *turnState);