Skip to content

Commit 082c129

Browse files
Change choice extra data syntax to not be a dictionary (#2345)
- Also allows setting dictionaries in Event Defaults and Style Editor.
1 parent b72f43f commit 082c129

File tree

5 files changed

+102
-42
lines changed

5 files changed

+102
-42
lines changed

addons/dialogic/Core/DialogicUtil.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,14 @@ static func setup_script_property_edit_node(property_info: Dictionary, value:Var
447447
if value != null:
448448
input.text = value
449449
input.text_submitted.connect(DialogicUtil._on_export_input_text_submitted.bind(property_info.name, property_changed))
450+
TYPE_DICTIONARY:
451+
input = load("res://addons/dialogic/Editor/Events/Fields/field_dictionary.tscn").instantiate()
452+
input.property_name = property_info["name"]
453+
input.value_changed.connect(_on_export_dict_submitted.bind(property_changed))
450454
TYPE_OBJECT:
451455
input = load("res://addons/dialogic/Editor/Common/hint_tooltip_icon.tscn").instantiate()
452456
input.hint_text = "Objects/Resources as settings are currently not supported. \nUse @export_file('*.extension') instead and load the resource once needed."
457+
453458
_:
454459
input = LineEdit.new()
455460
if value != null:
@@ -482,6 +487,9 @@ static func _on_export_string_enum_submitted(value:int, property_name:String, li
482487
static func _on_export_vector_submitted(property_name:String, value:Variant, callable: Callable) -> void:
483488
callable.call(property_name, var_to_str(value))
484489

490+
static func _on_export_dict_submitted(property_name:String, value:Variant, callable: Callable) -> void:
491+
callable.call(property_name, var_to_str(value))
492+
485493
#endregion
486494

487495

addons/dialogic/Editor/Settings/settings_modules.gd

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ func _refresh() -> void:
3737

3838

3939
func _on_refresh_pressed() -> void:
40+
DialogicUtil.get_indexers(true, true)
41+
DialogicResourceUtil.update_event_cache()
4042
load_modules_tree()
4143

4244

@@ -318,17 +320,23 @@ func load_event_settings(event:DialogicEvent) -> void:
318320

319321
var params := event.get_shortcode_parameters()
320322
for prop in params:
323+
var current_value: Variant = params[prop].default
324+
if event_default_overrides.get(event.event_name, {}).has(params[prop].property):
325+
current_value = event_default_overrides.get(event.event_name, {}).get(params[prop].property)
326+
321327
# Label
322328
var label := Label.new()
323329
label.text = prop.capitalize()
324330
%EventDefaults.add_child(label)
325331

332+
var reset := Button.new()
333+
reset.icon = get_theme_icon("Clear", "EditorIcons")
334+
reset.flat = true
335+
336+
%EventDefaults.add_child(reset)
337+
326338
# Editing field
327339
var editor_node: Node = null
328-
var current_value: Variant = params[prop].default
329-
if event_default_overrides.get(event.event_name, {}).has(params[prop].property):
330-
current_value = event_default_overrides.get(event.event_name, {}).get(params[prop].property)
331-
332340
match typeof(event.get(params[prop].property)):
333341
TYPE_STRING:
334342
editor_node = LineEdit.new()
@@ -356,7 +364,7 @@ func load_event_settings(event:DialogicEvent) -> void:
356364
editor_node.value_changed.connect(_on_event_default_number_changed.bind(params[prop].property))
357365

358366
TYPE_VECTOR2:
359-
editor_node = load("res://addons/dialogic/Editor/Events/Fields/Vector2.tscn").instantiate()
367+
editor_node = load("res://addons/dialogic/Editor/Events/Fields/field_vector2.tscn").instantiate()
360368
editor_node.set_value(current_value)
361369
editor_node.property_name = params[prop].property
362370
editor_node.value_changed.connect(_on_event_default_value_changed)
@@ -367,12 +375,18 @@ func load_event_settings(event:DialogicEvent) -> void:
367375
editor_node.toggled.connect(_on_event_default_bool_toggled.bind(params[prop].property))
368376

369377
TYPE_ARRAY:
370-
editor_node = load("res://addons/dialogic/Editor/Events/Fields/Array.tscn").instantiate()
378+
editor_node = load("res://addons/dialogic/Editor/Events/Fields/field_array.tscn").instantiate()
371379
editor_node.set_value(current_value)
372380
editor_node.property_name = params[prop].property
373381
editor_node.value_changed.connect(_on_event_default_value_changed)
374382

383+
TYPE_DICTIONARY:
384+
editor_node = load("res://addons/dialogic/Editor/Events/Fields/field_dictionary.tscn").instantiate()
385+
editor_node.set_value(current_value)
386+
editor_node.property_name = params[prop].property
387+
editor_node.value_changed.connect(_on_event_default_value_changed)
375388
%EventDefaults.add_child(editor_node)
389+
reset.pressed.connect(reset_event_default_override.bind(prop, editor_node, params[prop].default))
376390

377391

378392
func set_event_default_override(prop:String, value:Variant) -> void:
@@ -387,6 +401,29 @@ func set_event_default_override(prop:String, value:Variant) -> void:
387401
ProjectSettings.set_setting('dialogic/event_default_overrides', event_default_overrides)
388402

389403

404+
func reset_event_default_override(prop:String, node:Node, default:Variant) -> void:
405+
var event_default_overrides: Dictionary = ProjectSettings.get_setting('dialogic/event_default_overrides', {})
406+
var event: DialogicEvent = %Tree.get_selected().get_metadata(0).event
407+
408+
if not event_default_overrides.has(event.event_name):
409+
return
410+
411+
event_default_overrides[event.event_name].erase(prop)
412+
413+
ProjectSettings.set_setting('dialogic/event_default_overrides', event_default_overrides)
414+
415+
if node is CheckBox:
416+
node.button_pressed = default
417+
elif node is LineEdit:
418+
node.text = default
419+
elif node.has_method('set_value'):
420+
node.set_value(default)
421+
elif node is ColorPickerButton:
422+
node.color = default
423+
elif node is OptionButton:
424+
node.select(default)
425+
elif node is SpinBox:
426+
node.value = default
390427

391428

392429
func _on_event_default_string_submitted(text:String, prop:String) -> void:
@@ -398,7 +435,7 @@ func _on_event_default_option_selected(index:int, option_button:OptionButton, pr
398435
func _on_event_default_number_changed(value:float, prop:String) -> void:
399436
set_event_default_override(prop, value)
400437

401-
func _on_event_default_value_changed(prop:String, value:Vector2) -> void:
438+
func _on_event_default_value_changed(prop:String, value:Variant) -> void:
402439
set_event_default_override(prop, value)
403440

404441
func _on_event_default_bool_toggled(value:bool, prop:String) -> void:

addons/dialogic/Editor/Settings/settings_modules.tscn

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[ext_resource type="Script" path="res://addons/dialogic/Editor/Settings/settings_modules.gd" id="1_l2hk0"]
44

5-
[sub_resource type="Image" id="Image_pu0o6"]
5+
[sub_resource type="Image" id="Image_570p8"]
66
data = {
77
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
88
"format": "RGBA8",
@@ -12,9 +12,9 @@ data = {
1212
}
1313

1414
[sub_resource type="ImageTexture" id="ImageTexture_lce2m"]
15-
image = SubResource("Image_pu0o6")
15+
image = SubResource("Image_570p8")
1616

17-
[sub_resource type="Image" id="Image_g84xy"]
17+
[sub_resource type="Image" id="Image_ihhvm"]
1818
data = {
1919
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 131, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 128, 128, 4, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 93, 93, 55, 255, 97, 97, 58, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 97, 97, 42, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 98, 98, 47, 255, 97, 97, 42, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 93, 93, 233, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 94, 94, 46, 255, 93, 93, 236, 255, 93, 93, 233, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 93, 93, 252, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
2020
"format": "RGBA8",
@@ -24,7 +24,7 @@ data = {
2424
}
2525

2626
[sub_resource type="ImageTexture" id="ImageTexture_137g7"]
27-
image = SubResource("Image_g84xy")
27+
image = SubResource("Image_ihhvm")
2828

2929
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_315cl"]
3030
content_margin_left = 4.0
@@ -213,7 +213,7 @@ text = "Edit event defaults:"
213213
[node name="EventDefaults" type="GridContainer" parent="Scroll/Settings/EventDefaultsPanel/VBox"]
214214
unique_name_in_owner = true
215215
layout_mode = 2
216-
columns = 2
216+
columns = 3
217217

218218
[node name="GeneralInfo" type="Label" parent="Scroll/Settings"]
219219
unique_name_in_owner = true

addons/dialogic/Modules/Choice/event_choice.gd

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,15 @@ func to_text() -> String:
6969
if (condition and _has_condition) or shortcode:
7070
result_string += " |"
7171
if condition and _has_condition:
72-
result_string += " [if "+condition+"]"
72+
result_string += " [if " + condition + "]"
73+
74+
if shortcode or extra_data:
75+
result_string += " [" + shortcode
76+
if extra_data:
77+
for i in extra_data:
78+
result_string += ' ' + i + '="' + value_to_string(extra_data[i]) + '"'
79+
result_string += "]"
7380

74-
if shortcode:
75-
result_string += " ["+shortcode+"]"
7681
return result_string
7782

7883

@@ -85,6 +90,10 @@ func from_text(string:String) -> void:
8590
_has_condition = not condition.is_empty()
8691
if result.get_string('shortcode'):
8792
load_from_shortcode_parameters(result.get_string("shortcode"))
93+
var shortcode := parse_shortcode_parameters(result.get_string('shortcode'))
94+
shortcode.erase("else")
95+
shortcode.erase("alt_text")
96+
extra_data = shortcode.duplicate()
8897

8998

9099
func get_shortcode_parameters() -> Dictionary:
@@ -95,7 +104,7 @@ func get_shortcode_parameters() -> Dictionary:
95104
"Hide" :{'value':ElseActions.HIDE,'text_alt':['hide'] },
96105
"Disable" :{'value':ElseActions.DISABLE,'text_alt':['disable']}}},
97106
"alt_text" : {"property": "disabled_text", "default": ""},
98-
"extra_data" : {"property": "extra_data", "default": {}},
107+
"extra_data" : {"property": "extra_data", "default": {}, "custom_stored":true},
99108
}
100109

101110

addons/dialogic/Resources/event.gd

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ func from_text(string: String) -> void:
275275

276276

277277
## Returns a string with all the shortcode parameters.
278-
func store_to_shortcode_parameters() -> String:
279-
var params: Dictionary = get_shortcode_parameters()
278+
func store_to_shortcode_parameters(params:Dictionary = {}) -> String:
279+
if params.is_empty():
280+
params = get_shortcode_parameters()
280281
var custom_defaults: Dictionary = DialogicUtil.get_custom_event_defaults(event_name)
281282
var result_string := ""
282283
for parameter in params.keys():
@@ -294,38 +295,43 @@ func store_to_shortcode_parameters() -> String:
294295
if not "set_" + parameter_info.property in self or not get("set_" + parameter_info.property):
295296
continue
296297

297-
var value_as_string := ""
298-
match typeof(value):
299-
TYPE_OBJECT:
300-
value_as_string = str(value.resource_path)
298+
result_string += " " + parameter + '="' + value_to_string(value, parameter_info.get("suggestions", Callable())) + '"'
301299

302-
TYPE_STRING:
303-
value_as_string = value
300+
return result_string.strip_edges()
304301

305-
TYPE_INT when parameter_info.has('suggestions'):
306-
# HANDLE TEXT ALTERNATIVES FOR ENUMS
307-
for option in parameter_info.suggestions.call().values():
308-
if option.value != value:
309-
continue
310302

311-
if option.has('text_alt'):
312-
value_as_string = option.text_alt[0]
313-
else:
314-
value_as_string = var_to_str(option.value)
303+
func value_to_string(value: Variant, suggestions := Callable()) -> String:
304+
var value_as_string := ""
305+
match typeof(value):
306+
TYPE_OBJECT:
307+
value_as_string = str(value.resource_path)
315308

316-
break
309+
TYPE_STRING:
310+
value_as_string = value
317311

318-
TYPE_DICTIONARY:
319-
value_as_string = JSON.stringify(value)
312+
TYPE_INT when suggestions.is_valid():
313+
# HANDLE TEXT ALTERNATIVES FOR ENUMS
314+
for option in suggestions.call().values():
315+
if option.value != value:
316+
continue
320317

321-
_:
322-
value_as_string = var_to_str(value)
318+
if option.has('text_alt'):
319+
value_as_string = option.text_alt[0]
320+
else:
321+
value_as_string = var_to_str(option.value)
323322

324-
if not ((value_as_string.begins_with("[") and value_as_string.ends_with("]")) or (value_as_string.begins_with("{") and value_as_string.ends_with("}"))):
325-
value_as_string.replace('"', '\\"')
323+
break
326324

327-
result_string += " " + parameter + '="' + value_as_string + '"'
328-
return result_string.strip_edges()
325+
TYPE_DICTIONARY:
326+
value_as_string = JSON.stringify(value)
327+
328+
_:
329+
value_as_string = var_to_str(value)
330+
331+
if not ((value_as_string.begins_with("[") and value_as_string.ends_with("]")) or (value_as_string.begins_with("{") and value_as_string.ends_with("}"))):
332+
value_as_string.replace('"', '\\"')
333+
334+
return value_as_string
329335

330336

331337
func load_from_shortcode_parameters(string:String) -> void:

0 commit comments

Comments
 (0)