Skip to content

Commit 0bf1ed0

Browse files
committed
Validate Variable Names
- fixes #2408 - fixes other issues reported on discord
1 parent e098088 commit 0bf1ed0

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

addons/dialogic/Editor/TimelineEditor/timeline_editor.tscn

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[ext_resource type="PackedScene" uid="uid://defdeav8rli6o" path="res://addons/dialogic/Editor/TimelineEditor/TextEditor/timeline_editor_text.tscn" id="3_up2bn"]
77
[ext_resource type="Script" uid="uid://bb2umikh806og" path="res://addons/dialogic/Editor/TimelineEditor/shortcut_popup.gd" id="6_rfuk0"]
88

9-
[sub_resource type="Image" id="Image_u2118"]
9+
[sub_resource type="Image" id="Image_6bv6r"]
1010
data = {
1111
"data": PackedByteArray(255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 93, 93, 0, 255, 93, 93, 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, 0, 255, 92, 92, 127, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 93, 93, 0, 255, 93, 93, 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, 0, 255, 93, 93, 255, 255, 92, 92, 127, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 93, 93, 0, 255, 93, 93, 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, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 92, 92, 127, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 93, 93, 0, 255, 93, 93, 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, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 92, 92, 127, 255, 92, 92, 0, 255, 92, 92, 0, 255, 93, 93, 0, 255, 93, 93, 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, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 93, 93, 0, 255, 93, 93, 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, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 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, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 231, 255, 90, 90, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 90, 90, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 0, 255, 93, 93, 0, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 42, 255, 90, 90, 0, 255, 94, 94, 0, 255, 91, 91, 42, 255, 93, 93, 233, 255, 92, 92, 232, 255, 93, 93, 41, 255, 90, 90, 0, 255, 94, 94, 0, 255, 91, 91, 42, 255, 93, 93, 233, 255, 92, 92, 232, 255, 92, 92, 0, 255, 92, 92, 0, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 45, 255, 93, 93, 44, 255, 91, 91, 0, 255, 91, 91, 42, 255, 91, 91, 42, 255, 93, 93, 0, 255, 91, 91, 45, 255, 93, 93, 44, 255, 91, 91, 0, 255, 91, 91, 42, 255, 91, 91, 42, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 45, 255, 92, 92, 235, 255, 92, 92, 234, 255, 89, 89, 43, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 45, 255, 92, 92, 235, 255, 92, 92, 234, 255, 89, 89, 43, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 0, 255, 91, 91, 0, 255, 92, 92, 0, 255, 92, 92, 0, 255, 92, 92, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 91, 91, 59, 255, 92, 92, 61, 255, 92, 92, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 91, 91, 59, 255, 92, 92, 61, 255, 92, 92, 0, 255, 92, 92, 0, 255, 93, 93, 0, 255, 93, 93, 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, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 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, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0, 255, 93, 93, 0),
1212
"format": "RGBA8",
@@ -15,10 +15,10 @@ data = {
1515
"width": 16
1616
}
1717

18-
[sub_resource type="ImageTexture" id="ImageTexture_boacm"]
19-
image = SubResource("Image_u2118")
18+
[sub_resource type="ImageTexture" id="ImageTexture_u2118"]
19+
image = SubResource("Image_6bv6r")
2020

21-
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_r3ew6"]
21+
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_boacm"]
2222
content_margin_left = 4.0
2323
content_margin_top = 4.0
2424
content_margin_right = 4.0
@@ -116,15 +116,15 @@ size_flags_horizontal = 10
116116
size_flags_vertical = 4
117117
tooltip_text = "Switch between Text Editor and Visual Editor"
118118
text = "Text editor"
119-
icon = SubResource("ImageTexture_boacm")
119+
icon = SubResource("ImageTexture_u2118")
120120

121121
[node name="Shortcuts" type="Button" parent="VBox/HBox"]
122122
unique_name_in_owner = true
123123
layout_mode = 2
124124
size_flags_horizontal = 8
125125
size_flags_vertical = 4
126126
tooltip_text = "Shortcuts"
127-
icon = SubResource("ImageTexture_boacm")
127+
icon = SubResource("ImageTexture_u2118")
128128

129129
[node name="VisualEditor" parent="VBox" instance=ExtResource("2_qs7vc")]
130130
unique_name_in_owner = true
@@ -144,7 +144,7 @@ size_flags_vertical = 3
144144
unique_name_in_owner = true
145145
visible = false
146146
layout_mode = 2
147-
theme_override_styles/panel = SubResource("StyleBoxFlat_r3ew6")
147+
theme_override_styles/panel = SubResource("StyleBoxFlat_boacm")
148148

149149
[node name="VBox" type="VBoxContainer" parent="VBox/SearchReplaceSection"]
150150
layout_mode = 2
@@ -167,13 +167,13 @@ layout_mode = 2
167167
[node name="SearchUp" type="Button" parent="VBox/SearchReplaceSection/VBox/SearchSection"]
168168
unique_name_in_owner = true
169169
layout_mode = 2
170-
icon = SubResource("ImageTexture_boacm")
170+
icon = SubResource("ImageTexture_u2118")
171171
flat = true
172172

173173
[node name="SearchDown" type="Button" parent="VBox/SearchReplaceSection/VBox/SearchSection"]
174174
unique_name_in_owner = true
175175
layout_mode = 2
176-
icon = SubResource("ImageTexture_boacm")
176+
icon = SubResource("ImageTexture_u2118")
177177
flat = true
178178

179179
[node name="MatchCase" type="CheckBox" parent="VBox/SearchReplaceSection/VBox/SearchSection"]
@@ -189,7 +189,7 @@ text = "Whole Words"
189189
[node name="SearchClose" type="Button" parent="VBox/SearchReplaceSection/VBox/SearchSection"]
190190
unique_name_in_owner = true
191191
layout_mode = 2
192-
icon = SubResource("ImageTexture_boacm")
192+
icon = SubResource("ImageTexture_u2118")
193193
flat = true
194194

195195
[node name="ReplaceSection" type="HBoxContainer" parent="VBox/SearchReplaceSection/VBox"]
@@ -216,7 +216,7 @@ text = "Replace All"
216216
unique_name_in_owner = true
217217
layout_mode = 2
218218
tooltip_text = "Replace in all timelines"
219-
icon = SubResource("ImageTexture_boacm")
219+
icon = SubResource("ImageTexture_u2118")
220220

221221
[node name="ProgressSection" type="HBoxContainer" parent="VBox"]
222222
unique_name_in_owner = true
@@ -242,7 +242,7 @@ anchor_right = 1.0
242242
anchor_bottom = 1.0
243243
grow_horizontal = 2
244244
grow_vertical = 2
245-
theme_override_styles/panel = SubResource("StyleBoxFlat_r3ew6")
245+
theme_override_styles/panel = SubResource("StyleBoxFlat_boacm")
246246

247247
[node name="CenterContainer" type="CenterContainer" parent="NoTimelineScreen"]
248248
layout_mode = 2
@@ -289,7 +289,7 @@ text = "Shortcuts "
289289
[node name="CloseShortcutPanel" type="Button" parent="ShortcutsPanel/VBoxContainer/HBoxContainer"]
290290
unique_name_in_owner = true
291291
layout_mode = 2
292-
icon = SubResource("ImageTexture_boacm")
292+
icon = SubResource("ImageTexture_u2118")
293293
flat = true
294294

295295
[node name="ScrollContainer" type="ScrollContainer" parent="ShortcutsPanel/VBoxContainer"]

addons/dialogic/Modules/Variable/variables_editor/variable_tree.gd

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ enum TreeButtons {ADD_FOLDER, ADD_VARIABLE, DUPLICATE_FOLDER, DELETE, CHANGE_TYP
55

66
@onready var editor: DialogicEditor = find_parent("VariablesEditor")
77

8+
var validation_regex := RegEx.create_from_string(r"[^\w]")
89

910
#region INITIAL SETUP
1011

@@ -160,18 +161,50 @@ func _on_item_edited() -> void:
160161
0:
161162
if item.get_text(0).is_empty():
162163
item.set_text(0, item.get_metadata(0))
163-
164164
else:
165+
validate_name(item)
165166
if item.get_text(0) != item.get_metadata(0):
166167
item.set_metadata(0, item.get_text(0))
167168
report_name_changes(item)
168169

169170
2:
170171
item.set_metadata(2, get_variable_item_default(item))
171172
"FOLDER":
173+
validate_name(item)
172174
report_name_changes(item)
173175

174176

177+
func validate_name(item:TreeItem) -> void:
178+
var item_name := item.get_text(0)
179+
if not item_name.is_valid_identifier():
180+
item_name = validation_regex.sub(item_name, "_", true)
181+
if not item_name.is_valid_identifier():
182+
item_name = "_"+item_name
183+
184+
var sibling_names := []
185+
186+
for i in item.get_parent().get_children():
187+
if i == item:
188+
continue
189+
sibling_names.append(i.get_text(0))
190+
191+
if item_name in sibling_names:
192+
var number_regex := RegEx.create_from_string(r"(?<=\w)\d+$")
193+
var res := number_regex.search(item_name)
194+
var x := 2
195+
if res:
196+
var number := res.get_string()
197+
x = int(number)
198+
item_name = item_name.trim_suffix(number)
199+
200+
while item_name + str(x) in sibling_names:
201+
x += 1
202+
203+
item_name = item_name + str(x)
204+
205+
item.set_text(0, item_name)
206+
207+
175208
func adjust_variable_type(item:TreeItem, type:int, prev_value:Variant) -> void:
176209
set_variable_item_type(item, type)
177210
match type:

0 commit comments

Comments
 (0)