2019-09-17 08:12:53 +02:00
|
|
|
tool
|
|
|
|
extends MMGenBase
|
|
|
|
class_name MMGenIOs
|
|
|
|
|
|
|
|
"""
|
|
|
|
IOs just forward their inputs to their outputs and are used to specify graph interfaces
|
|
|
|
"""
|
|
|
|
|
|
|
|
var ports : Array = []
|
|
|
|
|
2019-10-29 22:10:08 +01:00
|
|
|
var editable = false
|
|
|
|
|
2019-10-24 09:00:31 +02:00
|
|
|
func can_be_deleted() -> bool:
|
|
|
|
return name != "gen_inputs" and name != "gen_outputs"
|
|
|
|
|
2019-10-29 22:10:08 +01:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_type() -> String:
|
2019-10-05 11:04:50 +02:00
|
|
|
return "ios"
|
2019-09-17 08:12:53 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_type_name() -> String:
|
2019-09-29 10:07:32 +02:00
|
|
|
match name:
|
|
|
|
"gen_inputs": return "Inputs"
|
|
|
|
"gen_outputs": return "Outputs"
|
2019-09-17 08:12:53 +02:00
|
|
|
_: return "IOs"
|
|
|
|
|
2019-10-29 22:10:08 +01:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_io_defs() -> Array:
|
2019-09-17 08:12:53 +02:00
|
|
|
var rv : Array = []
|
2019-10-05 11:04:50 +02:00
|
|
|
for p in ports:
|
|
|
|
rv.push_back({ name=p.name, type="rgba" })
|
2019-09-17 08:12:53 +02:00
|
|
|
return rv
|
2019-10-02 23:06:20 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_input_defs() -> Array:
|
2019-10-02 23:06:20 +02:00
|
|
|
return [] if name == "gen_inputs" else get_io_defs()
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_output_defs() -> Array:
|
2019-10-02 23:06:20 +02:00
|
|
|
return [] if name == "gen_outputs" else get_io_defs()
|
2019-09-17 08:12:53 +02:00
|
|
|
|
2019-10-29 22:10:08 +01:00
|
|
|
|
|
|
|
func toggle_editable() -> bool:
|
|
|
|
editable = !editable
|
|
|
|
if editable:
|
|
|
|
model = null
|
|
|
|
return true
|
|
|
|
|
|
|
|
func is_editable() -> bool:
|
|
|
|
return editable
|
|
|
|
|
|
|
|
|
|
|
|
func add_port() -> void:
|
|
|
|
ports.append({ name="unnamed", type="rgba" })
|
|
|
|
emit_signal("parameter_changed", "__update_all__", null)
|
|
|
|
|
|
|
|
func set_port_name(i : int, n : String) -> void:
|
|
|
|
ports[i].name = n
|
|
|
|
|
|
|
|
func delete_port(i : int) -> void:
|
|
|
|
ports.remove(i)
|
|
|
|
var input_gen = get_parent() if name == "gen_inputs" else self
|
|
|
|
var output_gen = get_parent() if name == "gen_outputs" else self
|
|
|
|
var port_reconnects = { i:-1 }
|
|
|
|
while i < ports.size():
|
|
|
|
port_reconnects[i+1] = i
|
|
|
|
i += 1
|
|
|
|
input_gen.get_parent().reconnect_inputs(input_gen, port_reconnects)
|
|
|
|
output_gen.get_parent().reconnect_outputs(output_gen, port_reconnects)
|
|
|
|
emit_signal("parameter_changed", "__update_all__", null)
|
|
|
|
|
|
|
|
func swap_ports(i1 : int, i2 : int) -> void:
|
|
|
|
var tmp = ports[i1]
|
|
|
|
ports[i1] = ports[i2]
|
|
|
|
ports[i2] = tmp
|
|
|
|
var input_gen = get_parent() if name == "gen_inputs" else self
|
|
|
|
var output_gen = get_parent() if name == "gen_outputs" else self
|
|
|
|
var port_reconnects = { i1:i2, i2:i1 }
|
|
|
|
input_gen.get_parent().reconnect_inputs(input_gen, port_reconnects)
|
|
|
|
output_gen.get_parent().reconnect_outputs(output_gen, port_reconnects)
|
|
|
|
emit_signal("parameter_changed", "__update_all__", null)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func source_changed(input_index : int) -> void:
|
2019-09-22 22:17:26 +02:00
|
|
|
if name == "gen_outputs":
|
2019-10-21 23:58:14 +02:00
|
|
|
if get_parent() != null:
|
|
|
|
get_parent().notify_output_change(input_index)
|
2019-09-22 22:17:26 +02:00
|
|
|
else:
|
|
|
|
notify_output_change(input_index)
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary:
|
2019-10-05 11:04:50 +02:00
|
|
|
var source = get_source(output_index)
|
|
|
|
if source != null:
|
|
|
|
var rv = source.generator._get_shader_code(uv, source.output_index, context)
|
|
|
|
while rv is GDScriptFunctionState:
|
|
|
|
rv = yield(rv, "completed")
|
|
|
|
return rv
|
2019-09-17 08:12:53 +02:00
|
|
|
return { defs="", code="", textures={} }
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _serialize(data: Dictionary) -> Dictionary:
|
2019-09-22 22:17:26 +02:00
|
|
|
data.type = "ios"
|
|
|
|
data.ports = ports
|
2019-09-17 08:12:53 +02:00
|
|
|
return data
|
2019-11-04 07:58:17 +01:00
|
|
|
|
|
|
|
func _deserialize(data : Dictionary) -> void:
|
|
|
|
ports = data.ports
|