Olympe Engine 2.0
2D Game Engine with ECS Architecture
Loading...
Searching...
No Matches
CommandAdapter.h
Go to the documentation of this file.
1#pragma once
2
3#include "../AI/BTEditorCommand.h"
4#include "../AI/BehaviorTree.h"
5
6namespace Olympe
7{
8 namespace NodeGraphShared
9 {
10 // Lightweight adapter that executes BTEditorCommand-derived commands
11 // using an existing BTCommandStack. This lets shared code invoke editor
12 // actions without depending on the command stack implementation.
14 {
15 public:
18
19 uint32_t AddNode(BTNodeType type, const std::string& name, const Vector& pos)
20 {
21 if (!m_stack || !m_tree) return 0;
22 auto cmd = std::make_unique<AddNodeCommand>(m_tree, type, name, pos);
23 m_stack->Execute(std::move(cmd));
24 // Newly created node is appended to tree; return last node id
25 if (!m_tree->nodes.empty())
26 return m_tree->nodes.back().id;
27 return 0;
28 }
29
30 void DeleteNode(uint32_t nodeId)
31 {
32 if (!m_stack || !m_tree) return;
33 auto cmd = std::make_unique<DeleteNodeCommand>(m_tree, nodeId);
34 m_stack->Execute(std::move(cmd));
35 }
36
37 void ConnectNodes(uint32_t parentId, uint32_t childId)
38 {
39 if (!m_stack || !m_tree) return;
40 auto cmd = std::make_unique<ConnectNodesCommand>(m_tree, parentId, childId);
41 m_stack->Execute(std::move(cmd));
42 }
43
44 void DisconnectNodes(uint32_t parentId, uint32_t childId)
45 {
46 if (!m_stack || !m_tree) return;
47 auto cmd = std::make_unique<DisconnectNodesCommand>(m_tree, parentId, childId);
48 m_stack->Execute(std::move(cmd));
49 }
50
51 void MoveNode(uint32_t nodeId, const Vector& oldPos, const Vector& newPos)
52 {
53 if (!m_stack || !m_tree) return;
54 auto cmd = std::make_unique<MoveNodeCommand>(m_tree, nodeId, oldPos, newPos);
55 m_stack->Execute(std::move(cmd));
56 }
57
58 private:
61 };
62 }
63}
BTNodeType
Behavior tree node types.
ComponentTypeID GetComponentTypeID_Static()
Definition ECS_Entity.h:56
Manages undo/redo stacks for editor commands.
void Execute(std::unique_ptr< BTEditorCommand > cmd)
Execute a command and add it to the undo stack.
uint32_t AddNode(BTNodeType type, const std::string &name, const Vector &pos)
void DisconnectNodes(uint32_t parentId, uint32_t childId)
CommandAdapter(BTCommandStack *stack, BehaviorTreeAsset *tree)
void MoveNode(uint32_t nodeId, const Vector &oldPos, const Vector &newPos)
void ConnectNodes(uint32_t parentId, uint32_t childId)
< Provides AssetID and INVALID_ASSET_ID
std::vector< BTNode > nodes