2019-08-02 08:17:32 +02:00
|
|
|
tool
|
2019-07-31 20:53:00 +02:00
|
|
|
extends MMGenBase
|
|
|
|
class_name MMGenGraph
|
2019-08-02 08:17:32 +02:00
|
|
|
|
2019-08-15 11:53:21 +02:00
|
|
|
var connections = []
|
2019-08-02 08:17:32 +02:00
|
|
|
|
2019-08-17 17:35:48 +02:00
|
|
|
func get_type():
|
|
|
|
return "graph"
|
|
|
|
|
2019-08-02 08:17:32 +02:00
|
|
|
func get_port_source(gen_name: String, input_index: int) -> OutputPort:
|
|
|
|
for c in connections:
|
|
|
|
if c.to == gen_name and c.to_port == input_index:
|
2019-08-17 17:35:48 +02:00
|
|
|
var src_gen = get_node(c.from)
|
|
|
|
if src_gen != null:
|
2019-09-14 09:14:27 +02:00
|
|
|
return OutputPort.new(src_gen, c.from_port)
|
|
|
|
return null
|
|
|
|
|
|
|
|
func get_port_target(gen_name: String, input_index: int) -> InputPort:
|
|
|
|
for c in connections:
|
|
|
|
if c.from == gen_name and c.from_port == input_index:
|
|
|
|
var tgt_gen = get_node(c.to)
|
|
|
|
if tgt_gen != null:
|
|
|
|
return InputPort.new(tgt_gen, c.to_port)
|
2019-08-02 08:17:32 +02:00
|
|
|
return null
|
2019-08-13 13:38:11 +02:00
|
|
|
|
2019-08-19 16:37:17 +02:00
|
|
|
func remove_generator(generator : MMGenBase):
|
|
|
|
var new_connections = []
|
|
|
|
for c in connections:
|
|
|
|
if c.from != generator.name and c.to != generator.name:
|
|
|
|
new_connections.append(c)
|
|
|
|
connections = new_connections
|
2019-09-09 22:00:18 +02:00
|
|
|
generator.queue_free()
|
|
|
|
|
|
|
|
func replace_generator(old : MMGenBase, new : MMGenBase):
|
|
|
|
new.name = old.name
|
|
|
|
new.position = old.position
|
|
|
|
remove_child(old)
|
|
|
|
old.free()
|
|
|
|
add_child(new)
|
2019-08-19 16:37:17 +02:00
|
|
|
|
2019-08-14 09:02:38 +02:00
|
|
|
func connect_children(from, from_port : int, to, to_port : int):
|
|
|
|
# disconnect target
|
|
|
|
while true:
|
|
|
|
var remove = -1
|
|
|
|
for i in connections.size():
|
|
|
|
if connections[i].to == to.name and connections[i].to_port == to_port:
|
|
|
|
remove = i
|
|
|
|
break
|
|
|
|
if remove == -1:
|
|
|
|
break
|
|
|
|
connections.remove(remove)
|
|
|
|
# create new connection
|
|
|
|
connections.append({from=from.name, from_port=from_port, to=to.name, to_port=to_port})
|
|
|
|
return true
|
|
|
|
|
|
|
|
func disconnect_children(from, from_port : int, to, to_port : int):
|
|
|
|
while true:
|
|
|
|
var remove = -1
|
|
|
|
for i in connections.size():
|
|
|
|
if connections[i].from == from.name and connections[i].from_port == from_port and connections[i].to == to.name and connections[i].to_port == to_port:
|
|
|
|
remove = i
|
|
|
|
break
|
|
|
|
if remove == -1:
|
|
|
|
break
|
|
|
|
connections.remove(remove)
|
2019-09-09 22:00:18 +02:00
|
|
|
return true
|
|
|
|
|
|
|
|
func _serialize(data):
|
|
|
|
data.nodes = []
|
|
|
|
for c in get_children():
|
|
|
|
data.nodes.append(c.serialize())
|
|
|
|
data.connections = connections
|
|
|
|
return data
|