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 "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 "../InputUser.h"
|
||||||
#include "../../../Application.h"
|
#include "../../../Application.h"
|
||||||
#include "../../../../../game/hexWorld/ecs/systems/TileHighlightSystem.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 {
|
class GameInputUser : public InputUser {
|
||||||
public:
|
public:
|
||||||
@ -29,6 +35,8 @@ public:
|
|||||||
|
|
||||||
highlightSystem.update(em, picker, camera, gameMode);
|
highlightSystem.update(em, picker, camera, gameMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
KeyboardIntent processKeyboard();
|
||||||
private:
|
private:
|
||||||
TileHighlightSystem& highlightSystem;
|
TileHighlightSystem& highlightSystem;
|
||||||
EntityManager& em;
|
EntityManager& em;
|
||||||
|
|||||||
@ -90,45 +90,36 @@ void GameLayer::onDetach()
|
|||||||
void GameLayer::onUpdate()
|
void GameLayer::onUpdate()
|
||||||
{
|
{
|
||||||
mousePicker->update(*camera);
|
mousePicker->update(*camera);
|
||||||
//printf("Mouse Ray: %f, %f, %f\n", mousePicker->getCurrentRay().x, mousePicker->getCurrentRay().y, mousePicker->getCurrentRay().z);
|
if (gameInputUser->isKeyboardEnabled()) {
|
||||||
glm::vec3 moveDir = glm::vec3(0,0,0);
|
KeyboardIntent intent = gameInputUser->processKeyboard();
|
||||||
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)) {
|
camera->move(intent.moveDir, 0.5f);
|
||||||
gameMode->setActiveBuilding(BuildingType::FOREST_HUT);
|
|
||||||
} else if (InputManager::isKeyPressed(GLFW_KEY_2)) {
|
if (intent.buildingType.has_value()) {
|
||||||
gameMode->setActiveBuilding(BuildingType::STONE_MASON);
|
gameMode->setActiveBuilding(*intent.buildingType);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (InputManager::isKeyPressed(GLFW_KEY_KP_ADD)) {
|
if (intent.nextTurn) {
|
||||||
turnSystem->nextTurn(*turnState, Application::getInstance().getEventBus());
|
turnSystem->nextTurn(*turnState, Application::getInstance().getEventBus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (intent.toggleUpgrade) {
|
||||||
if (gameInputUser->isKeyboardEnabled()) {
|
|
||||||
if (Application::getInstance().keyboard->keyPressEvent(GLFW_KEY_U)) {
|
|
||||||
if (gameMode->isUpgradeMode()) {
|
if (gameMode->isUpgradeMode()) {
|
||||||
// Disable upgrade mode in upgrade system
|
|
||||||
UpgradeSystem::disableUpgradeMode(*entityManager, gameMode->getCurrentPlayer(), *gameMode);
|
UpgradeSystem::disableUpgradeMode(*entityManager, gameMode->getCurrentPlayer(), *gameMode);
|
||||||
gameMode->setUpgradeMode(false);
|
gameMode->setUpgradeMode(false);
|
||||||
} else {
|
} else {
|
||||||
UpgradeSystem::enableUpgradeMode(*entityManager, gameMode->getCurrentPlayer(), *gameMode, *turnState);
|
UpgradeSystem::enableUpgradeMode(*entityManager, gameMode->getCurrentPlayer(), *gameMode, *turnState);
|
||||||
gameMode->setUpgradeMode(true);
|
gameMode->setUpgradeMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Application::getInstance().keyboard->keyPressEvent(GLFW_KEY_ESCAPE)) {
|
if (intent.cancelAction) {
|
||||||
gameMode->resetActiveBuilding();
|
gameMode->resetActiveBuilding();
|
||||||
BuildPreviewSystem::disableBuildPreview(*entityManager);
|
BuildPreviewSystem::disableBuildPreview(*entityManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimationSystem::update(*entityManager, EngineTime::totalTime);
|
AnimationSystem::update(*entityManager, EngineTime::totalTime);
|
||||||
camera->move(moveDir, 0.5f);
|
|
||||||
if (gameInputUser->isMouseEnabled()) {
|
if (gameInputUser->isMouseEnabled()) {
|
||||||
tileHighlightSystem->update(*entityManager, *mousePicker, *camera, *gameMode);
|
tileHighlightSystem->update(*entityManager, *mousePicker, *camera, *gameMode);
|
||||||
BuildPreviewSystem::updateBuildPreview(*entityManager, *gameMode, gameMode->getCurrentPlayer(), *turnState);
|
BuildPreviewSystem::updateBuildPreview(*entityManager, *gameMode, gameMode->getCurrentPlayer(), *turnState);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user