FIX: First build, then upgrade

This commit is contained in:
sebastian 2026-02-21 07:21:07 +01:00
parent 398414a43d
commit 041f423b4f
5 changed files with 23 additions and 8 deletions

View File

@ -105,9 +105,11 @@ void GameLayer::onUpdate()
turnSystem->nextTurn(*turnState, Application::getInstance().getEventBus());
}
if (InputManager::isKeyPressed(GLFW_KEY_U)) {
auto modelStateComponent = entityManager->getComponent<ModelStateComponent>(testEntity);
modelStateComponent->params["fillRatio"] += 0.1f;
if (gameInputUser->isKeyboardEnabled()) {
if (Application::getInstance().keyboard->keyPressEvent(GLFW_KEY_U)) {
gameMode->setUpgradeMode(!gameMode->isUpgradeMode());
}
}
AnimationSystem::update(*entityManager, EngineTime::totalTime);
@ -115,7 +117,9 @@ void GameLayer::onUpdate()
if (gameInputUser->isMouseEnabled()) {
tileHighlightSystem->update(*entityManager, *mousePicker, *camera, *gameMode);
SelectionSystem::update(*entityManager, *gameInputUser, *mousePicker);
if (gameMode->isUpgradeMode()) {
UpgradeSystem::tryUpdate(*entityManager, *gameMode, gameMode->getCurrentPlayer(), *turnState);
}
} else {
tileHighlightSystem->reset(*entityManager);
}

View File

@ -83,4 +83,12 @@ glm::vec3 GameMode::getColorOfPlayer(PlayerID playerID) {
return players[playerID].getColor();
}
void GameMode::setUpgradeMode(bool upgradeMode) {
this->upgradeMode = upgradeMode;
}
bool GameMode::isUpgradeMode() const {
return upgradeMode;
}

View File

@ -40,9 +40,14 @@ public:
void addResource(PlayerID uint32, RessourceType ressource, int get_storage);
glm::vec3 getColorOfPlayer(PlayerID playerID);
void setUpgradeMode(bool upgradeMode);
bool isUpgradeMode() const;
private:
std::unordered_map<PlayerID, Player> players;
std::optional<BuildingType> activeBuilding;
bool upgradeMode = false;
};

View File

@ -35,6 +35,7 @@ EntityID BuildingFactory::create(EntityManager &em, const BuildingDefinition &de
auto modelStateComponent = std::make_shared<ModelStateComponent>();
modelStateComponent->params["fillRatio"] = 0.f;
modelStateComponent->params["level"] = 1.f;
auto producingComponent = std::make_shared<ProducingComponent>( ProducingComponent(def.produces, def.baseAmountPerTurn, false));
producingComponent->setMaxStorage(def.maxStorage);

View File

@ -17,6 +17,7 @@ void SelectionSystem::update(EntityManager &em, GameInputUser& input, MousePicke
if (!input.isMouseEnabled()) return;
if (!Application::getInstance().mouse->isButtonDown(MouseButton::LEFT)) {
selectedEntity = 0;
return;
}
@ -31,8 +32,4 @@ void SelectionSystem::update(EntityManager &em, GameInputUser& input, MousePicke
}
}
if (Application::getInstance().mouse->isReleaseEvent(MouseButton::LEFT)) {
selectedEntity = 0;
}
}