Added missing return types (#30)

This commit is contained in:
RodZill4 2019-11-06 23:49:26 +01:00
parent 416b44e395
commit 8f4a525107
11 changed files with 52 additions and 50 deletions

View File

@ -53,7 +53,7 @@ func is_editable() -> bool:
return false return false
func has_randomness(): func has_randomness() -> bool:
return false return false
func get_seed() -> int: func get_seed() -> int:
@ -65,13 +65,13 @@ func get_seed() -> int:
else: else:
return seed_value return seed_value
func toggle_lock_seed(): func toggle_lock_seed() -> bool:
if !seed_locked: if !seed_locked:
seed_value = get_seed() seed_value = get_seed()
seed_locked = !seed_locked seed_locked = !seed_locked
return seed_locked return seed_locked
func is_seed_locked(): func is_seed_locked() -> bool:
return seed_locked return seed_locked
func init_parameters() -> void: func init_parameters() -> void:
@ -106,17 +106,17 @@ func get_parameter_def(param_name : String) -> Dictionary:
return p return p
return {} return {}
func set_parameter(n : String, v): func set_parameter(n : String, v) -> void:
parameters[n] = v parameters[n] = v
source_changed(0) source_changed(0)
emit_signal("parameter_changed", n, v) emit_signal("parameter_changed", n, v)
func notify_output_change(output_index : int): func notify_output_change(output_index : int) -> void:
var targets = get_targets(output_index) var targets = get_targets(output_index)
for target in targets: for target in targets:
target.generator.source_changed(target.input_index) target.generator.source_changed(target.input_index)
func source_changed(__): func source_changed(__) -> void:
emit_signal("parameter_changed", "__input_changed__", 0) emit_signal("parameter_changed", "__input_changed__", 0)
for i in range(get_output_defs().size()): for i in range(get_output_defs().size()):
notify_output_change(i) notify_output_change(i)
@ -143,10 +143,11 @@ func follow_input(input_index : int) -> Array:
rv.push_back(OutputPort.new(self, i)) rv.push_back(OutputPort.new(self, i))
return rv return rv
func get_input_shader(input_index : int): func get_input_shader(input_index : int) -> Dictionary:
var source = get_source(input_index) var source = get_source(input_index)
if source != null: if source != null:
return source.get_shader() return source.get_shader()
return {}
func get_shader(output_index : int, context) -> Dictionary: func get_shader(output_index : int, context) -> Dictionary:
return get_shader_code("UV", output_index, context) return get_shader_code("UV", output_index, context)
@ -193,7 +194,7 @@ func _serialize(data: Dictionary) -> Dictionary:
print("cannot save "+name) print("cannot save "+name)
return data return data
func serialize(): func serialize() -> Dictionary:
var rv = { name=name, type=get_type(), parameters={}, node_position={ x=position.x, y=position.y } } var rv = { name=name, type=get_type(), parameters={}, node_position={ x=position.x, y=position.y } }
for p in parameters.keys(): for p in parameters.keys():
rv.parameters[p] = MMType.serialize_value(parameters[p]) rv.parameters[p] = MMType.serialize_value(parameters[p])

View File

@ -31,7 +31,7 @@ func get_input_defs() -> Array:
func get_output_defs() -> Array: func get_output_defs() -> Array:
return [ { type="rgba" }, { type="rgba" } ] return [ { type="rgba" }, { type="rgba" } ]
func source_changed(input_port_index : int): func source_changed(input_port_index : int) -> void:
updated = false updated = false
.source_changed(input_port_index) .source_changed(input_port_index)

View File

@ -21,7 +21,7 @@ func _post_load() -> void:
fix_remotes() fix_remotes()
func has_randomness(): func has_randomness() -> bool:
return transmits_seed return transmits_seed
@ -47,9 +47,9 @@ func get_parameter_defs() -> Array:
return get_node("gen_parameters").get_parameter_defs() return get_node("gen_parameters").get_parameter_defs()
return [] return []
func set_parameter(p, v): func set_parameter(p, v) -> void:
if has_node("gen_parameters"): if has_node("gen_parameters"):
return get_node("gen_parameters").set_parameter(p, v) get_node("gen_parameters").set_parameter(p, v)
func get_input_defs() -> Array: func get_input_defs() -> Array:
if has_node("gen_inputs"): if has_node("gen_inputs"):
@ -61,9 +61,9 @@ func get_output_defs() -> Array:
return get_node("gen_outputs").get_input_defs() return get_node("gen_outputs").get_input_defs()
return [] return []
func source_changed(input_index : int): func source_changed(input_index : int) -> void:
if has_node("gen_inputs"): if has_node("gen_inputs"):
return get_node("gen_inputs").source_changed(input_index) get_node("gen_inputs").source_changed(input_index)
func get_port_source(gen_name: String, input_index: int) -> OutputPort: func get_port_source(gen_name: String, input_index: int) -> OutputPort:
if gen_name == "gen_inputs": if gen_name == "gen_inputs":

View File

@ -21,7 +21,7 @@ func get_widget(n : String) -> Dictionary:
return w return w
return {} return {}
func get_next_widget_name(): func get_next_widget_name() -> String:
var i = 0 var i = 0
while true: while true:
var param_name = "param"+str(i) var param_name = "param"+str(i)
@ -33,6 +33,7 @@ func get_next_widget_name():
if !used: if !used:
return param_name return param_name
i += 1 i += 1
return ""
func fix() -> void: func fix() -> void:
# Make sure all widgets have a name # Make sure all widgets have a name
@ -40,7 +41,6 @@ func fix() -> void:
for w in widgets: for w in widgets:
if !w.has("name"): if !w.has("name"):
w.name = get_next_widget_name() w.name = get_next_widget_name()
print("Named "+w.name)
var parent = get_parent() var parent = get_parent()
if parent == null: if parent == null:
return return
@ -155,6 +155,7 @@ func can_link_parameter(widget_name : String, generator : MMGenBase, param : Str
if lw.node == generator.name and lw.widget == param: if lw.node == generator.name and lw.widget == param:
return false return false
# Check the parameter type # Check the parameter type
if widget.type == "linked_control":
var linked : Dictionary = widget.linked_widgets[0] var linked : Dictionary = widget.linked_widgets[0]
var linked_generator : MMGenBase = get_parent().get_node(linked.node) var linked_generator : MMGenBase = get_parent().get_node(linked.node)
var linked_parameter : Dictionary = linked_generator.get_parameter_def(linked.widget) var linked_parameter : Dictionary = linked_generator.get_parameter_def(linked.widget)

View File

@ -16,7 +16,7 @@ func toggle_editable() -> bool:
func is_editable() -> bool: func is_editable() -> bool:
return editable return editable
func has_randomness(): func has_randomness() -> bool:
return uses_seed return uses_seed
func get_type() -> String: func get_type() -> String:
@ -39,13 +39,13 @@ func get_input_defs() -> Array:
else: else:
return shader_model.inputs return shader_model.inputs
func get_output_defs(): func get_output_defs() -> Array:
if shader_model == null or !shader_model.has("outputs"): if shader_model == null or !shader_model.has("outputs"):
return [] return []
else: else:
return shader_model.outputs return shader_model.outputs
func set_shader_model(data: Dictionary): func set_shader_model(data: Dictionary) -> void:
shader_model = data shader_model = data
init_parameters() init_parameters()
uses_seed = false uses_seed = false

View File

@ -31,10 +31,11 @@ func _gui_input(event) -> void:
# Misc. useful functions # Misc. useful functions
func get_source(node, port): func get_source(node, port) -> Dictionary:
for c in get_connection_list(): for c in get_connection_list():
if c.to == node and c.to_port == port: if c.to == node and c.to_port == port:
return { node=c.from, slot=c.from_port } return { node=c.from, slot=c.from_port }
return {}
func offset_from_global_position(global_position) -> Vector2: func offset_from_global_position(global_position) -> Vector2:
return (scroll_offset + global_position - rect_global_position) / zoom return (scroll_offset + global_position - rect_global_position) / zoom
@ -167,17 +168,18 @@ func new_material() -> void:
set_need_save(false) set_need_save(false)
center_view() center_view()
func get_free_name(type): func get_free_name(type) -> String:
var i = 0 var i = 0
while true: while true:
var node_name = type+"_"+str(i) var node_name = type+"_"+str(i)
if !has_node(node_name): if !has_node(node_name):
return node_name return node_name
i += 1 i += 1
return ""
func create_nodes(data, position : Vector2 = Vector2(0, 0)): func create_nodes(data, position : Vector2 = Vector2(0, 0)) -> Array:
if data == null: if data == null:
return return []
if data.has("type"): if data.has("type"):
data = { nodes=[data], connections=[] } data = { nodes=[data], connections=[] }
if typeof(data.nodes) == TYPE_ARRAY and typeof(data.connections) == TYPE_ARRAY: if typeof(data.nodes) == TYPE_ARRAY and typeof(data.connections) == TYPE_ARRAY:
@ -334,6 +336,6 @@ func edit_subgraph(g : MMGenGraph) -> void:
update_view(g) update_view(g)
func _on_ButtonTransmitsSeed_toggled(button_pressed): func _on_ButtonTransmitsSeed_toggled(button_pressed) -> void:
if button_pressed != generator.transmits_seed: if button_pressed != generator.transmits_seed:
generator.transmits_seed = button_pressed generator.transmits_seed = button_pressed

View File

@ -7,7 +7,7 @@ var generator : MMGenBase = null setget set_generator
func _ready() -> void: func _ready() -> void:
connect("offset_changed", self, "_on_offset_changed") connect("offset_changed", self, "_on_offset_changed")
func _draw(): func _draw() -> void:
if generator != null and generator.has_randomness(): if generator != null and generator.has_randomness():
var icon = preload("res://addons/material_maker/icons/randomness_locked.tres") if generator.is_seed_locked() else preload("res://addons/material_maker/icons/randomness_unlocked.tres") var icon = preload("res://addons/material_maker/icons/randomness_locked.tres") if generator.is_seed_locked() else preload("res://addons/material_maker/icons/randomness_unlocked.tres")
draw_texture_rect(icon, Rect2(rect_size.x-48, 4, 16, 16), false) draw_texture_rect(icon, Rect2(rect_size.x-48, 4, 16, 16), false)
@ -23,7 +23,7 @@ func set_generator(g) -> void:
func _on_offset_changed() -> void: func _on_offset_changed() -> void:
generator.set_position(offset) generator.set_position(offset)
func _on_gui_input(event): func _on_gui_input(event) -> void:
if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and Rect2(rect_size.x-48, 4, 16, 16).has_point(event.position): if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_LEFT and Rect2(rect_size.x-48, 4, 16, 16).has_point(event.position):
generator.toggle_lock_seed() generator.toggle_lock_seed()
update() update()

View File

@ -22,10 +22,10 @@ static func generate_shader(src_code) -> String:
code += shader_code code += shader_code
return code return code
func _on_Button_pressed(): func _on_Button_pressed() -> void:
var src = generator.get_source(0) var src = generator.get_source(0)
if src != null: if src != null:
var context : MMGenContext = MMGenContext.new(null) var context : MMGenContext = MMGenContext.new()
var source = src.generator.get_shader_code("UV", src.output_index, context) var source = src.generator.get_shader_code("UV", src.output_index, context)
var popup = preload("res://addons/material_maker/nodes/debug/debug_popup.tscn").instance() var popup = preload("res://addons/material_maker/nodes/debug/debug_popup.tscn").instance()
get_parent().add_child(popup) get_parent().add_child(popup)

View File

@ -10,14 +10,14 @@ func update_up_down_button() -> void:
$Up.disabled = (get_index() == 0) $Up.disabled = (get_index() == 0)
$Down.disabled = (get_index() == get_parent().get_child_count()-2) $Down.disabled = (get_index() == get_parent().get_child_count()-2)
func _on_Name_label_changed(new_label): func _on_Name_label_changed(new_label) -> void:
get_parent().generator.set_port_name(get_index(), new_label) get_parent().generator.set_port_name(get_index(), new_label)
func _on_Delete_pressed(): func _on_Delete_pressed() -> void:
get_parent().generator.delete_port(get_index()) get_parent().generator.delete_port(get_index())
func _on_Up_pressed(): func _on_Up_pressed() -> void:
get_parent().generator.swap_ports(get_index(), get_index()-1) get_parent().generator.swap_ports(get_index(), get_index()-1)
func _on_Down_pressed(): func _on_Down_pressed() -> void:
get_parent().generator.swap_ports(get_index(), get_index()+1) get_parent().generator.swap_ports(get_index(), get_index()+1)

View File

@ -13,7 +13,7 @@ class GradientCursor:
rect_position = Vector2(0, 15) rect_position = Vector2(0, 15)
rect_size = Vector2(WIDTH, 15) rect_size = Vector2(WIDTH, 15)
func _draw(): func _draw() -> void:
var polygon : PoolVector2Array = PoolVector2Array([Vector2(0, 5), Vector2(WIDTH/2, 0), Vector2(WIDTH, 5), Vector2(WIDTH, 15), Vector2(0, 15)]) var polygon : PoolVector2Array = PoolVector2Array([Vector2(0, 5), Vector2(WIDTH/2, 0), Vector2(WIDTH, 5), Vector2(WIDTH, 15), Vector2(0, 15)])
var c = color var c = color
c.a = 1.0 c.a = 1.0
@ -153,6 +153,6 @@ func update_shader() -> void:
$Gradient.material.shader.set_code(shader) $Gradient.material.shader.set_code(shader)
emit_signal("updated", value) emit_signal("updated", value)
func _on_Interpolation_item_selected(ID): func _on_Interpolation_item_selected(ID) -> void:
value.interpolation = ID value.interpolation = ID
update_shader() update_shader()

View File

@ -35,7 +35,7 @@ func show_link(s, t) -> void:
func closest(rect, point) -> Vector2: func closest(rect, point) -> Vector2:
return Vector2(max(rect.position.x, min(rect.end.x, point.x)), max(rect.position.y, min(rect.end.y, point.y))) return Vector2(max(rect.position.x, min(rect.end.x, point.x)), max(rect.position.y, min(rect.end.y, point.y)))
func find_control(gp): func find_control(gp) -> Dictionary:
for c in get_parent().get_children(): for c in get_parent().get_children():
if c is GraphNode: if c is GraphNode:
if c.get("controls") != null: if c.get("controls") != null:
@ -43,11 +43,9 @@ func find_control(gp):
var widget = c.controls[w] var widget = c.controls[w]
if Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp): if Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp):
return { node=c, widget=widget } return { node=c, widget=widget }
return null return {}
func _draw() -> void: func _draw() -> void:
#draw_rect(Rect2(rect_position, rect_size), Color(1.0, 0.0, 0.0, 0.2))
#draw_rect(Rect2(rect_position, rect_size), Color(1.0, 1.0, 0.0), false)
var start = get_global_transform().xform_inv(source.get_global_transform().xform(0.5*source.rect_size)) var start = get_global_transform().xform_inv(source.get_global_transform().xform(0.5*source.rect_size))
var color = Color(1, 0.5, 0.5, 0.5) var color = Color(1, 0.5, 0.5, 0.5)
var rect var rect
@ -69,13 +67,13 @@ func _input(event: InputEvent) -> void:
elif event is InputEventMouseMotion: elif event is InputEventMouseMotion:
var control = find_control(event.global_position) var control = find_control(event.global_position)
end = get_global_transform().xform_inv(event.global_position) end = get_global_transform().xform_inv(event.global_position)
target = control.widget if control != null and generator.can_link_parameter(param_name, control.node.generator, control.widget.name) else null target = control.widget if !control.empty() and generator.can_link_parameter(param_name, control.node.generator, control.widget.name) else null
update() update()
elif event is InputEventMouseButton: elif event is InputEventMouseButton:
if event.pressed: if event.pressed:
if event.button_index == BUTTON_LEFT: if event.button_index == BUTTON_LEFT:
var control = find_control(event.global_position) var control = find_control(event.global_position)
if control != null: if !control.empty():
generator.link_parameter(param_name, control.node.generator, control.widget.name) generator.link_parameter(param_name, control.node.generator, control.widget.name)
elif creating: elif creating:
generator.remove_parameter(param_name) generator.remove_parameter(param_name)