Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
BlueprintAdapter.h
Go to the documentation of this file.
1#pragma once
2
3#include "../BlueprintEditor/BPCommandSystem.h"
4#include "../BlueprintEditor/BlueprintEditor.h"
5#include <string>
6
7namespace Olympe
8{
9 namespace NodeGraphShared
10 {
11 // Adapter to execute Blueprint editor commands through the Blueprint command stack.
12 // This allows NodeGraphPanel to use a consistent adapter similar to the BT editor.
14 {
15 public:
17 : m_stack(stack), m_graphId(std::to_string(graphId)) {}
18
19 int CreateNode(const std::string& nodeType, float posX, float posY, const std::string& nodeName = "")
20 {
21 if (!m_stack) return 0;
22 int createdId = -1;
23 auto cmd = std::make_unique<Blueprint::CreateNodeCommand>(m_graphId, nodeType, posX, posY, nodeName, &createdId);
24 m_stack->ExecuteCommand(std::move(cmd));
25 return createdId >= 0 ? createdId : 0;
26 }
27
28 void DeleteNode(int nodeId)
29 {
30 if (!m_stack) return;
31 auto cmd = std::make_unique<Blueprint::DeleteNodeCommand>(m_graphId, nodeId);
32 m_stack->ExecuteCommand(std::move(cmd));
33 }
34
35 void MoveNode(int nodeId, float oldX, float oldY, float newX, float newY)
36 {
37 if (!m_stack) return;
38 auto cmd = std::make_unique<Blueprint::MoveNodeCommand>(m_graphId, nodeId, oldX, oldY, newX, newY);
39 m_stack->ExecuteCommand(std::move(cmd));
40 }
41
42 void ConnectNodes(int parentId, int childId)
43 {
44 if (!m_stack) return;
45 auto cmd = std::make_unique<Blueprint::LinkNodesCommand>(m_graphId, parentId, childId);
46 m_stack->ExecuteCommand(std::move(cmd));
47 }
48
49 void DisconnectNodes(int parentId, int childId)
50 {
51 if (!m_stack) return;
52 auto cmd = std::make_unique<Blueprint::UnlinkNodesCommand>(m_graphId, parentId, childId);
53 m_stack->ExecuteCommand(std::move(cmd));
54 }
55
56 void DuplicateNode(int nodeId)
57 {
58 if (!m_stack) return;
59 auto cmd = std::make_unique<Blueprint::DuplicateNodeCommand>(m_graphId, nodeId);
60 m_stack->ExecuteCommand(std::move(cmd));
61 }
62
63 private:
65 std::string m_graphId;
66 };
67 }
68}
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
CommandStack - Manages undo/redo command history Maintains two stacks for undo and redo operations.
void ExecuteCommand(std::unique_ptr< EditorCommand > cmd)
void DisconnectNodes(int parentId, int childId)
BlueprintAdapter(Blueprint::CommandStack *stack, int graphId)
int CreateNode(const std::string &nodeType, float posX, float posY, const std::string &nodeName="")
void ConnectNodes(int parentId, int childId)
void MoveNode(int nodeId, float oldX, float oldY, float newX, float newY)
< Provides AssetID and INVALID_ASSET_ID