mirror of
https://github.com/Relintai/material-maker.git
synced 2024-12-23 21:16:54 +01:00
Added missing return types (#30)
This commit is contained in:
parent
416b44e395
commit
8f4a525107
@ -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])
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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":
|
||||
|
@ -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,6 +155,7 @@ 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
|
||||
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)
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user