Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
AdditionalEditorPlugins.cpp
Go to the documentation of this file.
1/*
2 * Olympe Blueprint Editor - Additional Editor Plugins Implementation
3 */
4
6#include "../../Source/third_party/imgui/imgui.h"
7#include <chrono>
8#include <sstream>
9#include <iomanip>
10
12
13namespace Olympe
14{
15 static std::string GetCurrentTimestamp()
16 {
17 auto now = std::chrono::system_clock::now();
18 auto time = std::chrono::system_clock::to_time_t(now);
19 std::stringstream ss;
20 std::tm timeInfo;
21 #ifdef _WIN32
23 #else
25 #endif
26 ss << std::put_time(&timeInfo, "%Y-%m-%dT%H:%M:%S");
27 return ss.str();
28 }
29
30 // ========================================================================
31 // HFSM Editor Plugin
32 // ========================================================================
33
34 json HFSMEditorPlugin::CreateNew(const std::string& name)
35 {
36 json hfsm;
37 hfsm["schema_version"] = 2;
38 hfsm["blueprintType"] = "HFSM";
39 hfsm["name"] = name;
40 hfsm["description"] = "";
41 hfsm["metadata"]["author"] = "Atlasbruce";
42 hfsm["metadata"]["created"] = GetCurrentTimestamp();
43 hfsm["metadata"]["tags"] = json::array();
44 hfsm["editorState"]["zoom"] = 1.0;
45 hfsm["editorState"]["scrollOffset"] = nlohmann::json::object();
46 hfsm["editorState"]["scrollOffset"]["x"] = 0;
47 hfsm["editorState"]["scrollOffset"]["y"] = 0;
48 hfsm["data"]["initialState"] = "Idle";
49 hfsm["data"]["states"] = json::array();
50 hfsm["data"]["transitions"] = json::array();
51 return hfsm;
52 }
53
55 {
56 if (blueprint.contains("blueprintType") && blueprint["blueprintType"].is_string() && blueprint["blueprintType"].get<std::string>() == "HFSM")
57 return true;
58 return blueprint.contains("states") || blueprint.contains("initialState");
59 }
60
61 std::vector<ValidationError> HFSMEditorPlugin::Validate(const json& blueprint)
62 {
63 std::vector<ValidationError> errors;
64 if (!blueprint.contains("data"))
65 {
66 ValidationError error(-1, "", "Missing data section", ErrorSeverity::Error);
67 errors.push_back(error);
68 }
69 return errors;
70 }
71
73 {
74 ImGui::Text("HFSM Editor");
75 ImGui::Text("States: %d", blueprintData.contains("data") && blueprintData["data"].contains("states") ?
76 (int)blueprintData["data"]["states"].size() : 0);
77 }
78
79 void HFSMEditorPlugin::RenderProperties(const json& blueprintData)
80 {
81 ImGui::Text("Type: HFSM");
82 }
83
85 {
86 ImGui::Button("Add State");
87 }
88
89 // ========================================================================
90 // Animation Graph Editor Plugin
91 // ========================================================================
92
94 {
95 json anim;
96 anim["schema_version"] = 2;
97 anim["blueprintType"] = "AnimationGraph";
98 anim["name"] = name;
99 anim["description"] = "";
100 anim["metadata"]["author"] = "Atlasbruce";
101 anim["metadata"]["created"] = GetCurrentTimestamp();
102 anim["metadata"]["tags"] = json::array();
103 anim["editorState"]["zoom"] = 1.0;
104 anim["editorState"]["scrollOffset"] = nlohmann::json::object();
105 anim["editorState"]["scrollOffset"]["x"] = 0;
106 anim["editorState"]["scrollOffset"]["y"] = 0;
107 anim["data"]["initialState"] = "Idle";
108 anim["data"]["states"] = json::array();
109 anim["data"]["transitions"] = json::array();
110 return anim;
111 }
112
114 {
115 if (blueprint.contains("blueprintType") && blueprint["blueprintType"].is_string() && blueprint["blueprintType"].get<std::string>() == "AnimationGraph")
116 return true;
117 return false;
118 }
119
120 std::vector<ValidationError> AnimationGraphEditorPlugin::Validate(const json& blueprint)
121 {
122 std::vector<ValidationError> errors;
123 if (!blueprint.contains("data"))
124 {
125 ValidationError error(-1, "", "Missing data section", ErrorSeverity::Error);
126 errors.push_back(error);
127 }
128 return errors;
129 }
130
132 {
133 ImGui::Text("Animation Graph Editor");
134 if (blueprintData.contains("data") && blueprintData["data"].contains("states"))
135 {
136 const json& states = blueprintData["data"]["states"];
137 ImGui::Text("Animation States: %d", (int)states.size());
138
139 for (size_t i = 0; i < states.size(); ++i)
140 {
141 const json& state = states[i];
142 std::string stateName = state.contains("name") && state["name"].is_string()
143 ? state["name"].get<std::string>()
144 : "Unnamed";
145 ImGui::BulletText("%s", stateName.c_str());
146 }
147 }
148 }
149
151 {
152 ImGui::Text("Type: Animation Graph");
153 }
154
156 {
157 ImGui::Button("Add Animation State");
158 }
159
160 // ========================================================================
161 // Scripted Event Editor Plugin
162 // ========================================================================
163
165 {
166 json event;
167 event["schema_version"] = 2;
168 event["blueprintType"] = "ScriptedEvent";
169 event["name"] = name;
170 event["description"] = "";
171 event["metadata"]["author"] = "Atlasbruce";
172 event["metadata"]["created"] = GetCurrentTimestamp();
173 event["metadata"]["tags"] = json::array();
174 event["editorState"]["zoom"] = 1.0;
175 event["editorState"]["scrollOffset"] = nlohmann::json::object();
176 event["editorState"]["scrollOffset"]["x"] = 0;
177 event["editorState"]["scrollOffset"]["y"] = 0;
178 event["data"]["triggerType"] = "Manual";
179 event["data"]["oneShot"] = true;
180 event["data"]["sequence"] = json::array();
181 return event;
182 }
183
185 {
186 if (blueprint.contains("blueprintType") && blueprint["blueprintType"].is_string() && blueprint["blueprintType"].get<std::string>() == "ScriptedEvent")
187 return true;
188 return false;
189 }
190
191 std::vector<ValidationError> ScriptedEventEditorPlugin::Validate(const json& blueprint)
192 {
193 std::vector<ValidationError> errors;
194 if (!blueprint.contains("data"))
195 {
196 ValidationError error(-1, "", "Missing data section", ErrorSeverity::Error);
197 errors.push_back(error);
198 }
199 return errors;
200 }
201
203 {
204 ImGui::Text("Scripted Event Editor");
205 if (blueprintData.contains("data") && blueprintData["data"].contains("sequence"))
206 {
207 const json& sequence = blueprintData["data"]["sequence"];
208 ImGui::Text("Steps: %d", (int)sequence.size());
209
210 for (size_t i = 0; i < sequence.size(); ++i)
211 {
212 const json& step = sequence[i];
213 std::string stepType = step.contains("type") && step["type"].is_string()
214 ? step["type"].get<std::string>()
215 : "Unknown";
216 int stepNum = step.contains("step") && step["step"].is_number()
217 ? step["step"].get<int>()
218 : 0;
219 ImGui::BulletText("Step %d: %s", stepNum, stepType.c_str());
220 }
221 }
222 }
223
225 {
226 ImGui::Text("Type: Scripted Event");
227 }
228
230 {
231 ImGui::Button("Add Step");
232 }
233
234 // ========================================================================
235 // Level Definition Editor Plugin
236 // ========================================================================
237
239 {
240 json level;
241 level["schema_version"] = 2;
242 level["blueprintType"] = "LevelDefinition";
243 level["name"] = name;
244 level["description"] = "";
245 level["metadata"]["author"] = "Atlasbruce";
246 level["metadata"]["created"] = GetCurrentTimestamp();
247 level["metadata"]["tags"] = json::array();
248 level["editorState"]["zoom"] = 0.5;
249 level["editorState"]["scrollOffset"] = nlohmann::json::object();
250 level["editorState"]["scrollOffset"]["x"] = 0;
251 level["editorState"]["scrollOffset"]["y"] = 0;
252 level["data"]["levelName"] = name;
253 nlohmann::json worldSize = nlohmann::json::object();
254 worldSize["width"] = 1024;
255 worldSize["height"] = 768;
256 level["data"]["worldSize"] = worldSize;
257 level["data"]["entities"] = json::array();
258 return level;
259 }
260
262 {
263 if (blueprint.contains("blueprintType") && blueprint["blueprintType"].is_string() && blueprint["blueprintType"].get<std::string>() == "LevelDefinition")
264 return true;
265 return false;
266 }
267
268 std::vector<ValidationError> LevelDefinitionEditorPlugin::Validate(const json& blueprint)
269 {
270 std::vector<ValidationError> errors;
271 if (!blueprint.contains("data"))
272 {
273 ValidationError error(-1, "", "Missing data section", ErrorSeverity::Error);
274 errors.push_back(error);
275 }
276 return errors;
277 }
278
280 {
281 ImGui::Text("Level Definition Editor");
282 if (blueprintData.contains("data"))
283 {
284 auto& data = blueprintData["data"];
285 ImGui::Text("Level: %s", (data.contains("levelName") && data["levelName"].is_string() ? data["levelName"].get<std::string>() : "Unnamed").c_str());
286
287 if (data.contains("entities"))
288 ImGui::Text("Entities: %d", (int)data["entities"].size());
289
290 if (data.contains("objectives"))
291 ImGui::Text("Objectives: %d", (int)data["objectives"].size());
292 }
293 }
294
296 {
297 ImGui::Text("Type: Level Definition");
298 }
299
301 {
302 ImGui::Button("Add Entity");
303 ImGui::SameLine();
304 ImGui::Button("Add Objective");
305 }
306
307 // ========================================================================
308 // UI Menu Editor Plugin
309 // ========================================================================
310
311 json UIMenuEditorPlugin::CreateNew(const std::string& name)
312 {
313 json menu;
314 menu["schema_version"] = 2;
315 menu["blueprintType"] = "UIMenu";
316 menu["name"] = name;
317 menu["description"] = "";
318 menu["metadata"]["author"] = "Atlasbruce";
319 menu["metadata"]["created"] = GetCurrentTimestamp();
320 menu["metadata"]["tags"] = json::array();
321 menu["editorState"]["zoom"] = 1.0;
322 menu["editorState"]["scrollOffset"] = nlohmann::json::object();
323 menu["editorState"]["scrollOffset"]["x"] = 0;
324 menu["editorState"]["scrollOffset"]["y"] = 0;
325 menu["data"]["menuName"] = name;
326 menu["data"]["elements"] = json::array();
327 return menu;
328 }
329
331 {
332 if (blueprint.contains("blueprintType") && blueprint["blueprintType"].is_string() && blueprint["blueprintType"].get<std::string>() == "UIMenu")
333 return true;
334 return false;
335 }
336
337 std::vector<ValidationError> UIMenuEditorPlugin::Validate(const json& blueprint)
338 {
339 std::vector<ValidationError> errors;
340 if (!blueprint.contains("data"))
341 {
342 ValidationError error(-1, "", "Missing data section", ErrorSeverity::Error);
343 errors.push_back(error);
344 }
345 return errors;
346 }
347
349 {
350 ImGui::Text("UI Menu Editor");
351 if (blueprintData.contains("data") && blueprintData["data"].contains("elements"))
352 {
353 const json& elements = blueprintData["data"]["elements"];
354 ImGui::Text("UI Elements: %d", (int)elements.size());
355
356 for (size_t i = 0; i < elements.size(); ++i)
357 {
358 const json& element = elements[i];
359 std::string elemType = element.contains("type") && element["type"].is_string()
360 ? element["type"].get<std::string>()
361 : "Unknown";
362 std::string elemId = element.contains("id") && element["id"].is_string()
363 ? element["id"].get<std::string>()
364 : "unnamed";
365 ImGui::BulletText("%s (%s)", elemId.c_str(), elemType.c_str());
366 }
367 }
368 }
369
371 {
372 ImGui::Text("Type: UI Menu");
373 }
374
376 {
377 ImGui::Button("Add UI Element");
378 }
379}
nlohmann::json json
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
void RenderProperties(const nlohmann::json &blueprintData) override
void RenderToolbar(nlohmann::json &blueprintData) override
bool CanHandle(const nlohmann::json &blueprint) const override
std::vector< ValidationError > Validate(const nlohmann::json &blueprint) override
nlohmann::json CreateNew(const std::string &name) override
void RenderEditor(nlohmann::json &blueprintData, EditorContext_st &ctx) override
nlohmann::json CreateNew(const std::string &name) override
void RenderProperties(const nlohmann::json &blueprintData) override
std::vector< ValidationError > Validate(const nlohmann::json &blueprint) override
void RenderToolbar(nlohmann::json &blueprintData) override
bool CanHandle(const nlohmann::json &blueprint) const override
void RenderEditor(nlohmann::json &blueprintData, EditorContext_st &ctx) override
bool CanHandle(const nlohmann::json &blueprint) const override
void RenderEditor(nlohmann::json &blueprintData, EditorContext_st &ctx) override
void RenderToolbar(nlohmann::json &blueprintData) override
void RenderProperties(const nlohmann::json &blueprintData) override
nlohmann::json CreateNew(const std::string &name) override
std::vector< ValidationError > Validate(const nlohmann::json &blueprint) override
void RenderEditor(nlohmann::json &blueprintData, EditorContext_st &ctx) override
bool CanHandle(const nlohmann::json &blueprint) const override
void RenderProperties(const nlohmann::json &blueprintData) override
void RenderToolbar(nlohmann::json &blueprintData) override
nlohmann::json CreateNew(const std::string &name) override
std::vector< ValidationError > Validate(const nlohmann::json &blueprint) override
nlohmann::json CreateNew(const std::string &name) override
bool CanHandle(const nlohmann::json &blueprint) const override
void RenderToolbar(nlohmann::json &blueprintData) override
void RenderProperties(const nlohmann::json &blueprintData) override
void RenderEditor(nlohmann::json &blueprintData, EditorContext_st &ctx) override
std::vector< ValidationError > Validate(const nlohmann::json &blueprint) override
nlohmann::json json
static std::string GetCurrentTimestamp()
nlohmann::json json