Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
blueprinteditor.h
Go to the documentation of this file.
1/*
2 * Olympe Blueprint Editor - Backend (Business Logic)
3 *
4 * Singleton backend for the Blueprint Editor managing:
5 * - Editor state and lifecycle
6 * - Asset management and current blueprint data
7 * - Business logic and data models
8 * - NO UI/GUI code (separated into BlueprintEditorGUI)
9 */
10
11#pragma once
12
13#include "EntityBlueprint.h"
15#include "../../Source/third_party/nlohmann/json.hpp"
16#include <string>
17#include <memory>
18#include <vector>
19#include <map>
20
21namespace Olympe
22{
23 // Forward declaration
24 class BlueprintEditorGUI;
25
26 // Use nlohmann json
28
29 // Asset metadata structure for backend
31 {
32 std::string filepath; // Full path to asset file
33 std::string name; // Asset name (from JSON or filename)
34 std::string type; // Asset type (EntityBlueprint, BehaviorTree, etc.)
35 std::string description; // Asset description
36 bool isDirectory; // True if this is a directory
37 int componentCount; // For EntityBlueprint
38 int nodeCount; // For BehaviorTree
39 std::vector<std::string> components; // Component types
40 std::vector<std::string> nodes; // Node types
41 bool isValid; // False if JSON is malformed
42 std::string errorMessage; // Error message if not valid
43
45 };
46
47 // Asset tree node structure for backend
48 struct AssetNode
49 {
50 std::string name; // Display name (filename without path)
51 std::string fullPath; // Complete file path
52 std::string type; // Asset type
54 std::vector<std::shared_ptr<AssetNode>> children;
55
56 AssetNode(const std::string& n, const std::string& path, bool isDir)
57 : name(n), fullPath(path), isDirectory(isDir) {}
58 };
59
60 /**
61 * BlueprintEditor Singleton Backend
62 * Manages all business logic, state, and data for the Blueprint Editor
63 * Completely separated from UI rendering (handled by BlueprintEditorGUI)
64 */
66 {
67 public:
68 // Singleton access
69 static BlueprintEditor& Instance();
70 static BlueprintEditor& Get() { return Instance(); }
71
72 // Lifecycle methods
73 void Initialize();
74 void Shutdown();
75 void Update(float deltaTime); // Called by GameEngine when active
76
77 // Editor mode initialization
78 void InitializeRuntimeEditor(); // Initialize in Runtime mode (read-only)
79 void InitializeStandaloneEditor(); // Initialize in Standalone mode (full CRUD)
80
81 // Editor state
82 bool IsActive() const { return m_IsActive; }
85
86 // Blueprint operations
87 void NewBlueprint(const std::string& name, const std::string& description = "");
88 bool LoadBlueprint(const std::string& filepath);
89 bool SaveBlueprint();
90 bool SaveBlueprintAs(const std::string& filepath);
91
92 // Blueprint access (const for read-only, non-const for editing)
95
96 // State queries
97 bool HasBlueprint() const { return !m_CurrentBlueprint.name.empty(); }
98 bool HasUnsavedChanges() const { return m_HasUnsavedChanges; }
99 const std::string& GetCurrentFilepath() const { return m_CurrentFilepath; }
100
101 // State modification
104
105 // Asset management
106 std::string GetAssetRootPath() const { return m_AssetRootPath; }
107 void SetAssetRootPath(const std::string& path);
108
109 // Asset scanning and retrieval
110 void RefreshAssets(); // Rescan asset directory
111 std::shared_ptr<AssetNode> GetAssetTree() const { return m_AssetTreeRoot; }
112
113 // Asset queries
114 std::vector<AssetMetadata> GetAllAssets() const;
115 std::vector<AssetMetadata> GetAssetsByType(const std::string& type) const;
116 std::vector<AssetMetadata> SearchAssets(const std::string& query) const;
117
118 // Asset metadata
119 AssetMetadata GetAssetMetadata(const std::string& filepath);
120 bool IsAssetValid(const std::string& filepath) const;
121
122 // Asset type detection
123 std::string DetectAssetType(const std::string& filepath);
124
125 // Error handling
126 std::string GetLastError() const { return m_LastError; }
127 bool HasError() const { return !m_LastError.empty(); }
128 void ClearError() { m_LastError.clear(); }
129
130 // ===== B) Runtime Entity Management =====
131 // World bridge: notification hooks for entity lifecycle
132 void NotifyEntityCreated(uint64_t entityId);
133 void NotifyEntityDestroyed(uint64_t entityId);
134
135 // Runtime entity queries
136 const std::vector<uint64_t>& GetRuntimeEntities() const { return m_RuntimeEntities; }
137 size_t GetRuntimeEntityCount() const { return m_RuntimeEntities.size(); }
138
139 // ===== C) Entity Selection for Panel Synchronization =====
140 void SetSelectedEntity(uint64_t entityId);
142 bool HasSelectedEntity() const { return m_SelectedEntity != 0; } // 0 = INVALID_ENTITY_ID
143
144 // ===== Asset Selection for Panel Synchronization =====
145 void SelectAsset(const std::string& assetPath);
146 std::string GetSelectedAssetPath() const { return m_SelectedAssetPath; }
147 bool HasSelectedAsset() const { return !m_SelectedAssetPath.empty(); }
148
149 // ===== Graph Loading in Node Graph Editor =====
150 // Opens a BehaviorTree or HFSM asset in the Node Graph Editor
151 void OpenGraphInEditor(const std::string& assetPath);
152
153 // ===== Phase 5: Template Management =====
154 // Save current blueprint as template
155 bool SaveCurrentAsTemplate(const std::string& name, const std::string& description, const std::string& category);
156
157 // Apply template to current blueprint
158 bool ApplyTemplate(const std::string& templateId);
159
160 // Delete a template
161 bool DeleteTemplate(const std::string& templateId);
162
163 // Reload templates from disk
164 void ReloadTemplates();
165
166 // ===== Phase 6: Undo/Redo System =====
167 void Undo();
168 void Redo();
169 bool CanUndo() const;
170 bool CanRedo() const;
171 std::string GetLastCommandDescription() const;
172 std::string GetNextRedoDescription() const;
173
174 // Command stack access for history panel
176
177 // ===== Plugin System =====
178 void InitializePlugins();
179 void RegisterPlugin(std::unique_ptr<class BlueprintEditorPlugin> plugin);
180 class BlueprintEditorPlugin* GetPlugin(const std::string& type);
182
183 // ===== Migration System =====
185 std::vector<std::string> ScanBlueprintFiles(const std::string& directory);
188
189 private:
190 // Private constructor/destructor for singleton
193
194 // Disable copy and assignment
197
198 // Asset management helpers
199 std::shared_ptr<AssetNode> ScanDirectory(const std::string& path);
200 void ParseAssetMetadata(const std::string& filepath, AssetMetadata& metadata);
201 void ParseEntityBlueprint(const json& j, AssetMetadata& metadata);
202 void ParseBehaviorTree(const json& j, AssetMetadata& metadata);
203 void ParseHFSM(const json& j, AssetMetadata& metadata);
204 void CollectAllAssets(const std::shared_ptr<AssetNode>& node, std::vector<AssetMetadata>& assets) const;
205
206 private:
207 // Editor state
210
211 // Blueprint data
213 std::string m_CurrentFilepath;
214
215 // Asset paths and tree
216 std::string m_AssetRootPath;
217 std::shared_ptr<AssetNode> m_AssetTreeRoot;
218
219 // Error handling
220 std::string m_LastError;
221
222 // ===== B) Runtime Entity Tracking =====
223 std::vector<uint64_t> m_RuntimeEntities; // List of all runtime entities from World
224
225 // ===== C) Entity Selection =====
226 uint64_t m_SelectedEntity; // Currently selected entity (0 = none)
227
228 // ===== Asset Selection =====
229 std::string m_SelectedAssetPath; // Currently selected asset file path
230
231 // ===== Phase 6: Command System =====
232 class CommandStack* m_CommandStack; // Undo/redo command stack
233
234 // ===== Plugin System =====
235 std::map<std::string, std::unique_ptr<class BlueprintEditorPlugin>> m_Plugins;
236
237 // ===== Migration System =====
239 std::vector<std::string> m_BlueprintsToMigrate;
240 };
241}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
BlueprintEditorPlugin - Base interface for blueprint type plugins Each plugin handles a specific blue...
BlueprintEditor Singleton Backend Manages all business logic, state, and data for the Blueprint Edito...
std::vector< AssetMetadata > SearchAssets(const std::string &query) const
const std::string & GetCurrentFilepath() const
size_t GetRuntimeEntityCount() const
BlueprintEditor(const BlueprintEditor &)=delete
void RegisterPlugin(std::unique_ptr< class BlueprintEditorPlugin > plugin)
std::shared_ptr< AssetNode > GetAssetTree() const
std::string GetSelectedAssetPath() const
void SetActive(bool active)
void ParseEntityBlueprint(const json &j, AssetMetadata &metadata)
std::vector< std::string > ScanBlueprintFiles(const std::string &directory)
static BlueprintEditor & Instance()
const std::vector< uint64_t > & GetRuntimeEntities() const
std::map< std::string, std::unique_ptr< class BlueprintEditorPlugin > > m_Plugins
bool LoadBlueprint(const std::string &filepath)
void SetShowMigrationDialog(bool show)
std::string DetectAssetType(const std::string &filepath)
std::shared_ptr< AssetNode > ScanDirectory(const std::string &path)
std::vector< AssetMetadata > GetAssetsByType(const std::string &type) const
std::vector< uint64_t > m_RuntimeEntities
void NewBlueprint(const std::string &name, const std::string &description="")
void NotifyEntityDestroyed(uint64_t entityId)
std::string GetNextRedoDescription() const
void SetAssetRootPath(const std::string &path)
class CommandStack * m_CommandStack
std::string GetLastError() const
std::string GetLastCommandDescription() const
Blueprint::EntityBlueprint & GetCurrentBlueprintMutable()
const Blueprint::EntityBlueprint & GetCurrentBlueprint() const
void NotifyEntityCreated(uint64_t entityId)
void ParseHFSM(const json &j, AssetMetadata &metadata)
bool DeleteTemplate(const std::string &templateId)
AssetMetadata GetAssetMetadata(const std::string &filepath)
std::vector< std::string > m_BlueprintsToMigrate
bool IsAssetValid(const std::string &filepath) const
void SelectAsset(const std::string &assetPath)
void SetSelectedEntity(uint64_t entityId)
uint64_t GetSelectedEntity() const
class CommandStack * GetCommandStack()
bool SaveBlueprintAs(const std::string &filepath)
class BlueprintEditorPlugin * GetPlugin(const std::string &type)
void OpenGraphInEditor(const std::string &assetPath)
bool ApplyTemplate(const std::string &templateId)
std::shared_ptr< AssetNode > m_AssetTreeRoot
void ParseAssetMetadata(const std::string &filepath, AssetMetadata &metadata)
bool SaveCurrentAsTemplate(const std::string &name, const std::string &description, const std::string &category)
class BlueprintEditorPlugin * DetectPlugin(const json &blueprint)
std::vector< AssetMetadata > GetAllAssets() const
void CollectAllAssets(const std::shared_ptr< AssetNode > &node, std::vector< AssetMetadata > &assets) const
void ParseBehaviorTree(const json &j, AssetMetadata &metadata)
std::string GetAssetRootPath() const
static BlueprintEditor & Get()
BlueprintEditor & operator=(const BlueprintEditor &)=delete
Blueprint::EntityBlueprint m_CurrentBlueprint
void Update(float deltaTime)
CommandStack - Manages undo/redo command history Maintains two stacks for undo and redo operations.
nlohmann::json json
nlohmann::json json
std::vector< std::string > components
std::vector< std::string > nodes
AssetNode(const std::string &n, const std::string &path, bool isDir)
std::vector< std::shared_ptr< AssetNode > > children