ADD: Create WorldSprits when Inventory of Building is full
This commit is contained in:
parent
1941ee3690
commit
f1f1dde9b5
BIN
assets/worldIcons/error.png
Normal file
BIN
assets/worldIcons/error.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
@ -13,6 +13,7 @@
|
||||
|
||||
class WorldSpriteComponent : public Component {
|
||||
public:
|
||||
std::string iconName;
|
||||
std::shared_ptr<ModelTexture> texture;
|
||||
|
||||
glm::vec3 offset = {0.f, 6.0f, 0.f};
|
||||
|
||||
@ -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<WorldSpriteComponent>();
|
||||
worldSpritePtr->texture = modelTexture;
|
||||
entityManager->addComponent(testEntity, worldSpritePtr);
|
||||
|
||||
auto anim = std::make_shared<AnimationComponent>();
|
||||
|
||||
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<TurnChangedEvent>([this](const TurnChangedEvent& event) {
|
||||
|
||||
@ -7,10 +7,18 @@
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
#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<StorageStatus> 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<ProducingComponent>(e);
|
||||
@ -30,5 +38,51 @@ void ProducingSystem::onTurnEnded(EntityManager &em) {
|
||||
|
||||
float fillRatio = static_cast<float>(prod->getStorage()) / static_cast<float>(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<WorldSpriteComponent>(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<WorldSpriteComponent>();
|
||||
std::weak_ptr<WorldSpriteComponent> weakSprite = worldSpritePtr;
|
||||
worldSpritePtr->texture = iconTexture;
|
||||
worldSpritePtr->iconName = iconName;
|
||||
|
||||
auto anim = std::make_shared<AnimationComponent>();
|
||||
|
||||
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<WorldSpriteComponent>(e)) {
|
||||
em.addComponent(e, worldSpritePtr);
|
||||
}
|
||||
|
||||
if (!em.getComponent<AnimationComponent>(e)) {
|
||||
em.addComponent(e, anim);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,14 +4,27 @@
|
||||
|
||||
#ifndef DICEWARS_SIEDLER_PRODUCINGSYSTEM_H
|
||||
#define DICEWARS_SIEDLER_PRODUCINGSYSTEM_H
|
||||
#include <vector>
|
||||
|
||||
#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<StorageStatus> storageIcons;
|
||||
|
||||
static void createWorldSprite(EntityManager &em, uint32_t e, const std::string &iconName);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user