Olympe Engine
2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
Source
NodeGraphCore
GraphComment.cpp
Go to the documentation of this file.
1
/**
2
* @file GraphComment.cpp
3
* @brief CommentManager and GraphComment serialisation (Phase 9).
4
* @author Olympe Engine
5
* @date 2026-03-09
6
*/
7
8
#include "
GraphComment.h
"
9
10
#include "../system/system_utils.h"
11
12
using
json
=
nlohmann::json
;
13
14
namespace
Olympe
{
15
16
// ============================================================================
17
// GraphComment serialisation
18
// ============================================================================
19
20
json
GraphComment::ToJson
()
const
21
{
22
json
j
= json::object();
23
j
[
"id"
] =
id
;
24
j
[
"text"
] =
text
;
25
j
[
"posX"
] =
posX
;
26
j
[
"posY"
] =
posY
;
27
j
[
"w"
] =
width
;
28
j
[
"h"
] =
height
;
29
j
[
"color"
] =
static_cast<
int
>
(
color
);
30
j
[
"font"
] =
fontSize
;
31
j
[
"vis"
] =
isVisible
;
32
return
j
;
33
}
34
35
GraphComment
GraphComment::FromJson
(
const
json
&
j
)
36
{
37
GraphComment
c
;
38
39
if
(
j
.contains(
"id"
) &&
j
[
"id"
].is_number_integer())
40
c
.
id
=
j
[
"id"
].get<
int
>();
41
42
if
(
j
.contains(
"text"
) &&
j
[
"text"
].is_string())
43
c
.text =
j
[
"text"
].get<std::string>();
44
45
if
(
j
.contains(
"posX"
) &&
j
[
"posX"
].is_number())
46
c
.posX =
j
[
"posX"
].get<
float
>();
47
48
if
(
j
.contains(
"posY"
) &&
j
[
"posY"
].is_number())
49
c
.posY =
j
[
"posY"
].get<
float
>();
50
51
if
(
j
.contains(
"w"
) &&
j
[
"w"
].is_number())
52
c
.width =
j
[
"w"
].get<
float
>();
53
54
if
(
j
.contains(
"h"
) &&
j
[
"h"
].is_number())
55
c
.height =
j
[
"h"
].get<
float
>();
56
57
if
(
j
.contains(
"color"
) &&
j
[
"color"
].is_number_integer())
58
c
.color =
j
[
"color"
].get<
unsigned
int
>();
59
60
if
(
j
.contains(
"font"
) &&
j
[
"font"
].is_number())
61
c
.fontSize =
j
[
"font"
].get<
float
>();
62
63
if
(
j
.contains(
"vis"
) &&
j
[
"vis"
].is_boolean())
64
c
.isVisible =
j
[
"vis"
].get<
bool
>();
65
66
return
c
;
67
}
68
69
// ============================================================================
70
// CommentManager — Singleton
71
// ============================================================================
72
73
CommentManager
&
CommentManager::Get
()
74
{
75
static
CommentManager
s_Instance;
76
return
s_Instance;
77
}
78
79
CommentManager::CommentManager
()
80
: m_NextCommentId(1)
81
{
82
}
83
84
// ============================================================================
85
// CRUD
86
// ============================================================================
87
88
int
CommentManager::AddComment
(
const
GraphComment
& comment)
89
{
90
GraphComment
c
= comment;
91
c
.
id
=
m_NextCommentId
++;
92
m_Comments
.push_back(
c
);
93
return
c
.id;
94
}
95
96
void
CommentManager::RemoveComment
(
int
commentId
)
97
{
98
for
(
size_t
i
= 0;
i
<
m_Comments
.size(); ++
i
)
99
{
100
if
(
m_Comments
[
i
].
id
==
commentId
)
101
{
102
m_Comments
.erase(
m_Comments
.begin() +
static_cast<
int
>
(
i
));
103
return
;
104
}
105
}
106
}
107
108
GraphComment
*
CommentManager::GetComment
(
int
commentId
)
109
{
110
for
(
size_t
i
= 0;
i
<
m_Comments
.size(); ++
i
)
111
{
112
if
(
m_Comments
[
i
].
id
==
commentId
)
113
return
&
m_Comments
[
i
];
114
}
115
return
nullptr
;
116
}
117
118
void
CommentManager::UpdateComment
(
int
commentId
,
const
GraphComment
& comment)
119
{
120
for
(
size_t
i
= 0;
i
<
m_Comments
.size(); ++
i
)
121
{
122
if
(
m_Comments
[
i
].
id
==
commentId
)
123
{
124
GraphComment
updated
= comment;
125
updated
.
id
=
commentId
;
// preserve ID
126
m_Comments
[
i
] =
updated
;
127
return
;
128
}
129
}
130
SYSTEM_LOG
<<
"[CommentManager] UpdateComment: ID "
<<
commentId
131
<<
" not found."
<< std::endl;
132
}
133
134
int
CommentManager::GetCommentCount
()
const
135
{
136
return
static_cast<
int
>
(
m_Comments
.size());
137
}
138
139
void
CommentManager::Clear
()
140
{
141
m_Comments
.clear();
142
m_NextCommentId
= 1;
143
}
144
145
// ============================================================================
146
// Serialisation
147
// ============================================================================
148
149
void
CommentManager::SaveToJson
(
json
&
j
)
const
150
{
151
json
arr
= json::array();
152
for
(
size_t
i
= 0;
i
<
m_Comments
.size(); ++
i
)
153
arr
.push_back(
m_Comments
[
i
].ToJson());
154
j
[
"comments"
] =
arr
;
155
}
156
157
void
CommentManager::LoadFromJson
(
const
json
&
j
)
158
{
159
Clear
();
160
if
(!
j
.contains(
"comments"
) || !
j
[
"comments"
].is_array())
161
return
;
162
163
const
json
&
arr
=
j
[
"comments"
];
164
for
(
auto
it
=
arr
.begin();
it
!=
arr
.end(); ++
it
)
165
{
166
GraphComment
c
=
GraphComment::FromJson
(*
it
);
167
// Re-insert preserving original ID but updating the counter
168
if
(
c
.id >=
m_NextCommentId
)
169
m_NextCommentId
=
c
.id + 1;
170
m_Comments
.push_back(
c
);
171
}
172
}
173
174
}
// namespace Olympe
json
nlohmann::json json
Definition
BehaviorTree.cpp:27
GetComponentTypeID_Static
ComponentTypeID GetComponentTypeID_Static()
Definition
ECS_Entity.h:56
GraphComment.h
Visual comment/annotation system for node graphs (Phase 9).
Olympe::CommentManager
Singleton that owns all GraphComment instances for the active graph.
Definition
GraphComment.h:67
Olympe::CommentManager::SaveToJson
void SaveToJson(nlohmann::json &j) const
Definition
GraphComment.cpp:149
Olympe::CommentManager::Get
static CommentManager & Get()
Returns the single shared instance.
Definition
GraphComment.cpp:73
Olympe::CommentManager::CommentManager
CommentManager()
Definition
GraphComment.cpp:79
Olympe::CommentManager::m_NextCommentId
int m_NextCommentId
Definition
GraphComment.h:117
Olympe::CommentManager::LoadFromJson
void LoadFromJson(const nlohmann::json &j)
Definition
GraphComment.cpp:157
Olympe::CommentManager::Clear
void Clear()
Removes all comments and resets the ID counter.
Definition
GraphComment.cpp:139
Olympe::CommentManager::GetComment
GraphComment * GetComment(int commentId)
Returns a pointer to the comment with the given ID.
Definition
GraphComment.cpp:108
Olympe::CommentManager::m_Comments
std::vector< GraphComment > m_Comments
Definition
GraphComment.h:116
Olympe::CommentManager::AddComment
int AddComment(const GraphComment &comment)
Adds a comment and assigns it a unique ID.
Definition
GraphComment.cpp:88
Olympe::CommentManager::GetCommentCount
int GetCommentCount() const
Returns the total number of comments managed.
Definition
GraphComment.cpp:134
Olympe::CommentManager::UpdateComment
void UpdateComment(int commentId, const GraphComment &comment)
Replaces the stored comment data for the given ID.
Definition
GraphComment.cpp:118
Olympe::CommentManager::RemoveComment
void RemoveComment(int commentId)
Removes the comment with the given ID.
Definition
GraphComment.cpp:96
Olympe
< Provides AssetID and INVALID_ASSET_ID
Definition
BTEditorCommand.cpp:16
Olympe::json
nlohmann::json json
Definition
blueprinteditor.h:135
nlohmann::json
nlohmann::json json
Definition
ParameterSchema.h:23
Olympe::GraphComment
A rectangular comment box placed on the graph canvas.
Definition
GraphComment.h:34
Olympe::GraphComment::FromJson
static GraphComment FromJson(const nlohmann::json &j)
Definition
GraphComment.cpp:35
Olympe::GraphComment::posX
float posX
Left edge in graph space.
Definition
GraphComment.h:37
Olympe::GraphComment::id
int id
Unique comment ID (assigned by CommentManager)
Definition
GraphComment.h:35
Olympe::GraphComment::ToJson
nlohmann::json ToJson() const
Definition
GraphComment.cpp:20
Olympe::GraphComment::fontSize
float fontSize
Font size in points.
Definition
GraphComment.h:42
Olympe::GraphComment::height
float height
Box height in graph space.
Definition
GraphComment.h:40
Olympe::GraphComment::color
unsigned int color
RGBA packed colour (default: amber)
Definition
GraphComment.h:41
Olympe::GraphComment::text
std::string text
Text content displayed inside the box.
Definition
GraphComment.h:36
Olympe::GraphComment::width
float width
Box width in graph space.
Definition
GraphComment.h:39
Olympe::GraphComment::isVisible
bool isVisible
Whether the comment is drawn.
Definition
GraphComment.h:43
Olympe::GraphComment::posY
float posY
Top edge in graph space.
Definition
GraphComment.h:38
SYSTEM_LOG
#define SYSTEM_LOG
Definition
system_utils.h:23
Generated on Mon Apr 13 2026 08:15:20 for Olympe Engine by
1.9.8