98 const std::string& name,
const Vector& position)
102 , m_position(position)
113 std::cout <<
"[AddNodeCommand] Created node ID=" <<
m_createdNodeId << std::endl;
122 std::cout <<
"[AddNodeCommand] Removed node ID=" <<
m_createdNodeId << std::endl;
156 conn.childId = nodeId;
157 conn.isDecorator =
false;
158 conn.childIndex =
static_cast<int>(
i);
163 if (
otherNode.decoratorChildId == nodeId)
167 conn.childId = nodeId;
168 conn.isDecorator =
true;
183 std::cout <<
"[DeleteNodeCommand] Deleted node ID=" <<
m_nodeId << std::endl;
200 if (
conn.isDecorator)
207 if (
conn.childIndex >= 0 &&
static_cast<size_t>(
conn.childIndex) <= parent->
childIds.size())
219 std::cout <<
"[DeleteNodeCommand] Restored node ID=" <<
m_nodeId << std::endl;
224 return "Delete Node ID=" + std::to_string(
m_nodeId);
244 std::cout <<
"[MoveNodeCommand] Moved node ID=" <<
m_nodeId << std::endl;
249 std::cout <<
"[MoveNodeCommand] Restored position for node ID=" <<
m_nodeId << std::endl;
254 return "Move Node ID=" + std::to_string(
m_nodeId);
263 , m_parentId(parentId)
274 std::cout <<
"[ConnectNodesCommand] Connected " <<
m_parentId <<
" -> " <<
m_childId << std::endl;
283 std::cout <<
"[ConnectNodesCommand] Disconnected " <<
m_parentId <<
" -X-> " <<
m_childId << std::endl;
297 , m_parentId(parentId)
308 std::cout <<
"[DisconnectNodesCommand] Disconnected " <<
m_parentId <<
" -X-> " <<
m_childId << std::endl;
317 std::cout <<
"[DisconnectNodesCommand] Reconnected " <<
m_parentId <<
" -> " <<
m_childId << std::endl;
Command pattern implementation for behavior tree editor undo/redo.
BTNodeType
Behavior tree node types.
ComponentTypeID GetComponentTypeID_Static()
std::string GetDescription() const override
Get a human-readable description of the command.
void Undo() override
Undo the command.
BehaviorTreeAsset * m_tree
AddNodeCommand(BehaviorTreeAsset *tree, BTNodeType type, const std::string &name, const Vector &position)
void Execute() override
Execute the command.
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.
std::string GetDescription() const override
Get a human-readable description of the command.
BehaviorTreeAsset * m_tree
ConnectNodesCommand(BehaviorTreeAsset *tree, uint32_t parentId, uint32_t childId)
void Execute() override
Execute the command.
void Undo() override
Undo the command.
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.
DeleteNodeCommand(BehaviorTreeAsset *tree, uint32_t nodeId)
BehaviorTreeAsset * m_tree
void Undo() override
Undo the command.
std::string GetDescription() const override
Get a human-readable description of the command.
BehaviorTreeAsset * m_tree
void Execute() override
Execute the command.
DisconnectNodesCommand(BehaviorTreeAsset *tree, uint32_t parentId, uint32_t childId)
std::string GetDescription() const override
Get a human-readable description of the command.
EditParameterCommand(BehaviorTreeAsset *tree, uint32_t nodeId, const std::string ¶mName, const std::string &oldValue, const std::string &newValue, ParamType type)
void Undo() override
Undo the command.
void Execute() override
Execute the command.
BehaviorTreeAsset * m_tree
std::string GetDescription() const override
Get a human-readable description of the command.
void Undo() override
Undo the command.
MoveNodeCommand(BehaviorTreeAsset *tree, uint32_t nodeId, const Vector &oldPos, const Vector &newPos)
void Execute() override
Execute the command.
Represents a single node in a behavior tree.
std::vector< uint32_t > childIds
IDs of child nodes.
uint32_t decoratorChildId
std::map< std::string, std::string > stringParams
String parameters.
uint32_t AddNode(BTNodeType type, const std::string &name, const Vector &position)
bool RemoveNode(uint32_t nodeId)
bool ConnectNodes(uint32_t parentId, uint32_t childId)
std::vector< BTNode > nodes
BTNode * GetNode(uint32_t nodeId)
bool DisconnectNodes(uint32_t parentId, uint32_t childId)