-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathVisualNodeSocket.cpp
More file actions
151 lines (130 loc) · 3.22 KB
/
Copy pathVisualNodeSocket.cpp
File metadata and controls
151 lines (130 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "VisualNodeSocket.h"
#include "VisualNodeSystem.h"
using namespace VisNodeSys;
std::unordered_map<std::string, ImColor> NodeSocket::SocketTypeToColorAssociations;
NodeSocket::NodeSocket(Node* Parent, const std::string Type, const std::string Name, SocketFlow Flow, std::function<void* ()> OutputDataFunction)
{
this->Parent = Parent;
this->AllowedTypes.push_back(Type);
StripEmptyTypes(this->AllowedTypes);
this->Name = Name;
this->ID = NODE_CORE.GetUniqueHexID();
this->Flow = Flow;
if (!OutputDataFunction)
{
this->OutputData = []() { return nullptr; };
}
else
{
this->OutputData = OutputDataFunction;
}
}
NodeSocket::NodeSocket(Node* Parent, const std::vector<std::string> Types, const std::string Name, SocketFlow Flow, std::function<void* ()> OutputDataFunction)
{
this->Parent = Parent;
this->AllowedTypes = Types;
StripEmptyTypes(this->AllowedTypes);
this->Name = Name;
this->ID = NODE_CORE.GetUniqueHexID();
this->Flow = Flow;
if (!OutputDataFunction)
{
this->OutputData = []() { return nullptr; };
}
else
{
this->OutputData = OutputDataFunction;
}
}
void NodeSocket::StripEmptyTypes(std::vector<std::string>& Types)
{
for (int i = 0; i < static_cast<int>(Types.size()); i++)
{
if (Types[i].empty())
{
Types.erase(Types.begin() + i, Types.begin() + i + 1);
i--;
}
}
}
std::string NodeSocket::GetID() const
{
return ID;
}
Node* NodeSocket::GetParent() const
{
return Parent;
}
const std::vector<NodeSocket*>& NodeSocket::GetConnectedSockets() const
{
return ConnectedSockets;
}
std::string NodeSocket::GetName() const
{
return Name;
}
void NodeSocket::SetName(std::string NewValue)
{
Name = NewValue;
SocketMirrorNode* MirrorParent = dynamic_cast<SocketMirrorNode*>(GetParent());
if (MirrorParent != nullptr)
NODE_SYSTEM.SyncMirrorNodeSocketName(MirrorParent->GetID(), GetID(), NewValue);
}
const std::vector<std::string>& NodeSocket::GetAllowedTypes() const
{
return AllowedTypes;
}
NodeSocket::SocketFlow NodeSocket::GetFlowDirection() const
{
return Flow;
}
void NodeSocket::SetFunctionToOutputData(std::function<void* ()> NewFunction)
{
if (!NewFunction)
{
OutputData = []() { return nullptr; };
}
else
{
OutputData = NewFunction;
}
}
void* NodeSocket::GetData()
{
return OutputData();
}
bool NodeSocket::CanBeDeletedByUser() const
{
return bCanBeDeletedByUser;
}
void NodeSocket::SetCanBeDeletedByUser(bool NewValue)
{
bCanBeDeletedByUser = NewValue;
}
bool NodeSocket::SetAllowedTypes(std::vector<std::string> NewTypes)
{
StripEmptyTypes(NewTypes);
SocketMirrorNode* MirrorParent = dynamic_cast<SocketMirrorNode*>(GetParent());
if (MirrorParent != nullptr)
{
if (!AllowedTypes.empty() && AllowedTypes[0] == "EXECUTE" && GetParent() != nullptr && GetParent()->GetSocketIndexByID(GetID()) == 0)
return false; // We should never change execution socket types.
AllowedTypes = NewTypes;
NODE_SYSTEM.SyncMirrorNodeSocketAllowedTypes(MirrorParent->GetID(), GetID(), NewTypes);
}
else
{
AllowedTypes = NewTypes;
}
return !NODE_SYSTEM.RevalidateSocketConnections(this);
}
Connection::Connection(NodeSocket* Out, NodeSocket* In)
{
this->Out = Out;
this->In = In;
}
Connection::~Connection()
{
for (size_t i = 0; i < RerouteNodes.size(); i++)
delete RerouteNodes[i];
}