2019-09-10 22:51:49 +02:00
|
|
|
tool
|
|
|
|
extends MMGenBase
|
|
|
|
class_name MMGenSwitch
|
|
|
|
|
|
|
|
"""
|
|
|
|
Texture generator switch
|
|
|
|
"""
|
|
|
|
|
2019-10-20 00:59:51 +02:00
|
|
|
var editable = false
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_type() -> String:
|
2019-09-10 22:51:49 +02:00
|
|
|
return "switch"
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_type_name() -> String:
|
2019-09-10 22:51:49 +02:00
|
|
|
return "Switch"
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func toggle_editable() -> bool:
|
2019-10-20 00:59:51 +02:00
|
|
|
editable = !editable
|
|
|
|
return true
|
2019-10-20 16:22:06 +02:00
|
|
|
|
|
|
|
func is_editable() -> bool:
|
2019-10-20 00:59:51 +02:00
|
|
|
return editable
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_parameter_defs() -> Array:
|
2019-10-20 00:59:51 +02:00
|
|
|
var choices = parameters.choices if parameters.has("choices") else 2
|
2019-10-17 14:15:51 +02:00
|
|
|
return [
|
|
|
|
{ name="outputs", label="Outputs", type="float", min=1, max=5, step=1, default=2 },
|
|
|
|
{ name="choices", label="Choices", type="float", min=2, max=5, step=1, default=2 },
|
2019-10-20 00:59:51 +02:00
|
|
|
{ name="source", label="Source", type="float", min=0, max=choices-1, step=1, default=0 },
|
2019-10-17 14:15:51 +02:00
|
|
|
]
|
2019-09-10 22:51:49 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_input_defs() -> Array:
|
2019-09-22 22:17:26 +02:00
|
|
|
var rv : Array = []
|
|
|
|
for c in range(parameters.choices):
|
|
|
|
for o in range(parameters.outputs):
|
2019-10-20 00:59:51 +02:00
|
|
|
var n = PoolByteArray([65+o]).get_string_from_ascii()+str(c)
|
2019-12-25 10:36:45 +01:00
|
|
|
rv.push_back({ name=n, label=n, type="any" })
|
2019-09-22 22:17:26 +02:00
|
|
|
return rv
|
2019-10-17 14:15:51 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_output_defs() -> Array:
|
2019-09-22 22:17:26 +02:00
|
|
|
var rv : Array = []
|
2020-03-13 07:50:04 +01:00
|
|
|
for o in range(get_parameter("outputs")):
|
2019-10-20 00:59:51 +02:00
|
|
|
var n = PoolByteArray([65+o]).get_string_from_ascii()
|
2019-12-25 10:36:45 +01:00
|
|
|
rv.push_back({ name=n, type="any" })
|
2019-09-22 22:17:26 +02:00
|
|
|
return rv
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func set_parameter(p, v) -> void:
|
2019-10-27 14:48:35 +01:00
|
|
|
if p == "outputs" or p == "choices":
|
|
|
|
var parent = get_parent()
|
|
|
|
if parent != null:
|
|
|
|
var connected_inputs : Array = parent.get_connected_inputs(self)
|
|
|
|
var connected_outputs : Array = parent.get_connected_outputs(self)
|
|
|
|
var inputs_changes : Dictionary = {}
|
|
|
|
var outputs_changes : Dictionary = {}
|
|
|
|
if p == "outputs":
|
|
|
|
for i in connected_inputs:
|
|
|
|
var input = int(i) % int(parameters.outputs)
|
|
|
|
var choice = int(i) / int(parameters.outputs)
|
|
|
|
if input >= v:
|
|
|
|
inputs_changes[i] = -1
|
|
|
|
else:
|
|
|
|
inputs_changes[i] = input + v * choice
|
|
|
|
for i in connected_outputs:
|
|
|
|
if i >= v:
|
|
|
|
outputs_changes[i] = -1
|
|
|
|
else:
|
|
|
|
for i in connected_inputs:
|
|
|
|
var input = int(i) % int(parameters.outputs)
|
|
|
|
var choice = int(i) / int(parameters.outputs)
|
|
|
|
if choice >= v:
|
|
|
|
inputs_changes[i] = -1
|
|
|
|
parent.reconnect_inputs(self, inputs_changes)
|
|
|
|
parent.reconnect_outputs(self, outputs_changes)
|
2019-10-20 00:59:51 +02:00
|
|
|
.set_parameter(p, v)
|
|
|
|
emit_signal("parameter_changed", "__update_all__", null)
|
|
|
|
|
2019-10-20 17:28:06 +02:00
|
|
|
# get the list of outputs that depend on the input whose index is passed as parameter
|
|
|
|
func follow_input(input_index : int) -> Array:
|
|
|
|
return [ OutputPort.new(self, input_index % int(parameters.outputs)) ]
|
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func source_changed(input_index : int) -> void:
|
2019-10-21 23:58:14 +02:00
|
|
|
if parameters.has("outputs"):
|
|
|
|
notify_output_change(input_index % int(parameters.outputs))
|
2019-09-22 22:17:26 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _get_shader_code(uv : String, output_index : int, context : MMGenContext) -> Dictionary:
|
2019-09-22 22:17:26 +02:00
|
|
|
var source = get_source(output_index+parameters.source*parameters.outputs)
|
|
|
|
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-10-20 00:59:51 +02:00
|
|
|
return { globals=[], defs="", code="", textures={} }
|
2019-09-29 10:07:32 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func _serialize(data: Dictionary) -> Dictionary:
|
2019-09-29 10:07:32 +02:00
|
|
|
return data
|