Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BTGraphCommands.cpp
Go to the documentation of this file.
1/**
2 * @file BTGraphCommands.cpp
3 * @brief Implementation of BehaviorTree command operations
4 * @author Olympe Engine
5 */
6
7#include "BTGraphCommands.h"
8#include "../BTNodeGraphManager.h"
9#include <algorithm>
10
11namespace Olympe
12{
13 // ============ CopyNodesCommand ============
14 CopyNodesCommand::CopyNodesCommand(NodeGraph* graph, const std::vector<int>& nodeIds)
15 : m_graph(graph), m_nodeIds(nodeIds)
16 {
17 }
18
20 {
21 if (!m_graph)
22 return false;
23
25 return true;
26 }
27
29 {
30 // Copy operations are not undoable (they don't modify the graph)
31 return true;
32 }
33
35 {
36 return "Copy " + std::to_string(m_nodeIds.size()) + " node(s)";
37 }
38
39 // ============ PasteNodesCommand ============
41 : m_graph(graph), m_offsetX(offsetX), m_offsetY(offsetY)
42 {
43 }
44
46 {
47 if (!m_graph)
48 return false;
49
51 return !m_pastedNodeIds.empty();
52 }
53
55 {
56 if (!m_graph || m_pastedNodeIds.empty())
57 return false;
58
59 // Delete all pasted nodes
60 for (int nodeId : m_pastedNodeIds)
61 {
62 m_graph->DeleteNode(nodeId);
63 }
64
65 return true;
66 }
67
69 {
70 return "Paste " + std::to_string(m_pastedNodeIds.size()) + " node(s)";
71 }
72
73 // ============ DuplicateNodeCommand ============
74 DuplicateNodeCommand::DuplicateNodeCommand(NodeGraph* graph, const std::vector<int>& nodeIds, float offsetX, float offsetY)
75 : m_graph(graph), m_originalNodeIds(nodeIds), m_offsetX(offsetX), m_offsetY(offsetY)
76 {
77 }
78
87
89 {
90 if (!m_graph || m_duplicatedNodeIds.empty())
91 return false;
92
93 // Delete all duplicated nodes
94 for (int nodeId : m_duplicatedNodeIds)
95 {
96 m_graph->DeleteNode(nodeId);
97 }
98
99 return true;
100 }
101
103 {
104 return "Duplicate " + std::to_string(m_originalNodeIds.size()) + " node(s)";
105 }
106}
Concrete command implementations for BehaviorTree operations.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
bool Undo() override
Undo the command (reverse operation)
CopyNodesCommand(NodeGraph *graph, const std::vector< int > &nodeIds)
std::vector< int > m_nodeIds
bool Execute() override
Execute the command (forward operation)
std::string GetDescription() const override
Get a human-readable description of the command.
std::string GetDescription() const override
Get a human-readable description of the command.
std::vector< int > m_originalNodeIds
DuplicateNodeCommand(NodeGraph *graph, const std::vector< int > &nodeIds, float offsetX=30.0f, float offsetY=30.0f)
bool Execute() override
Execute the command (forward operation)
std::vector< int > m_duplicatedNodeIds
bool Undo() override
Undo the command (reverse operation)
bool DeleteNode(int nodeId)
void CopyNodesToClipboard(const std::vector< int > &nodeIds)
std::vector< int > PasteNodesFromClipboard(float offsetX=30.0f, float offsetY=30.0f)
std::vector< int > DuplicateNodes(const std::vector< int > &nodeIds, float offsetX=30.0f, float offsetY=30.0f)
bool Execute() override
Execute the command (forward operation)
std::string GetDescription() const override
Get a human-readable description of the command.
PasteNodesCommand(NodeGraph *graph, float offsetX=30.0f, float offsetY=30.0f)
std::vector< int > m_pastedNodeIds
bool Undo() override
Undo the command (reverse operation)
< Provides AssetID and INVALID_ASSET_ID