12#include "../system/system_utils.h"
24 json j = json::object();
42 if (
j.contains(
"name") &&
j[
"name"].is_string())
43 p.
name =
j[
"name"].get<std::string>();
45 if (
j.contains(
"description") &&
j[
"description"].is_string())
46 p.description =
j[
"description"].get<std::string>();
48 if (
j.contains(
"category") &&
j[
"category"].is_string())
49 p.category =
j[
"category"].get<std::string>();
51 if (
j.contains(
"nodeData"))
52 p.nodeData =
j[
"nodeData"];
54 if (
j.contains(
"nodeIds") &&
j[
"nodeIds"].is_array())
59 if (
it->is_number_integer())
60 p.nodeIds.push_back(
it->get<
int>());
89 std::ifstream
ifs(path.c_str());
92 SYSTEM_LOG <<
"[NodePresetManager] Cannot open '" << path <<
"' for reading."
104 SYSTEM_LOG <<
"[NodePresetManager] JSON parse error in '" << path <<
"'."
109 if (!
root.contains(
"presets") || !
root[
"presets"].is_array())
111 SYSTEM_LOG <<
"[NodePresetManager] '" << path <<
"' has no 'presets' array."
121 <<
" preset(s) from '" << path <<
"'." << std::endl;
132 std::ofstream
ofs(path.c_str());
135 SYSTEM_LOG <<
"[NodePresetManager] Cannot open '" << path <<
"' for writing."
142 <<
" preset(s) to '" << path <<
"'." << std::endl;
186 const std::string& category)
const
188 std::vector<NodePreset> result;
199 return static_cast<int>(
m_Presets.size());
ComponentTypeID GetComponentTypeID_Static()
Node preset / template system for frequently used node configurations (Phase 9).
Singleton that stores, serialises, and retrieves NodePreset instances.
std::vector< NodePreset > GetPresetsInCategory(const std::string &category) const
Returns all presets that belong to category.
NodePreset * GetPreset(const std::string &name)
Returns a pointer to the preset with the given name.
int GetPresetCount() const
Returns the total number of stored presets.
void AddPreset(const NodePreset &preset)
Adds or replaces a preset (matched by name).
void SavePresets(const std::string &path) const
Saves all current presets to a JSON file at path.
void LoadPresets(const std::string &path)
Loads presets from a JSON file at path.
std::vector< NodePreset > m_Presets
void Clear()
Removes all presets.
static NodePresetManager & Get()
Returns the single shared instance.
void RemovePreset(const std::string &name)
Removes the preset with the given name.
< Provides AssetID and INVALID_ASSET_ID
A saved node configuration that can be applied to the active graph.
nlohmann::json nodeData
JSON snapshot of the node(s)
static NodePreset FromJson(const nlohmann::json &j)
std::string name
Unique preset identifier.
nlohmann::json ToJson() const
std::vector< int > nodeIds
For multi-node presets: list of involved IDs.
std::string description
Human-readable description.
std::string category
Category for grouping in the UI.