Add hacky implementation of group instances

Adds a button that makes groups with names like copy_X copy their
contents from other groups.
This commit is contained in:
easynam 2021-10-07 20:06:35 +01:00
parent 3d357f55ef
commit e127c814f5
2 changed files with 46 additions and 1 deletions

View File

@ -708,3 +708,40 @@ func on_drop_image_file(file_name : String) -> void:
func _on_Description_descriptions_changed(short_description, long_description):
generator.shortdesc = short_description
generator.longdesc = long_description
func find_graph_with_label(label: String) -> GraphNode:
for c in get_children():
if c is GraphNode and c.generator is MMGenGraph && c.generator.get_type_name() == label:
return c
return null
func _on_ButtonRegenCopies_pressed():
for c in get_children():
if c is GraphNode and c.generator is MMGenGraph and c.generator.get_type_name().begins_with("copy_"):
var gen = c.generator
var copy_from_label = gen.get_type_name().substr(5,-1)
var label = gen.get_type_name()
var copy_from = find_graph_with_label(copy_from_label)
if copy_from == null:
continue
var data = copy_from.generator._serialize({})
var param_data = copy_from.generator.get_node("gen_parameters")._serialize({})
for n in gen.get_children():
gen.remove_child(n)
n.queue_free()
data.label = label
gen._deserialize(data)
var params = gen.get_node("gen_parameters")
params._deserialize(param_data)
gen.fix_remotes()
var main_window = get_node("/root/MainWindow")
main_window.hierarchy.update_from_graph_edit(self)
update()

View File

@ -44,7 +44,7 @@ one_shot = true
[node name="GraphUI" type="HBoxContainer" parent="."]
anchor_left = 1.0
anchor_right = 1.0
margin_left = -294.0
margin_left = -698.0
margin_top = 11.0
margin_bottom = 24.0
alignment = 2
@ -92,6 +92,13 @@ margin_bottom = 24.0
hint_tooltip = "Show hierarchy"
icon = SubResource( 4 )
[node name="ButtonRegenCopies" type="Button" parent="GraphUI"]
margin_left = 551.0
margin_right = 682.0
margin_bottom = 24.0
hint_tooltip = "Copies the contents of groups named X to any other groups named copy_X"
text = "Regenerate Copies"
[node name="Control" type="Control" parent="GraphUI"]
margin_left = 282.0
margin_right = 296.0
@ -116,3 +123,4 @@ script = ExtResource( 3 )
[connection signal="toggled" from="GraphUI/SubGraphUI/ButtonTransmitsSeed" to="." method="_on_ButtonTransmitsSeed_toggled"]
[connection signal="pressed" from="GraphUI/SubGraphUI/ButtonUp" to="." method="on_ButtonUp_pressed"]
[connection signal="pressed" from="GraphUI/ButtonShowTree" to="." method="_on_ButtonShowTree_pressed"]
[connection signal="pressed" from="GraphUI/ButtonRegenCopies" to="." method="_on_ButtonRegenCopies_pressed"]