UPD: Move Keyboard-Input to GameInputUser, closes #4
This commit is contained in:
parent
d67be5b5a9
commit
705d311c6d
@ -3,3 +3,34 @@
|
||||
//
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
@ -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> buildingType;
|
||||
};
|
||||
|
||||
class GameInputUser : public InputUser {
|
||||
public:
|
||||
@ -29,6 +35,8 @@ public:
|
||||
|
||||
highlightSystem.update(em, picker, camera, gameMode);
|
||||
}
|
||||
|
||||
KeyboardIntent processKeyboard();
|
||||
private:
|
||||
TileHighlightSystem& highlightSystem;
|
||||
EntityManager& em;
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user