103 const std::string& name,
const Vector& position)
107 , m_position(position)
118 std::cout <<
"[AddNodeCommand] Created node ID=" <<
m_createdNodeId << std::endl;
127 std::cout <<
"[AddNodeCommand] Removed node ID=" <<
m_createdNodeId << std::endl;
161 conn.childId = nodeId;
162 conn.isDecorator =
false;
163 conn.childIndex =
static_cast<int>(
i);
168 if (
otherNode.decoratorChildId == nodeId)
172 conn.childId = nodeId;
173 conn.isDecorator =
true;
188 std::cout <<
"[DeleteNodeCommand] Deleted node ID=" <<
m_nodeId << std::endl;
205 if (
conn.isDecorator)
212 if (
conn.childIndex >= 0 &&
static_cast<size_t>(
conn.childIndex) <= parent->
childIds.size())
224 std::cout <<
"[DeleteNodeCommand] Restored node ID=" <<
m_nodeId << std::endl;
229 return "Delete Node ID=" + std::to_string(
m_nodeId);
249 std::cout <<
"[MoveNodeCommand] Moved node ID=" <<
m_nodeId << std::endl;
254 std::cout <<
"[MoveNodeCommand] Restored position for node ID=" <<
m_nodeId << std::endl;
259 return "Move Node ID=" + std::to_string(
m_nodeId);
268 , m_parentId(parentId)
279 std::cout <<
"[ConnectNodesCommand] Connected " <<
m_parentId <<
" -> " <<
m_childId << std::endl;
288 std::cout <<
"[ConnectNodesCommand] Disconnected " <<
m_parentId <<
" -X-> " <<
m_childId << std::endl;
302 , m_parentId(parentId)
313 std::cout <<
"[DisconnectNodesCommand] Disconnected " <<
m_parentId <<
" -X-> " <<
m_childId << std::endl;
322 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_undoStack
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.
static const size_t kMaxStackSize
std::string GetRedoDescription() const
Get description of the next redo command.
std::vector< std::unique_ptr< BTEditorCommand > > m_redoStack
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.
< Provides AssetID and INVALID_ASSET_ID
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)