Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
NodeGroup.h
Go to the documentation of this file.
1/**
2 * @file NodeGroup.h
3 * @brief Node grouping and collapse system for node graphs (Phase 9).
4 * @author Olympe Engine
5 * @date 2026-03-09
6 *
7 * @details
8 * NodeGroup allows the user to logically associate a set of nodes under a
9 * named, coloured header. A collapsed group renders only the header bar,
10 * hiding the individual nodes to reduce visual clutter.
11 *
12 * GroupManager is a Meyers singleton that owns all groups. It is UI-agnostic;
13 * the rendering layer reads the group data each frame.
14 *
15 * C++14 compliant — no std::optional, structured bindings, std::filesystem.
16 */
17
18#pragma once
19
20#include <string>
21#include <vector>
22
23#include "../third_party/nlohmann/json.hpp"
24
25namespace Olympe {
26
27// ============================================================================
28// NodeGroup
29// ============================================================================
30
31/**
32 * @struct NodeGroup
33 * @brief A named set of node IDs that can be collapsed into a single header.
34 */
35struct NodeGroup {
36 int id = -1; ///< Unique group ID
37 std::string name; ///< Display name for the group
38 std::vector<int> nodeIds; ///< IDs of member nodes
39 bool isCollapsed = false; ///< True = render as header only
40 float collapsedPosX = 0.0f; ///< Position used when collapsed
41 float collapsedPosY = 0.0f;
42 unsigned int headerColor = 0xFF4444FFu; ///< RGBA packed (default: blue)
43
44 nlohmann::json ToJson() const;
45 static NodeGroup FromJson(const nlohmann::json& j);
46};
47
48// ============================================================================
49// GroupManager
50// ============================================================================
51
52/**
53 * @class GroupManager
54 * @brief Singleton that owns all NodeGroup instances for the active graph.
55 *
56 * Typical usage:
57 * @code
58 * auto& gm = GroupManager::Get();
59 * std::vector<int> ids = {1, 2, 3};
60 * int gid = gm.CreateGroup("Patrol Logic", ids);
61 * gm.CollapseGroup(gid);
62 * @endcode
63 */
65public:
66
67 // -----------------------------------------------------------------------
68 // Singleton access
69 // -----------------------------------------------------------------------
70
71 /** @brief Returns the single shared instance. */
72 static GroupManager& Get();
73
74 // -----------------------------------------------------------------------
75 // Lifecycle
76 // -----------------------------------------------------------------------
77
78 /**
79 * @brief Creates a new group from the given node IDs.
80 * @return The assigned group ID.
81 */
82 int CreateGroup(const std::string& name, const std::vector<int>& nodeIds);
83
84 /** @brief Deletes the group with the given ID. No-op if not found. */
85 void DeleteGroup(int groupId);
86
87 /** @brief Marks the group as collapsed. No-op if not found. */
88 void CollapseGroup(int groupId);
89
90 /** @brief Marks the group as expanded. No-op if not found. */
91 void ExpandGroup(int groupId);
92
93 /**
94 * @brief Returns a pointer to the group with the given ID.
95 * @return Pointer, or nullptr if not found.
96 */
98
99 /** @brief Returns the total number of groups. */
100 int GetGroupCount() const;
101
102 /** @brief Removes all groups and resets the ID counter. */
103 void Clear();
104
105 // -----------------------------------------------------------------------
106 // Serialisation
107 // -----------------------------------------------------------------------
108
109 void SaveToJson(nlohmann::json& j) const;
110 void LoadFromJson(const nlohmann::json& j);
111
112private:
113
114 GroupManager();
115
116 std::vector<NodeGroup> m_Groups;
118};
119
120} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Singleton that owns all NodeGroup instances for the active graph.
Definition NodeGroup.h:64
static GroupManager & Get()
Returns the single shared instance.
Definition NodeGroup.cpp:77
void LoadFromJson(const nlohmann::json &j)
void ExpandGroup(int groupId)
Marks the group as expanded.
void Clear()
Removes all groups and resets the ID counter.
void DeleteGroup(int groupId)
Deletes the group with the given ID.
NodeGroup * GetGroup(int groupId)
Returns a pointer to the group with the given ID.
int CreateGroup(const std::string &name, const std::vector< int > &nodeIds)
Creates a new group from the given node IDs.
Definition NodeGroup.cpp:92
int GetGroupCount() const
Returns the total number of groups.
std::vector< NodeGroup > m_Groups
Definition NodeGroup.h:116
void CollapseGroup(int groupId)
Marks the group as collapsed.
void SaveToJson(nlohmann::json &j) const
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json
A named set of node IDs that can be collapsed into a single header.
Definition NodeGroup.h:35
unsigned int headerColor
RGBA packed (default: blue)
Definition NodeGroup.h:42
bool isCollapsed
True = render as header only.
Definition NodeGroup.h:39
float collapsedPosX
Position used when collapsed.
Definition NodeGroup.h:40
static NodeGroup FromJson(const nlohmann::json &j)
Definition NodeGroup.cpp:38
std::string name
Display name for the group.
Definition NodeGroup.h:37
nlohmann::json ToJson() const
Definition NodeGroup.cpp:20
std::vector< int > nodeIds
IDs of member nodes.
Definition NodeGroup.h:38