2 extends DialogicVisualEditorField
4 ## Event block field for editing dictionaries.
6 const DictionaryValue = "res://addons/dialogic/Editor/Events/Fields/dictionary_part.tscn"
9 %Add.icon = get_theme_icon("Add", "EditorIcons")
12 func _set_value(value:Variant) -> void:
13 for child in get_children():
19 # attempt to take dictionary values, create a fresh one if not possible
20 if typeof(value) == TYPE_DICTIONARY:
22 elif typeof(value) == TYPE_STRING:
23 if value.begins_with('{'):
24 var result: Variant = JSON.parse_string(value)
26 dict = result as Dictionary
28 var keys := dict.keys()
29 var values := dict.values()
31 for index in dict.size():
32 var x: Node = load(DictionaryValue).instantiate()
34 x.set_value(values[index])
35 x.set_key(keys[index])
36 x.value_changed.connect(recalculate_values)
40 func _on_value_changed(value:Variant) -> void:
41 value_changed.emit(property_name, value)
44 func recalculate_values() -> void:
46 for child in get_children():
47 if child != %Add and !child.is_queued_for_deletion():
48 dict[child.get_key()] = child.get_value()
49 _on_value_changed(dict)
52 func _on_AddButton_pressed() -> void:
53 var x: Control = load(DictionaryValue).instantiate()
57 x.value_changed.connect(recalculate_values)