diff --git a/assets/worldIcons/error.png b/assets/worldIcons/error.png new file mode 100644 index 0000000..6352566 Binary files /dev/null and b/assets/worldIcons/error.png differ diff --git a/src/engine/core/ECS/WorldSpriteComponent.h b/src/engine/core/ECS/WorldSpriteComponent.h index 5602369..4c3fce3 100644 --- a/src/engine/core/ECS/WorldSpriteComponent.h +++ b/src/engine/core/ECS/WorldSpriteComponent.h @@ -13,6 +13,7 @@ class WorldSpriteComponent : public Component { public: + std::string iconName; std::shared_ptr texture; glm::vec3 offset = {0.f, 6.0f, 0.f}; diff --git a/src/game/GameLayer.cpp b/src/game/GameLayer.cpp index f742d78..5f66d55 100644 --- a/src/game/GameLayer.cpp +++ b/src/game/GameLayer.cpp @@ -59,25 +59,7 @@ void GameLayer::onAttach() AssetManager::loadAsset("assets/buildings/forest_hut/cabin.json", loader); auto modelTexture = AssetManager::loadTexture("warning", "assets/worldIcons/warning.png", loader); - - TransformComponent transformComponent(glm::vec3(0,0,0), glm::vec3(0), 1.0f); - testEntity = BuildingFactory::create(*entityManager, TemporaryBuildingDefinitionFactory::createForestHutDefinition(), transformComponent, 0, 0); - auto worldSpritePtr = std::make_shared(); - worldSpritePtr->texture = modelTexture; - entityManager->addComponent(testEntity, worldSpritePtr); - - auto anim = std::make_shared(); - - float baseY = worldSpritePtr->offset.y; - - anim->tracks.push_back({ - AnimationCurve{CurveType::Sine, 0.3f, 5.f}, - [worldSpritePtr, baseY](float v) { - worldSpritePtr->offset.y = baseY + v; - } - }); - - entityManager->addComponent(testEntity, anim); + AssetManager::loadTexture("error", "assets/worldIcons/error.png", loader); events.subscribe([this](const TurnChangedEvent& event) { diff --git a/src/game/hexWorld/ecs/systems/ProducingSystem.cpp b/src/game/hexWorld/ecs/systems/ProducingSystem.cpp index 8fe078d..a512b3c 100644 --- a/src/game/hexWorld/ecs/systems/ProducingSystem.cpp +++ b/src/game/hexWorld/ecs/systems/ProducingSystem.cpp @@ -7,10 +7,18 @@ #include #include +#include "../../../../engine/core/animations/AnimationComponent.h" #include "../../../../engine/core/ECS/EntityManager.h" #include "../../../../engine/core/ECS/ModelStateComponent.h" +#include "../../../../engine/core/ECS/WorldSpriteComponent.h" +#include "../../../../engine/renderer/loader/AssetManager.h" #include "../components/ProducingComponent.h" +std::vector ProducingSystem::storageIcons = { + {0.75f, 0.99f, "warning"}, + {0.99f, 1.0f, "error"} +}; + void ProducingSystem::onTurnEnded(EntityManager &em) { for (const EntityID e : em.getAllEntities()) { const auto prod = em.getComponent(e); @@ -30,5 +38,51 @@ void ProducingSystem::onTurnEnded(EntityManager &em) { float fillRatio = static_cast(prod->getStorage()) / static_cast(prod->getMaxStorage()); modelState->params["fillRatio"] = fillRatio; + + // -- Icon / Animation Logik + for (const auto& status : storageIcons) { + if (fillRatio >= status.minRatio && fillRatio <= status.maxRatio) { + auto spriteComp = em.getComponent(e); + if (spriteComp) { + if (spriteComp->iconName != status.iconName) { + spriteComp->iconName = status.iconName; + spriteComp->texture = AssetManager::getTexture(status.iconName); + } + } else { + createWorldSprite(em, e, status.iconName); + } + break; + } + } + } +} + +void ProducingSystem::createWorldSprite(EntityManager &em, EntityID e, const std::string &iconName) { + auto iconTexture = AssetManager::getTexture(iconName); + + auto worldSpritePtr = std::make_shared(); + std::weak_ptr weakSprite = worldSpritePtr; + worldSpritePtr->texture = iconTexture; + worldSpritePtr->iconName = iconName; + + auto anim = std::make_shared(); + + float baseY = worldSpritePtr->offset.y; + + anim->tracks.push_back({ + AnimationCurve{CurveType::Sine, 0.3f, 5.f}, + [weakSprite, baseY](float v) { + if (auto sprite = weakSprite.lock()) { + sprite->offset.y = baseY + v; + } + } + }); + + if (!em.getComponent(e)) { + em.addComponent(e, worldSpritePtr); + } + + if (!em.getComponent(e)) { + em.addComponent(e, anim); } } diff --git a/src/game/hexWorld/ecs/systems/ProducingSystem.h b/src/game/hexWorld/ecs/systems/ProducingSystem.h index 84bce98..3740697 100644 --- a/src/game/hexWorld/ecs/systems/ProducingSystem.h +++ b/src/game/hexWorld/ecs/systems/ProducingSystem.h @@ -4,14 +4,27 @@ #ifndef DICEWARS_SIEDLER_PRODUCINGSYSTEM_H #define DICEWARS_SIEDLER_PRODUCINGSYSTEM_H +#include + +#include "../../../../engine/core/ECS/WorldSpriteComponent.h" #include "../../../player/Player.h" +struct StorageStatus { + float minRatio = 0.0; + float maxRatio = 1.0; + std::string iconName; +}; class EntityManager; class ProducingSystem { public: static void onTurnEnded(EntityManager &em); + +private: + static std::vector storageIcons; + + static void createWorldSprite(EntityManager &em, uint32_t e, const std::string &iconName); };