12#include "../json_helper.h"
13#include "../system/system_utils.h"
43 SYSTEM_LOG <<
"[BlackboardVariablePresetRegistry] LoadFromFile: failed to open '"
48 if (!
root.contains(
"availableVariables") || !
root[
"availableVariables"].is_array())
50 SYSTEM_LOG <<
"[BlackboardVariablePresetRegistry] LoadFromFile: missing or invalid"
51 " 'availableVariables' array in '" << filePath <<
"'\n";
58 for (
size_t i = 0;
i <
arr.size(); ++
i)
62 if (!
item.contains(
"name") || !
item[
"name"].is_string())
64 SYSTEM_LOG <<
"[BlackboardVariablePresetRegistry] LoadFromFile: entry " <<
i
65 <<
" missing 'name' — skipping\n";
78 SYSTEM_LOG <<
"[BlackboardVariablePresetRegistry] LoadFromFile: entry " <<
i
79 <<
" has empty 'name' — skipping\n";
85 SYSTEM_LOG <<
"[BlackboardVariablePresetRegistry] LoadFromFile: duplicate preset '"
86 <<
preset.name <<
"' — skipping\n";
97 return a.name < b.name;
105 SYSTEM_LOG <<
"[BlackboardVariablePresetRegistry] LoadFromFile: loaded "
106 <<
m_presets.size() <<
" presets from '" << filePath <<
"'\n";
114const std::vector<BlackboardVariablePreset>&
124 std::unordered_map<std::string, size_t>::const_iterator
it =
m_nameIndex.find(name);
130std::vector<BlackboardVariablePreset>
133 std::vector<BlackboardVariablePreset> result;
144 std::vector<std::string> categories;
151 for (
size_t j = 0;
j < categories.size(); ++
j)
153 if (categories[
j] ==
cat)
160 categories.push_back(
cat);
162 std::sort(categories.begin(), categories.end());
Singleton registry for blackboard variable presets loaded from JSON config.
ComponentTypeID GetComponentTypeID_Static()
Singleton registry for global blackboard variable presets.
const BlackboardVariablePreset * GetPreset(const std::string &name) const
Returns a pointer to the preset with the given name, or nullptr.
std::mutex m_mutex
Guards m_presets during concurrent access.
std::vector< BlackboardVariablePreset > m_presets
size_t GetCount() const
Returns the number of loaded presets.
const std::vector< BlackboardVariablePreset > & GetAllPresets() const
Returns all loaded presets, sorted by name.
static BlackboardVariablePresetRegistry & Instance()
Returns the singleton instance.
std::unordered_map< std::string, size_t > m_nameIndex
name -> index in m_presets
bool LoadFromFile(const std::string &filePath)
Loads presets from a JSON file.
std::vector< BlackboardVariablePreset > GetByCategory(const std::string &category) const
Returns all presets belonging to a given category.
bool HasPreset(const std::string &name) const
Returns true if a preset with the given name exists.
void Clear()
Clears all loaded presets and resets the registry.
std::vector< std::string > GetAllCategories() const
Returns all unique category names present in the registry.
std::string GetString(const json &j, const std::string &key, const std::string &defaultValue="")
Safely get a string value from JSON.
bool LoadJsonFromFile(const std::string &filepath, json &j)
Load and parse a JSON file.
< Provides AssetID and INVALID_ASSET_ID
Metadata for a single blackboard variable preset entry.
std::string category
Category label (e.g. "Targeting", "Movement")
std::string name
Variable key (e.g. "targetDistance")