From 8f4a5251079d08e4f32883c421885a4d61add0db Mon Sep 17 00:00:00 2001 From: RodZill4 Date: Wed, 6 Nov 2019 23:49:26 +0100 Subject: [PATCH] Added missing return types (#30) --- addons/material_maker/engine/gen_base.gd | 17 +++++++------ addons/material_maker/engine/gen_buffer.gd | 2 +- addons/material_maker/engine/gen_graph.gd | 10 ++++---- addons/material_maker/engine/gen_remote.gd | 25 ++++++++++--------- addons/material_maker/engine/gen_shader.gd | 6 ++--- addons/material_maker/graph_edit.gd | 12 +++++---- addons/material_maker/nodes/base.gd | 4 +-- addons/material_maker/nodes/debug.gd | 4 +-- addons/material_maker/nodes/ios/port.gd | 8 +++--- .../material_maker/widgets/gradient_editor.gd | 4 +-- .../widgets/linked_widgets/link.gd | 10 +++----- 11 files changed, 52 insertions(+), 50 deletions(-) diff --git a/addons/material_maker/engine/gen_base.gd b/addons/material_maker/engine/gen_base.gd index 64975b4..ac077d6 100644 --- a/addons/material_maker/engine/gen_base.gd +++ b/addons/material_maker/engine/gen_base.gd @@ -53,7 +53,7 @@ func is_editable() -> bool: return false -func has_randomness(): +func has_randomness() -> bool: return false func get_seed() -> int: @@ -65,13 +65,13 @@ func get_seed() -> int: else: return seed_value -func toggle_lock_seed(): +func toggle_lock_seed() -> bool: if !seed_locked: seed_value = get_seed() seed_locked = !seed_locked return seed_locked -func is_seed_locked(): +func is_seed_locked() -> bool: return seed_locked func init_parameters() -> void: @@ -106,17 +106,17 @@ func get_parameter_def(param_name : String) -> Dictionary: return p return {} -func set_parameter(n : String, v): +func set_parameter(n : String, v) -> void: parameters[n] = v source_changed(0) 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) for target in targets: target.generator.source_changed(target.input_index) -func source_changed(__): +func source_changed(__) -> void: emit_signal("parameter_changed", "__input_changed__", 0) for i in range(get_output_defs().size()): notify_output_change(i) @@ -143,10 +143,11 @@ func follow_input(input_index : int) -> Array: rv.push_back(OutputPort.new(self, i)) return rv -func get_input_shader(input_index : int): +func get_input_shader(input_index : int) -> Dictionary: var source = get_source(input_index) if source != null: return source.get_shader() + return {} func get_shader(output_index : int, context) -> Dictionary: return get_shader_code("UV", output_index, context) @@ -193,7 +194,7 @@ func _serialize(data: Dictionary) -> Dictionary: print("cannot save "+name) return data -func serialize(): +func serialize() -> Dictionary: var rv = { name=name, type=get_type(), parameters={}, node_position={ x=position.x, y=position.y } } for p in parameters.keys(): rv.parameters[p] = MMType.serialize_value(parameters[p]) diff --git a/addons/material_maker/engine/gen_buffer.gd b/addons/material_maker/engine/gen_buffer.gd index 3023a25..5de59ee 100644 --- a/addons/material_maker/engine/gen_buffer.gd +++ b/addons/material_maker/engine/gen_buffer.gd @@ -31,7 +31,7 @@ func get_input_defs() -> Array: func get_output_defs() -> Array: return [ { type="rgba" }, { type="rgba" } ] -func source_changed(input_port_index : int): +func source_changed(input_port_index : int) -> void: updated = false .source_changed(input_port_index) diff --git a/addons/material_maker/engine/gen_graph.gd b/addons/material_maker/engine/gen_graph.gd index f78e570..65eb070 100644 --- a/addons/material_maker/engine/gen_graph.gd +++ b/addons/material_maker/engine/gen_graph.gd @@ -21,7 +21,7 @@ func _post_load() -> void: fix_remotes() -func has_randomness(): +func has_randomness() -> bool: return transmits_seed @@ -47,9 +47,9 @@ func get_parameter_defs() -> Array: return get_node("gen_parameters").get_parameter_defs() return [] -func set_parameter(p, v): +func set_parameter(p, v) -> void: 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: if has_node("gen_inputs"): @@ -61,9 +61,9 @@ func get_output_defs() -> Array: return get_node("gen_outputs").get_input_defs() return [] -func source_changed(input_index : int): +func source_changed(input_index : int) -> void: 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: if gen_name == "gen_inputs": diff --git a/addons/material_maker/engine/gen_remote.gd b/addons/material_maker/engine/gen_remote.gd index 7388b0e..fd831f9 100644 --- a/addons/material_maker/engine/gen_remote.gd +++ b/addons/material_maker/engine/gen_remote.gd @@ -21,7 +21,7 @@ func get_widget(n : String) -> Dictionary: return w return {} -func get_next_widget_name(): +func get_next_widget_name() -> String: var i = 0 while true: var param_name = "param"+str(i) @@ -33,6 +33,7 @@ func get_next_widget_name(): if !used: return param_name i += 1 + return "" func fix() -> void: # Make sure all widgets have a name @@ -40,7 +41,6 @@ func fix() -> void: for w in widgets: if !w.has("name"): w.name = get_next_widget_name() - print("Named "+w.name) var parent = get_parent() if parent == null: return @@ -155,16 +155,17 @@ func can_link_parameter(widget_name : String, generator : MMGenBase, param : Str if lw.node == generator.name and lw.widget == param: return false # Check the parameter type - var linked : Dictionary = widget.linked_widgets[0] - var linked_generator : MMGenBase = get_parent().get_node(linked.node) - var linked_parameter : Dictionary = linked_generator.get_parameter_def(linked.widget) - var parameter : Dictionary = generator.get_parameter_def(param) - if parameter.type != linked_parameter.type: - return false - match parameter.type: - "enum": - if to_json(linked_parameter.values) != to_json(parameter.values): - return false + if widget.type == "linked_control": + var linked : Dictionary = widget.linked_widgets[0] + var linked_generator : MMGenBase = get_parent().get_node(linked.node) + var linked_parameter : Dictionary = linked_generator.get_parameter_def(linked.widget) + var parameter : Dictionary = generator.get_parameter_def(param) + if parameter.type != linked_parameter.type: + return false + match parameter.type: + "enum": + if to_json(linked_parameter.values) != to_json(parameter.values): + return false return true func link_parameter(widget_name : String, generator : MMGenBase, param : String) -> void: diff --git a/addons/material_maker/engine/gen_shader.gd b/addons/material_maker/engine/gen_shader.gd index e041717..022808e 100644 --- a/addons/material_maker/engine/gen_shader.gd +++ b/addons/material_maker/engine/gen_shader.gd @@ -16,7 +16,7 @@ func toggle_editable() -> bool: func is_editable() -> bool: return editable -func has_randomness(): +func has_randomness() -> bool: return uses_seed func get_type() -> String: @@ -39,13 +39,13 @@ func get_input_defs() -> Array: else: return shader_model.inputs -func get_output_defs(): +func get_output_defs() -> Array: if shader_model == null or !shader_model.has("outputs"): return [] else: return shader_model.outputs -func set_shader_model(data: Dictionary): +func set_shader_model(data: Dictionary) -> void: shader_model = data init_parameters() uses_seed = false diff --git a/addons/material_maker/graph_edit.gd b/addons/material_maker/graph_edit.gd index b077425..6cae875 100644 --- a/addons/material_maker/graph_edit.gd +++ b/addons/material_maker/graph_edit.gd @@ -31,10 +31,11 @@ func _gui_input(event) -> void: # Misc. useful functions -func get_source(node, port): +func get_source(node, port) -> Dictionary: for c in get_connection_list(): if c.to == node and c.to_port == port: return { node=c.from, slot=c.from_port } + return {} func offset_from_global_position(global_position) -> Vector2: return (scroll_offset + global_position - rect_global_position) / zoom @@ -167,17 +168,18 @@ func new_material() -> void: set_need_save(false) center_view() -func get_free_name(type): +func get_free_name(type) -> String: var i = 0 while true: var node_name = type+"_"+str(i) if !has_node(node_name): return node_name 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: - return + return [] if data.has("type"): data = { nodes=[data], connections=[] } 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) -func _on_ButtonTransmitsSeed_toggled(button_pressed): +func _on_ButtonTransmitsSeed_toggled(button_pressed) -> void: if button_pressed != generator.transmits_seed: generator.transmits_seed = button_pressed diff --git a/addons/material_maker/nodes/base.gd b/addons/material_maker/nodes/base.gd index 96d33ab..60c177e 100644 --- a/addons/material_maker/nodes/base.gd +++ b/addons/material_maker/nodes/base.gd @@ -7,7 +7,7 @@ var generator : MMGenBase = null setget set_generator func _ready() -> void: connect("offset_changed", self, "_on_offset_changed") -func _draw(): +func _draw() -> void: 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") 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: 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): generator.toggle_lock_seed() update() diff --git a/addons/material_maker/nodes/debug.gd b/addons/material_maker/nodes/debug.gd index 5cce0e9..07bbda2 100644 --- a/addons/material_maker/nodes/debug.gd +++ b/addons/material_maker/nodes/debug.gd @@ -22,10 +22,10 @@ static func generate_shader(src_code) -> String: code += shader_code return code -func _on_Button_pressed(): +func _on_Button_pressed() -> void: var src = generator.get_source(0) 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 popup = preload("res://addons/material_maker/nodes/debug/debug_popup.tscn").instance() get_parent().add_child(popup) diff --git a/addons/material_maker/nodes/ios/port.gd b/addons/material_maker/nodes/ios/port.gd index eb32006..8f2d297 100644 --- a/addons/material_maker/nodes/ios/port.gd +++ b/addons/material_maker/nodes/ios/port.gd @@ -10,14 +10,14 @@ func update_up_down_button() -> void: $Up.disabled = (get_index() == 0) $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) -func _on_Delete_pressed(): +func _on_Delete_pressed() -> void: 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) -func _on_Down_pressed(): +func _on_Down_pressed() -> void: get_parent().generator.swap_ports(get_index(), get_index()+1) diff --git a/addons/material_maker/widgets/gradient_editor.gd b/addons/material_maker/widgets/gradient_editor.gd index ad35c61..1dafe06 100644 --- a/addons/material_maker/widgets/gradient_editor.gd +++ b/addons/material_maker/widgets/gradient_editor.gd @@ -13,7 +13,7 @@ class GradientCursor: rect_position = Vector2(0, 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 c = color c.a = 1.0 @@ -153,6 +153,6 @@ func update_shader() -> void: $Gradient.material.shader.set_code(shader) emit_signal("updated", value) -func _on_Interpolation_item_selected(ID): +func _on_Interpolation_item_selected(ID) -> void: value.interpolation = ID update_shader() diff --git a/addons/material_maker/widgets/linked_widgets/link.gd b/addons/material_maker/widgets/linked_widgets/link.gd index e969bfc..f93b8de 100644 --- a/addons/material_maker/widgets/linked_widgets/link.gd +++ b/addons/material_maker/widgets/linked_widgets/link.gd @@ -35,7 +35,7 @@ func show_link(s, t) -> void: 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))) -func find_control(gp): +func find_control(gp) -> Dictionary: for c in get_parent().get_children(): if c is GraphNode: if c.get("controls") != null: @@ -43,11 +43,9 @@ func find_control(gp): var widget = c.controls[w] if Rect2(widget.rect_global_position, widget.rect_size*widget.get_global_transform().get_scale()).has_point(gp): return { node=c, widget=widget } - return null + return {} 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 color = Color(1, 0.5, 0.5, 0.5) var rect @@ -69,13 +67,13 @@ func _input(event: InputEvent) -> void: elif event is InputEventMouseMotion: var control = find_control(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() elif event is InputEventMouseButton: if event.pressed: if event.button_index == BUTTON_LEFT: var control = find_control(event.global_position) - if control != null: + if !control.empty(): generator.link_parameter(param_name, control.node.generator, control.widget.name) elif creating: generator.remove_parameter(param_name)