Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
NodeAnnotations.cpp
Go to the documentation of this file.
1/**
2 * @file NodeAnnotations.cpp
3 * @brief Implementation of NodeAnnotationsManager (Phase 2.0)
4 * @author Olympe Engine
5 * @date 2026-02-19
6 */
7
8#include "NodeAnnotations.h"
9#include "../system/system_utils.h"
10
11namespace Olympe {
12namespace NodeGraph {
13
14// ============================================================================
15// Query
16// ============================================================================
17
19{
20 return m_annotations.find(nodeId) != m_annotations.end();
21}
22
24{
25 auto it = m_annotations.find(nodeId);
26 if (it != m_annotations.end())
27 {
28 return &it->second;
29 }
30 return nullptr;
31}
32
34{
35 auto it = m_annotations.find(nodeId);
36 if (it != m_annotations.end())
37 {
38 return &it->second;
39 }
40 return nullptr;
41}
42
43// ============================================================================
44// Mutation
45// ============================================================================
46
47void NodeAnnotationsManager::SetBreakpoint(int nodeId, bool enabled)
48{
50 ann.hasBreakpoint = enabled;
51 SYSTEM_LOG << "[NodeAnnotations] Node " << nodeId
52 << " breakpoint: " << (enabled ? "ON" : "OFF") << std::endl;
53}
54
55void NodeAnnotationsManager::SetComment(int nodeId, const std::string& text)
56{
58 ann.comment = text;
59 SYSTEM_LOG << "[NodeAnnotations] Node " << nodeId << " comment set" << std::endl;
60}
61
62void NodeAnnotationsManager::SetColor(int nodeId, float r, float g, float b, float a)
63{
65 ann.colorR = r;
66 ann.colorG = g;
67 ann.colorB = b;
68 ann.colorA = a;
69}
70
72{
73 m_annotations.erase(nodeId);
74 SYSTEM_LOG << "[NodeAnnotations] Node " << nodeId << " annotation cleared" << std::endl;
75}
76
77// ============================================================================
78// Accessors
79// ============================================================================
80
81const std::map<int, NodeAnnotation>& NodeAnnotationsManager::GetAll() const
82{
83 return m_annotations;
84}
85
86// ============================================================================
87// Serialization
88// ============================================================================
89
91{
92 json arr = json::array();
93 for (auto it = m_annotations.begin(); it != m_annotations.end(); ++it)
94 {
95 const NodeAnnotation& ann = it->second;
96 json entry = json::object();
97 entry["nodeId"] = ann.nodeId;
98 entry["hasBreakpoint"] = ann.hasBreakpoint;
99 entry["comment"] = ann.comment;
100 json colorObj = json::object();
101 colorObj["r"] = ann.colorR;
102 colorObj["g"] = ann.colorG;
103 colorObj["b"] = ann.colorB;
104 colorObj["a"] = ann.colorA;
105 entry["color"] = colorObj;
106 arr.push_back(entry);
107 }
108 return arr;
109}
110
112{
113 m_annotations.clear();
114
115 if (!j.is_array())
116 {
117 return;
118 }
119
120 for (size_t i = 0; i < j.size(); ++i)
121 {
122 const json& entry = j[i];
123 if (!entry.is_object())
124 {
125 continue;
126 }
127
128 int nodeId = JsonHelper::GetInt(entry, "nodeId", 0);
129 if (nodeId <= 0)
130 {
131 continue;
132 }
133
135 ann.nodeId = nodeId;
136 ann.hasBreakpoint = JsonHelper::GetBool(entry, "hasBreakpoint", false);
137 ann.comment = JsonHelper::GetString(entry, "comment", "");
138
139 if (entry.contains("color") && entry["color"].is_object())
140 {
141 const json& col = entry["color"];
142 ann.colorR = JsonHelper::GetFloat(col, "r", 1.0f);
143 ann.colorG = JsonHelper::GetFloat(col, "g", 1.0f);
144 ann.colorB = JsonHelper::GetFloat(col, "b", 1.0f);
145 ann.colorA = JsonHelper::GetFloat(col, "a", 1.0f);
146 }
147
148 m_annotations[nodeId] = ann;
149 }
150}
151
152// ============================================================================
153// Private helpers
154// ============================================================================
155
157{
158 auto it = m_annotations.find(nodeId);
159 if (it != m_annotations.end())
160 {
161 return it->second;
162 }
163
165 ann.nodeId = nodeId;
166 m_annotations[nodeId] = ann;
167 return m_annotations[nodeId];
168}
169
170} // namespace NodeGraph
171} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Per-node annotations manager for node graphs (Phase 2.0)
void ClearAnnotation(int nodeId)
Remove all annotation data for a node.
json ToJson() const
Serialize all annotations to JSON.
void SetComment(int nodeId, const std::string &text)
Set comment for a node.
void SetBreakpoint(int nodeId, bool enabled)
Set breakpoint state for a node.
const std::map< int, NodeAnnotation > & GetAll() const
Get all annotations (for serialization / rendering)
std::map< int, NodeAnnotation > m_annotations
NodeAnnotation * GetAnnotation(int nodeId)
Get annotation for a node (non-const)
NodeAnnotation & GetOrCreate(int nodeId)
Get or create annotation for a node.
void FromJson(const json &j)
Deserialize annotations from JSON.
void SetColor(int nodeId, float r, float g, float b, float a)
Set custom color for a node.
bool HasAnnotation(int nodeId) const
Check if a node has any annotation.
std::string GetString(const json &j, const std::string &key, const std::string &defaultValue="")
Safely get a string value from JSON.
int GetInt(const json &j, const std::string &key, int defaultValue=0)
Safely get an integer value from JSON.
float GetFloat(const json &j, const std::string &key, float defaultValue=0.0f)
Safely get a float value from JSON.
bool GetBool(const json &j, const std::string &key, bool defaultValue=false)
Safely get a boolean value from JSON.
< Provides AssetID and INVALID_ASSET_ID
nlohmann::json json
Holds annotation data for a single node.
#define SYSTEM_LOG