Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
NodePresets.h
Go to the documentation of this file.
1/**
2 * @file NodePresets.h
3 * @brief Node preset / template system for frequently used node configurations (Phase 9).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 *
7 * @details
8 * NodePresets allows users to save and recall commonly used node configurations.
9 * A preset can cover a single node (its type and parameter defaults) or a set
10 * of connected nodes (a mini-graph snippet).
11 *
12 * NodePresetManager is a Meyers singleton that owns all presets.
13 * Presets are serialised to / deserialised from JSON.
14 *
15 * No ImGui dependency.
16 *
17 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
18 */
19
20#pragma once
21
22#include <string>
23#include <vector>
24
25#include "../third_party/nlohmann/json.hpp"
26
27namespace Olympe {
28
29// ============================================================================
30// NodePreset
31// ============================================================================
32
33/**
34 * @struct NodePreset
35 * @brief A saved node configuration that can be applied to the active graph.
36 */
37struct NodePreset {
38 std::string name; ///< Unique preset identifier
39 std::string description; ///< Human-readable description
40 std::string category; ///< Category for grouping in the UI
41 nlohmann::json nodeData; ///< JSON snapshot of the node(s)
42 std::vector<int> nodeIds; ///< For multi-node presets: list of involved IDs
43
44 nlohmann::json ToJson() const;
45 static NodePreset FromJson(const nlohmann::json& j);
46};
47
48// ============================================================================
49// NodePresetManager
50// ============================================================================
51
52/**
53 * @class NodePresetManager
54 * @brief Singleton that stores, serialises, and retrieves NodePreset instances.
55 *
56 * Typical usage:
57 * @code
58 * auto& pm = NodePresetManager::Get();
59 * pm.LoadPresets("Config/presets.json");
60 *
61 * NodePreset p;
62 * p.name = "MyPatrol";
63 * p.category = "AI";
64 * pm.AddPreset(p);
65 *
66 * auto* found = pm.GetPreset("MyPatrol");
67 * @endcode
68 */
70public:
71
72 // -----------------------------------------------------------------------
73 // Singleton access
74 // -----------------------------------------------------------------------
75
76 /** @brief Returns the single shared instance. */
77 static NodePresetManager& Get();
78
79 // -----------------------------------------------------------------------
80 // Persistence
81 // -----------------------------------------------------------------------
82
83 /**
84 * @brief Loads presets from a JSON file at @p path.
85 * Existing presets are replaced.
86 */
87 void LoadPresets(const std::string& path);
88
89 /**
90 * @brief Saves all current presets to a JSON file at @p path.
91 */
92 void SavePresets(const std::string& path) const;
93
94 // -----------------------------------------------------------------------
95 // CRUD
96 // -----------------------------------------------------------------------
97
98 /** @brief Adds or replaces a preset (matched by name). */
99 void AddPreset(const NodePreset& preset);
100
101 /** @brief Removes the preset with the given name. No-op if not found. */
102 void RemovePreset(const std::string& name);
103
104 /**
105 * @brief Returns a pointer to the preset with the given name.
106 * @return Pointer, or nullptr if not found.
107 */
108 NodePreset* GetPreset(const std::string& name);
109
110 /**
111 * @brief Returns all presets that belong to @p category.
112 */
113 std::vector<NodePreset> GetPresetsInCategory(const std::string& category) const;
114
115 /** @brief Returns the total number of stored presets. */
116 int GetPresetCount() const;
117
118 /** @brief Removes all presets. */
119 void Clear();
120
121private:
122
124
125 std::vector<NodePreset> m_Presets;
126};
127
128} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton that stores, serialises, and retrieves NodePreset instances.
Definition NodePresets.h:69
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
nlohmann::json json
A saved node configuration that can be applied to the active graph.
Definition NodePresets.h:37
nlohmann::json nodeData
JSON snapshot of the node(s)
Definition NodePresets.h:41
static NodePreset FromJson(const nlohmann::json &j)
std::string name
Unique preset identifier.
Definition NodePresets.h:38
nlohmann::json ToJson() const
std::vector< int > nodeIds
For multi-node presets: list of involved IDs.
Definition NodePresets.h:42
std::string description
Human-readable description.
Definition NodePresets.h:39
std::string category
Category for grouping in the UI.
Definition NodePresets.h:40