-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeSocket.hpp
101 lines (67 loc) · 1.85 KB
/
NodeSocket.hpp
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
#pragma once
#include<Siv3D.hpp>
#include"Config.hpp"
namespace NodeEditor
{
class Node;
class ISocket : public ISerializable
{
private:
static void connectIO(std::shared_ptr<ISocket> in, std::shared_ptr<ISocket> out);
protected:
bool singleConnect;
virtual bool canConnectSameType(const ISocket& to) = 0;
public:
Node& Parent;
const String Name;
const IOType SocketType;
const size_t Index;
Array<std::shared_ptr<ISocket>> ConnectedSocket;
ISocket(Node& node, const String& desc, const IOType& socketType, const size_t index)
:Parent(node),
Name(desc),
SocketType(socketType),
Index(index)
{
}
virtual Vec2 calcPos(const Config& cfg) = 0;
bool canConnect(const ISocket& to);
static void disconnect(std::shared_ptr<ISocket> ptr);
static void connect(std::shared_ptr<ISocket> ptr, std::shared_ptr<ISocket> to);
//Jsonシリアライズ/デシリアライズ
void serialize(JSONWriter&) const override;
void deserialize(const JSONValue&) override;
};
class ValueSocket : public ISocket
{
private:
std::any m_value;
bool canConnectSameType(const ISocket& to) override;
public:
const Type ValueType;
ValueSocket(Node& node, const String& desc, const IOType& socketType, const size_t index, const Type valType)
:ISocket(node, desc, socketType, index),
ValueType(valType)
{
singleConnect = socketType == IOType::Input;
}
std::any value() const
{
return m_value;
}
void setValue(std::any value);
Vec2 calcPos(const Config& cfg) override;
};
class ExecSocket : public ISocket
{
private:
bool canConnectSameType(const ISocket& to) override;
public:
ExecSocket(Node& node, const String& desc, const IOType& socketType, const size_t index)
:ISocket(node, desc, socketType, index)
{
singleConnect = false;
}
Vec2 calcPos(const Config& cfg) override;
};
}