Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
NodeGraphManager.h
Go to the documentation of this file.
1/**
2 * @file NodeGraphManager.h
3 * @brief Singleton manager for multiple node graphs
4 * @author Olympe Engine
5 * @date 2026-02-18
6 *
7 * @details
8 * Manages multiple graph documents with tab-like interface.
9 * Handles graph lifecycle (create, load, save, close) and active graph selection.
10 */
11
12#pragma once
13
14#include "GraphDocument.h"
15#include <map>
16#include <memory>
17
18namespace Olympe {
19namespace NodeGraph {
20
21/**
22 * @class NodeGraphManager
23 * @brief Singleton manager for multiple node graphs
24 */
26public:
27 /**
28 * @brief Get singleton instance
29 */
30 static NodeGraphManager& Get();
31
32 // Prevent copying
35
36 // ========================================================================
37 // Graph Lifecycle
38 // ========================================================================
39
40 /**
41 * @brief Create a new graph
42 * @param graphType Type of graph (e.g., "AIGraph")
43 * @param graphKind Kind of graph (e.g., "BehaviorTree", "HFSM")
44 * @return ID of created graph
45 */
46 GraphId CreateGraph(const std::string& graphType, const std::string& graphKind);
47
48 /**
49 * @brief Load a graph from file
50 * @param filepath Path to JSON file
51 * @return ID of loaded graph, or {0} if failed
52 */
53 GraphId LoadGraph(const std::string& filepath);
54
55 /**
56 * @brief Save a graph to file
57 * @param id Graph ID
58 * @param filepath Path to save file
59 * @return true if saved successfully
60 */
61 bool SaveGraph(GraphId id, const std::string& filepath);
62
63 /**
64 * @brief Close a graph
65 * @param id Graph ID
66 * @return true if closed successfully
67 */
68 bool CloseGraph(GraphId id);
69
70 // ========================================================================
71 // Active Graph Management
72 // ========================================================================
73
74 /**
75 * @brief Set active graph
76 * @param id Graph ID
77 */
78 void SetActiveGraph(GraphId id);
79
80 /**
81 * @brief Get active graph
82 * @return Pointer to active graph or nullptr
83 */
85
86 /**
87 * @brief Get active graph ID
88 * @return Active graph ID
89 */
91
92 // ========================================================================
93 // Queries
94 // ========================================================================
95
96 /**
97 * @brief Get graph by ID
98 * @param id Graph ID
99 * @return Pointer to graph or nullptr
100 */
102
103 /**
104 * @brief Get all graph IDs
105 * @return Vector of graph IDs
106 */
107 std::vector<GraphId> GetAllGraphIds() const;
108
109 /**
110 * @brief Get graph name (for tab display)
111 * @param id Graph ID
112 * @return Graph name or empty string
113 */
114 std::string GetGraphName(GraphId id) const;
115
116 /**
117 * @brief Get graph order for tabs
118 * @return Vector of graph IDs in insertion order
119 */
120 std::vector<GraphId> GetGraphOrderForTabs() const { return m_graphOrder; }
121
122private:
125
126 std::map<GraphId, std::unique_ptr<GraphDocument>> m_graphs;
127 std::map<GraphId, std::string> m_graphNames;
128 std::vector<GraphId> m_graphOrder;
131};
132
133} // namespace NodeGraph
134} // namespace Olympe
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Document class for managing node graphs.
Main document class for a node graph.
Singleton manager for multiple node graphs.
std::string GetGraphName(GraphId id) const
Get graph name (for tab display)
std::map< GraphId, std::string > m_graphNames
GraphId GetActiveGraphId() const
Get active graph ID.
GraphDocument * GetGraph(GraphId id)
Get graph by ID.
std::vector< GraphId > GetGraphOrderForTabs() const
Get graph order for tabs.
static NodeGraphManager & Get()
Get singleton instance.
void SetActiveGraph(GraphId id)
Set active graph.
GraphDocument * GetActiveGraph()
Get active graph.
GraphId CreateGraph(const std::string &graphType, const std::string &graphKind)
Create a new graph.
bool SaveGraph(GraphId id, const std::string &filepath)
Save a graph to file.
std::vector< GraphId > GetAllGraphIds() const
Get all graph IDs.
GraphId LoadGraph(const std::string &filepath)
Load a graph from file.
std::map< GraphId, std::unique_ptr< GraphDocument > > m_graphs
NodeGraphManager & operator=(const NodeGraphManager &)=delete
bool CloseGraph(GraphId id)
Close a graph.
NodeGraphManager(const NodeGraphManager &)=delete
< Provides AssetID and INVALID_ASSET_ID