0
0
mirror of https://github.com/Nimac0/SDL_Minigame synced 2026-01-12 10:13:42 +00:00
SDL_Minigame/include/DataComponent.h
Nimac0 044d957106 feat: data and stats
- reimplemented/unhardcoded stateffects
- reimplemented/unhardcoded pickupables
- implemented datacomponent
- some minor cleanup
2025-01-28 17:31:03 +01:00

26 lines
695 B
C++

#pragma once
#include <map>
#include <any>
#include <string>
#include <optional>
#include "Component.h"
class DataComponent : public Component
{
public:
DataComponent() {};
~DataComponent() {};
template <typename T>
void setEntry(const std::string& key, const T& value) { dataMap.insert_or_assign(key, value); }
template<typename T>
std::optional<T> getEntry(std::string key) const {
if (!this->dataMap.contains(key)) return std::nullopt;
const std::any& value = this->dataMap.at(key);
if (value.type() != typeid(T)) { return std::nullopt; }
return std::any_cast<T>(value);
}
private:
std::map<std::string, std::any> dataMap;
};