Added can_connect() and get_node_type_id()
This commit is contained in:
parent
5aa7c4cbd6
commit
dcc53d9351
@ -97,6 +97,17 @@ bool ProgramGraph::is_connected(PortLocation src, PortLocation dst) const {
|
||||
}
|
||||
}
|
||||
|
||||
bool ProgramGraph::can_connect(PortLocation src, PortLocation dst) const {
|
||||
if (is_connected(src, dst)) {
|
||||
return false;
|
||||
}
|
||||
if (has_path(dst.node_id, src.node_id)) {
|
||||
return false;
|
||||
}
|
||||
const Node *dst_node = get_node(dst.node_id);
|
||||
return dst_node->inputs[dst.port_index].connections.size() == 0;
|
||||
}
|
||||
|
||||
void ProgramGraph::connect(PortLocation src, PortLocation dst) {
|
||||
ERR_FAIL_COND(is_connected(src, dst));
|
||||
ERR_FAIL_COND(has_path(dst.node_id, src.node_id));
|
||||
|
@ -46,6 +46,7 @@ public:
|
||||
void clear();
|
||||
|
||||
bool is_connected(PortLocation src, PortLocation dst) const;
|
||||
bool can_connect(PortLocation src, PortLocation dst) const;
|
||||
void connect(PortLocation src, PortLocation dst);
|
||||
bool disconnect(PortLocation src, PortLocation dst);
|
||||
|
||||
|
@ -66,6 +66,12 @@ void VoxelGeneratorGraph::remove_node(uint32_t node_id) {
|
||||
}
|
||||
}
|
||||
|
||||
bool VoxelGeneratorGraph::can_connect(uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index) const {
|
||||
return _graph.can_connect(
|
||||
ProgramGraph::PortLocation{ src_node_id, src_port_index },
|
||||
ProgramGraph::PortLocation{ dst_node_id, dst_port_index });
|
||||
}
|
||||
|
||||
void VoxelGeneratorGraph::add_connection(uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index) {
|
||||
_graph.connect(
|
||||
ProgramGraph::PortLocation{ src_node_id, src_port_index },
|
||||
@ -78,6 +84,10 @@ void VoxelGeneratorGraph::remove_connection(uint32_t src_node_id, uint32_t src_p
|
||||
ProgramGraph::PortLocation{ dst_node_id, dst_port_index });
|
||||
}
|
||||
|
||||
void VoxelGeneratorGraph::get_connections(std::vector<ProgramGraph::Connection> &connections) const {
|
||||
_graph.get_connections(connections);
|
||||
}
|
||||
|
||||
void VoxelGeneratorGraph::set_node_param(uint32_t node_id, uint32_t param_index, Variant value) {
|
||||
Node **pptr = _nodes.getptr(node_id);
|
||||
ERR_FAIL_COND(pptr == nullptr);
|
||||
@ -108,8 +118,11 @@ void VoxelGeneratorGraph::set_node_gui_position(uint32_t node_id, Vector2 pos) {
|
||||
node->gui_position = pos;
|
||||
}
|
||||
|
||||
void VoxelGeneratorGraph::get_connections(std::vector<ProgramGraph::Connection> &connections) const {
|
||||
_graph.get_connections(connections);
|
||||
VoxelGeneratorGraph::NodeTypeID VoxelGeneratorGraph::get_node_type_id(uint32_t node_id) {
|
||||
Node **node_pptr = _nodes.getptr(node_id);
|
||||
ERR_FAIL_COND_V(node_pptr == nullptr, NODE_TYPE_COUNT);
|
||||
Node *node = *node_pptr;
|
||||
return node->type;
|
||||
}
|
||||
|
||||
PoolIntArray VoxelGeneratorGraph::get_node_ids() const {
|
||||
@ -1158,14 +1171,17 @@ void VoxelGeneratorGraph::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("clear"), &VoxelGeneratorGraph::clear);
|
||||
ClassDB::bind_method(D_METHOD("create_node", "type_id"), &VoxelGeneratorGraph::create_node);
|
||||
ClassDB::bind_method(D_METHOD("remove_node", "node_id"), &VoxelGeneratorGraph::remove_node);
|
||||
ClassDB::bind_method(D_METHOD("can_connect", "src_node_id", "src_port_index", "dst_node_id", "dst_port_index"), &VoxelGeneratorGraph::can_connect);
|
||||
ClassDB::bind_method(D_METHOD("add_connection", "src_node_id", "src_port_index", "dst_node_id", "dst_port_index"), &VoxelGeneratorGraph::add_connection);
|
||||
ClassDB::bind_method(D_METHOD("remove_connection", "src_node_id", "src_port_index", "dst_node_id", "dst_port_index"), &VoxelGeneratorGraph::remove_connection);
|
||||
ClassDB::bind_method(D_METHOD("get_connections"), &VoxelGeneratorGraph::_b_get_connections);
|
||||
ClassDB::bind_method(D_METHOD("get_node_ids"), &VoxelGeneratorGraph::get_node_ids);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_node_type_id", "node_id"), &VoxelGeneratorGraph::get_node_type_id);
|
||||
ClassDB::bind_method(D_METHOD("get_node_param", "node_id", "param_index"), &VoxelGeneratorGraph::get_node_param);
|
||||
ClassDB::bind_method(D_METHOD("set_node_param", "node_id", "param_index", "value"), &VoxelGeneratorGraph::set_node_param);
|
||||
ClassDB::bind_method(D_METHOD("get_node_gui_position", "node_id"), &VoxelGeneratorGraph::get_node_gui_position);
|
||||
ClassDB::bind_method(D_METHOD("set_node_gui_position", "node_id", "position"), &VoxelGeneratorGraph::set_node_gui_position);
|
||||
ClassDB::bind_method(D_METHOD("get_connections"), &VoxelGeneratorGraph::_b_get_connections);
|
||||
ClassDB::bind_method(D_METHOD("get_node_ids"), &VoxelGeneratorGraph::get_node_ids);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("compile"), &VoxelGeneratorGraph::compile);
|
||||
|
||||
|
@ -41,13 +41,19 @@ public:
|
||||
|
||||
uint32_t create_node(NodeTypeID type_id);
|
||||
void remove_node(uint32_t node_id);
|
||||
|
||||
bool can_connect(uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index) const;
|
||||
void add_connection(uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index);
|
||||
void remove_connection(uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index);
|
||||
void get_connections(std::vector<ProgramGraph::Connection> &connections) const;
|
||||
|
||||
Variant get_node_param(uint32_t node_id, uint32_t param_index) const;
|
||||
void set_node_param(uint32_t node_id, uint32_t param_index, Variant value);
|
||||
|
||||
Vector2 get_node_gui_position(uint32_t node_id) const;
|
||||
void set_node_gui_position(uint32_t node_id, Vector2 pos);
|
||||
void get_connections(std::vector<ProgramGraph::Connection> &connections) const;
|
||||
|
||||
NodeTypeID get_node_type_id(uint32_t node_id);
|
||||
PoolIntArray get_node_ids() const;
|
||||
|
||||
int get_used_channels_mask() const override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user