Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BTEditorCommand.h
Go to the documentation of this file.
1/**
2 * @file BTEditorCommand.h
3 * @brief Command pattern implementation for behavior tree editor undo/redo
4 * @author Olympe Engine - BT Editor
5 * @date 2026
6 *
7 * @details
8 * Implements the Command pattern for all editor operations to enable undo/redo.
9 * Each command encapsulates an action and stores the data needed to undo it.
10 */
11
12#pragma once
13
14#include "BehaviorTree.h"
15#include "../vector.h"
16#include <string>
17#include <vector>
18#include <memory>
19
20namespace Olympe
21{
22 /**
23 * @class BTEditorCommand
24 * @brief Base class for all editor commands
25 */
27 {
28 public:
29 virtual ~BTEditorCommand() = default;
30
31 /**
32 * @brief Execute the command
33 */
34 virtual void Execute() = 0;
35
36 /**
37 * @brief Undo the command
38 */
39 virtual void Undo() = 0;
40
41 /**
42 * @brief Get a human-readable description of the command
43 */
44 virtual std::string GetDescription() const = 0;
45 };
46
47 /**
48 * @class BTCommandStack
49 * @brief Manages undo/redo stacks for editor commands
50 */
52 {
53 public:
54 /**
55 * @brief Execute a command and add it to the undo stack
56 * @param cmd Command to execute
57 */
58 void Execute(std::unique_ptr<BTEditorCommand> cmd);
59
60 /**
61 * @brief Undo the last command
62 */
63 void Undo();
64
65 /**
66 * @brief Redo the last undone command
67 */
68 void Redo();
69
70 /**
71 * @brief Check if undo is available
72 */
73 bool CanUndo() const;
74
75 /**
76 * @brief Check if redo is available
77 */
78 bool CanRedo() const;
79
80 /**
81 * @brief Get description of the next undo command
82 */
83 std::string GetUndoDescription() const;
84
85 /**
86 * @brief Get description of the next redo command
87 */
88 std::string GetRedoDescription() const;
89
90 /**
91 * @brief Clear all commands
92 */
93 void Clear();
94
95 private:
96 std::vector<std::unique_ptr<BTEditorCommand>> m_undoStack;
97 std::vector<std::unique_ptr<BTEditorCommand>> m_redoStack;
98 static const size_t kMaxStackSize = 100;
99 };
100
101 /**
102 * @class AddNodeCommand
103 * @brief Command to add a node to the tree
104 */
106 {
107 public:
108 AddNodeCommand(BehaviorTreeAsset* tree, BTNodeType type, const std::string& name, const Vector& position);
109
110 void Execute() override;
111 void Undo() override;
112 std::string GetDescription() const override;
113
114 private:
117 std::string m_nodeName;
120 };
121
122 /**
123 * @class DeleteNodeCommand
124 * @brief Command to delete a node from the tree
125 */
127 {
128 public:
130
131 void Execute() override;
132 void Undo() override;
133 std::string GetDescription() const override;
134
135 private:
145 std::vector<Connection> m_savedConnections;
146 };
147
148 /**
149 * @class MoveNodeCommand
150 * @brief Command to move a node
151 */
153 {
154 public:
156
157 void Execute() override;
158 void Undo() override;
159 std::string GetDescription() const override;
160
161 private:
166 };
167
168 /**
169 * @class ConnectNodesCommand
170 * @brief Command to connect two nodes
171 */
173 {
174 public:
176
177 void Execute() override;
178 void Undo() override;
179 std::string GetDescription() const override;
180
181 private:
185 };
186
187 /**
188 * @class DisconnectNodesCommand
189 * @brief Command to disconnect two nodes
190 */
192 {
193 public:
195
196 void Execute() override;
197 void Undo() override;
198 std::string GetDescription() const override;
199
200 private:
204 };
205
206 /**
207 * @class EditParameterCommand
208 * @brief Command to edit a node parameter
209 */
211 {
212 public:
213 enum class ParamType { String, Int, Float };
214
216 const std::string& paramName, const std::string& oldValue,
217 const std::string& newValue, ParamType type);
218
219 void Execute() override;
220 void Undo() override;
221 std::string GetDescription() const override;
222
223 private:
226 std::string m_paramName;
227 std::string m_oldValue;
228 std::string m_newValue;
230 };
231
232} // namespace Olympe
Data-driven behavior tree system for AI decision making.
BTNodeType
Behavior tree node types.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Command to add a node to the tree.
std::string GetDescription() const override
Get a human-readable description of the command.
void Undo() override
Undo the command.
BehaviorTreeAsset * m_tree
void Execute() override
Execute the command.
Manages undo/redo stacks for editor commands.
std::vector< std::unique_ptr< BTEditorCommand > > m_redoStack
std::string GetUndoDescription() const
Get description of the next undo command.
bool CanRedo() const
Check if redo is available.
void Execute(std::unique_ptr< BTEditorCommand > cmd)
Execute a command and add it to the undo stack.
void Undo()
Undo the last command.
bool CanUndo() const
Check if undo is available.
std::vector< std::unique_ptr< BTEditorCommand > > m_undoStack
static const size_t kMaxStackSize
std::string GetRedoDescription() const
Get description of the next redo command.
void Clear()
Clear all commands.
void Redo()
Redo the last undone command.
Base class for all editor commands.
virtual std::string GetDescription() const =0
Get a human-readable description of the command.
virtual ~BTEditorCommand()=default
virtual void Execute()=0
Execute the command.
virtual void Undo()=0
Undo the command.
Command to connect two nodes.
std::string GetDescription() const override
Get a human-readable description of the command.
void Execute() override
Execute the command.
void Undo() override
Undo the command.
DeleteNodeCommand - Command to delete a node from graph.
void Undo() override
Undo the command.
std::vector< Connection > m_savedConnections
void Execute() override
Execute the command.
std::string GetDescription() const override
Get a human-readable description of the command.
BehaviorTreeAsset * m_tree
Command to disconnect two nodes.
void Undo() override
Undo the command.
std::string GetDescription() const override
Get a human-readable description of the command.
void Execute() override
Execute the command.
Command to edit a node parameter.
std::string GetDescription() const override
Get a human-readable description of the command.
void Undo() override
Undo the command.
void Execute() override
Execute the command.
MoveNodeCommand - Command to move a node's position.
std::string GetDescription() const override
Get a human-readable description of the command.
void Undo() override
Undo the command.
BehaviorTreeAsset * m_tree
void Execute() override
Execute the command.
Represents a single node in a behavior tree.