6#include "../json_helper.h"
22 : m_Initialized(
false)
23 , m_CatalogsPath(
"Blueprints/Catalogues/")
37 std::cout <<
"[EnumCatalogManager] Initializing...\n";
42 std::cerr <<
"[EnumCatalogManager] Failed to load catalogs: " <<
m_LastError <<
"\n";
47 std::cout <<
"[EnumCatalogManager] Initialized successfully\n";
55 std::cout <<
"[EnumCatalogManager] Shutting down...\n";
74 std::cerr <<
"[EnumCatalogManager] Failed to load ActionTypes catalog\n";
80 std::cerr <<
"[EnumCatalogManager] Failed to load ConditionTypes catalog\n";
86 std::cerr <<
"[EnumCatalogManager] Failed to load DecoratorTypes catalog\n";
95 std::cout <<
"[EnumCatalogManager] Loading catalog: " << filepath <<
"\n";
98 std::ifstream
file(filepath);
105 std::string
jsonText((std::istreambuf_iterator<char>(
file)), std::istreambuf_iterator<char>());
110 catch (
const std::exception&
e)
112 m_LastError =
"JSON parse error: " + std::string(
e.what());
117 auto catalog = std::make_unique<EnumCatalog>();
122 m_LastError =
"Failed to parse catalog: " + filepath;
135 if (
catalog->catalogType ==
"Actions")
138 std::cout <<
"[EnumCatalogManager] Loaded " <<
m_ActionCatalog->types.size() <<
" action types\n";
140 else if (
catalog->catalogType ==
"Conditions")
143 std::cout <<
"[EnumCatalogManager] Loaded " <<
m_ConditionCatalog->types.size() <<
" condition types\n";
145 else if (
catalog->catalogType ==
"Decorators")
148 std::cout <<
"[EnumCatalogManager] Loaded " <<
m_DecoratorCatalog->types.size() <<
" decorator types\n";
161 std::cout <<
"[EnumCatalogManager] Hot-reloading catalogs...\n";
179 if (
catalog.catalogType.empty())
225 return !type.
id.empty();
235 if (
j.contains(
"default"))
246 return !
param.name.empty();
258 std::map<std::string, int>
idCount;
259 for (
const auto& type :
catalog.types)
263 errorMsg =
"Type with empty ID found";
ComponentTypeID GetComponentTypeID_Static()
EnumCatalogManager - Singleton manager for enum catalogs Loads and manages dynamic type definitions f...
const CatalogType * FindActionType(const std::string &id) const
bool IsValidActionType(const std::string &id) const
std::vector< std::string > GetDecoratorTypes() const
std::vector< std::string > GetActionTypes() const
bool ParseCatalogParameter(const nlohmann::json &j, CatalogParameter ¶m)
bool ValidateCatalog(const EnumCatalog &catalog, std::string &errorMsg)
const CatalogType * FindDecoratorType(const std::string &id) const
bool IsValidDecoratorType(const std::string &id) const
bool IsValidConditionType(const std::string &id) const
std::vector< std::string > GetConditionTypes() const
bool ParseCatalogType(const nlohmann::json &j, CatalogType &type)
bool ParseCatalogJson(const nlohmann::json &j, EnumCatalog &catalog)
bool LoadCatalog(const std::string &filepath)
std::string m_CatalogsPath
bool LoadCatalogs(const std::string &catalogsPath)
static EnumCatalogManager & Instance()
std::unique_ptr< EnumCatalog > m_ConditionCatalog
std::unique_ptr< EnumCatalog > m_ActionCatalog
const CatalogType * FindConditionType(const std::string &id) const
std::unique_ptr< EnumCatalog > m_DecoratorCatalog
std::string GetString(const json &j, const std::string &key, const std::string &defaultValue="")
Safely get a string value from JSON.
void ForEachInArray(const json &j, const std::string &key, std::function< void(const json &, size_t)> callback)
Iterate over an array with a callback function.
bool IsArray(const json &j, const std::string &key)
Check if a key contains an array.
bool GetBool(const json &j, const std::string &key, bool defaultValue=false)
Safely get a boolean value from JSON.
std::vector< CatalogParameter > parameters