Files
dota_factory/src/lib/ecs/system/ScrapSystem.h

42 lines
986 B
C++

#pragma once
#include <optional>
#include <vector>
#include <QVector2D>
#include "Tick.h"
#include "entt/entity/entity.hpp"
class EntityAdmin;
struct ScrapInfo
{
entt::entity entity;
QVector2D position;
};
class ScrapSystem
{
public:
explicit ScrapSystem(EntityAdmin& admin);
entt::entity spawn(QVector2D position, int amount, Tick despawnAt);
void tickDespawn(Tick currentTick);
// Removes the scrap and returns its amount, or nullopt if not found.
std::optional<int> consume(entt::entity entity);
// Collects a single scrap unit from the pile: decrements its amount by one,
// destroying the entity once depleted. Returns true if a scrap was collected,
// false if the entity is invalid or already empty (REQ-SHP-SALVAGE).
bool collectOne(entt::entity entity);
// Lightweight snapshot for callers that need to iterate all scrap.
std::vector<ScrapInfo> allScrapInfo() const;
private:
EntityAdmin& m_admin;
};