1
0
mirror of https://github.com/Relintai/broken_seals.git synced 2024-12-21 13:16:49 +01:00

Now add slot universal methods in MMGraphNode only take an universal property as argument. Also added an universal texture slot. Had to add init_properties and _init_properties, and had to change register_methods to _register_methods in subclasses.

This commit is contained in:
Relintai 2021-10-06 10:30:22 +02:00
parent 8654865b1b
commit e31aedbb1b
6 changed files with 97 additions and 43 deletions

View File

@ -20,6 +20,26 @@ func add_slot_texture(input_type : int, output_type : int, getter : String, sett
properties[slot_idx].append(t.texture)
return slot_idx
func add_slot_texture_universal(property : MMNodeUniversalProperty) -> int:
var t : TextureRect = TextureRect.new()
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", t)
var img : Image = property.get_active_image()
var tex : ImageTexture = ImageTexture.new()
if img:
tex.create_from_image(img, 0)
t.texture = tex
properties[slot_idx].append(property)
property.connect("changed", self, "on_universal_texture_changed", [ slot_idx ])
return slot_idx
func add_slot_label(input_type : int, output_type : int, getter : String, setter : String, slot_name : String) -> int:
var l : Label = Label.new()
@ -71,26 +91,26 @@ func add_slot_int(input_type : int, output_type : int, getter : String, setter :
return slot_idx
func add_slot_int_universal(input_property : MMNodeUniversalProperty, output_type : int, slot_name : String, prange : Vector2 = Vector2(-1000, 1000)) -> int:
func add_slot_int_universal(property : MMNodeUniversalProperty) -> int:
var bc : VBoxContainer = VBoxContainer.new()
var l : Label = Label.new()
l.text = slot_name
l.text = property.slot_name
bc.add_child(l)
var sb : SpinBox = SpinBox.new()
sb.rounded = true
sb.min_value = prange.x
sb.max_value = prange.y
sb.min_value = property.value_range.x
sb.max_value = property.value_range.y
bc.add_child(sb)
var slot_idx : int = add_slot(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, output_type, "", "", bc)
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", bc)
sb.value = input_property.get_default_value()
sb.value = property.get_default_value()
sb.connect("value_changed", self, "on_int_universal_spinbox_value_changed", [ slot_idx ])
properties[slot_idx].append(input_property)
properties[slot_idx].append(property)
return slot_idx
@ -115,24 +135,24 @@ func add_slot_float(input_type : int, output_type : int, getter : String, setter
return slot_idx
func add_slot_float_universal(input_property : MMNodeUniversalProperty, output_type : int, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int:
func add_slot_float_universal(property : MMNodeUniversalProperty) -> int:
var bc : VBoxContainer = VBoxContainer.new()
var l : Label = Label.new()
l.text = slot_name
l.text = property.slot_name
bc.add_child(l)
var sb : SpinBox = SpinBox.new()
bc.add_child(sb)
var slot_idx : int = add_slot(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, output_type, "", "", bc)
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", bc)
sb.rounded = false
sb.step = step
sb.min_value = prange.x
sb.max_value = prange.y
sb.value = input_property.get_default_value()
sb.step = property.value_step
sb.min_value = property.value_range.x
sb.max_value = property.value_range.y
sb.value = property.get_default_value()
properties[slot_idx].append(input_property)
properties[slot_idx].append(property)
sb.connect("value_changed", self, "on_float_universal_spinbox_value_changed", [ slot_idx ])
@ -171,11 +191,11 @@ func add_slot_vector2(input_type : int, output_type : int, getter : String, sett
return slot_idx
func add_slot_vector2_universal(input_property : MMNodeUniversalProperty, output_type : int, slot_name : String, step : float = 0.1, prange : Vector2 = Vector2(-1000, 1000)) -> int:
func add_slot_vector2_universal(property : MMNodeUniversalProperty) -> int:
var bc : VBoxContainer = VBoxContainer.new()
var l : Label = Label.new()
l.text = slot_name
l.text = property.slot_name
bc.add_child(l)
var sbx : SpinBox = SpinBox.new()
@ -184,22 +204,22 @@ func add_slot_vector2_universal(input_property : MMNodeUniversalProperty, output
var sby : SpinBox = SpinBox.new()
bc.add_child(sby)
var slot_idx : int = add_slot(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL, output_type, "", "", bc)
var slot_idx : int = add_slot(property.input_slot_type, property.output_slot_type, "", "", bc)
sbx.rounded = false
sby.rounded = false
sbx.step = step
sby.step = step
sbx.min_value = prange.x
sbx.max_value = prange.y
sby.min_value = prange.x
sby.max_value = prange.y
sbx.step = property.value_step
sby.step = property.value_step
sbx.min_value = property.value_range.x
sbx.max_value = property.value_range.y
sby.min_value = property.value_range.x
sby.max_value = property.value_range.y
var val : Vector2 = input_property.get_default_value()
var val : Vector2 = property.get_default_value()
sbx.value = val.x
sby.value = val.y
properties[slot_idx].append(input_property)
properties[slot_idx].append(property)
sbx.connect("value_changed", self, "on_vector2_universal_spinbox_value_changed", [ slot_idx, sbx, sby ])
sby.connect("value_changed", self, "on_vector2_universal_spinbox_value_changed", [ slot_idx, sbx, sby ])
@ -296,3 +316,15 @@ func on_vector2_universal_spinbox_value_changed(val : float, slot_idx, spinbox_x
func on_slot_enum_item_selected(val : int, slot_idx : int) -> void:
_node.call(properties[slot_idx][4], val)
func on_universal_texture_changed(slot_idx : int) -> void:
var img : Image = properties[slot_idx][6].get_active_image()
var tex : ImageTexture = properties[slot_idx][5].texture
if img:
properties[slot_idx][5].texture.create_from_image(img, 0)
else:
properties[slot_idx][5].texture = ImageTexture.new()

View File

@ -28,8 +28,6 @@ default_float = 0.2
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
getter = ""
params = [ ]
[sub_resource type="Resource" id=4]
script = ExtResource( 5 )
@ -39,8 +37,6 @@ default_float = 0.35
default_vector2 = Vector2( 0, 0 )
default_vector3 = Vector3( 0, 0, 0 )
default_color = Color( 0, 0, 0, 1 )
getter = ""
params = [ ]
[sub_resource type="Resource" id=5]
script = ExtResource( 4 )

View File

@ -4,6 +4,8 @@ extends Resource
export(Vector2) var graph_position : Vector2 = Vector2()
var properties_initialized : bool = false
func recalculate_image(material, slot_idx : int) -> ImageTexture:
var image : Image = Image.new()
image.create(material.image_size.x, material.image_size.y, false, Image.FORMAT_RGBA8)
@ -34,7 +36,20 @@ func recalculate_image(material, slot_idx : int) -> ImageTexture:
func get_value_for(uv : Vector2, slot_idx : int, pseed : int) -> Color:
return Color()
func init_properties() -> void:
if !properties_initialized:
properties_initialized = true
_init_properties()
func _init_properties() -> void:
pass
func register_methods(mm_graph_node) -> void:
init_properties()
_register_methods(mm_graph_node)
func _register_methods(mm_graph_node) -> void:
pass
func get_graph_position() -> Vector2:

View File

@ -38,7 +38,7 @@ export(Resource) var input_property : Resource
var input_slot_type : int = SlotTypes.SLOT_TYPE_NONE
var output_slot_type : int = SlotTypes.SLOT_TYPE_NONE
var slot_name : String = ""
var slot_name : String
var value_step : float = 0.1
var value_range : Vector2 = Vector2(-1000, 1000)
@ -101,3 +101,9 @@ func set_default_value(val):
default_image = val
emit_changed()
func get_active_image() -> Image:
if override_image:
return override_image
return default_image

View File

@ -13,7 +13,7 @@ export(float) var persistence : float = 0.5
func get_value_for(uv : Vector2, slot_idx : int, pseed : int) -> Color:
return NoisePerlin.perlinc(uv, scale, iterations, persistence, pseed)
func register_methods(mm_graph_node) -> void:
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_texture(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE, "recalculate_image", "")
mm_graph_node.add_slot_int(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_iterations", "set_iterations", "iterations")#, Vector2(1, 10))
mm_graph_node.add_slot_float(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_persistence", "set_persistence", "persistence", 0.05)#, Vector2(0, 1))

View File

@ -16,10 +16,7 @@ export(int) var sides : int = 6
export(Resource) var radius : Resource
export(Resource) var edge : Resource
#export(float) var radius : float = 0.845361000; #univ input todo
#export(float) var edge : float = 0.051546000; #univ input todo
func _init():
func _init_properties():
var changed : bool = false
if !radius:
@ -27,6 +24,10 @@ func _init():
radius.default_type = MMNodeUniversalProperty.MMNodeUniversalPropertyDefaultType.DEFAULT_TYPE_FLOAT
radius.set_default_value(0.34375)
changed = true
radius.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
radius.slot_name = "radius"
radius.value_step = 0.05
if !edge:
edge = MMNodeUniversalProperty.new()
@ -34,9 +35,20 @@ func _init():
edge.set_default_value(0.2)
changed = true
edge.input_slot_type = MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_UNIVERSAL
edge.slot_name = "edge"
edge.value_step = 0.05
if changed:
emit_changed()
func _register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_texture(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE, "recalculate_image", "")
mm_graph_node.add_slot_enum(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_shape_typoe", "set_shape_typoe", "shape_type", [ "Circle", "Polygon", "Star", "Curved Star", "Rays" ])
mm_graph_node.add_slot_int(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_sides", "set_sides", "sides")#, Vector2(1, 10))
mm_graph_node.add_slot_float_universal(radius)
mm_graph_node.add_slot_float_universal(edge)
func get_value_for(uv : Vector2, slot_idx : int, pseed : int) -> Color:
var c : float = 0
@ -53,13 +65,6 @@ func get_value_for(uv : Vector2, slot_idx : int, pseed : int) -> Color:
return Color(c, c, c, 1)
func register_methods(mm_graph_node) -> void:
mm_graph_node.add_slot_texture(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_IMAGE, "recalculate_image", "")
mm_graph_node.add_slot_enum(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_shape_typoe", "set_shape_typoe", "shape_type", [ "Circle", "Polygon", "Star", "Curved Star", "Rays" ])
mm_graph_node.add_slot_int(MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "get_sides", "set_sides", "sides")#, Vector2(1, 10))
mm_graph_node.add_slot_float_universal(radius, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "radius", 0.05)
mm_graph_node.add_slot_float_universal(edge, MMNodeUniversalProperty.SlotTypes.SLOT_TYPE_NONE, "edge", 0.05)
func get_shape_typoe() -> int:
return shape_type