Browse Source

update dialogic

Arnaud Vergnet 3 years ago
parent
commit
2fc0420194

+ 19
- 23
addons/dialogic/Editor/DefinitionEditor/DefinitionEditor.gd View File

@@ -3,7 +3,7 @@ extends ScrollContainer
3 3
 
4 4
 var editor_reference
5 5
 onready var master_tree = get_node('../MasterTree')
6
-var current_section = ''
6
+var current_definition = null
7 7
 
8 8
 onready var nodes = {
9 9
 	'name' : $VBoxContainer/HBoxContainer/VBoxContainer/Name,
@@ -22,19 +22,19 @@ func _ready():
22 22
 	nodes['type'].connect('item_selected', self, '_on_type_selected')
23 23
 
24 24
 
25
-func load_definition(section):
26
-	current_section = section
25
+func load_definition(id):
26
+	current_definition = DialogicResources.get_default_definition_item(id)
27 27
 	reset_editor()
28 28
 	nodes['name'].editable = true
29
-	nodes['name'].text = get_definition('name', 'Unnamed')
30
-	var type = get_definition('type', 0)
29
+	nodes['name'].text = current_definition['name']
30
+	var type = current_definition['type']
31 31
 	nodes['type'].select(type)
32 32
 	if type == 0:
33
-		nodes['value'].text = get_definition('value', '')
33
+		nodes['value'].text = current_definition['value']
34 34
 	if type == 1:
35
-		nodes['extra_title'].text = get_definition('extra_title', '')
36
-		nodes['extra_text'].text = get_definition('extra_text', '')
37
-		nodes['extra_extra'].text = get_definition('extra_extra', '')
35
+		nodes['extra_title'].text = current_definition['title']
36
+		nodes['extra_text'].text = current_definition['text']
37
+		nodes['extra_extra'].text = current_definition['extra']
38 38
 	show_sub_editor(type)
39 39
 
40 40
 
@@ -44,7 +44,10 @@ func reset_editor():
44 44
 	nodes['extra_title'].text = ''
45 45
 	nodes['extra_text'].text = ''
46 46
 	nodes['extra_extra'].text = ''
47
-	nodes['type'].select(get_definition('type', 0))
47
+	var type = 0
48
+	if current_definition != null:
49
+		type = current_definition['type']
50
+	nodes['type'].select(type)
48 51
 
49 52
 
50 53
 func _on_name_changed(text):
@@ -70,23 +73,16 @@ func show_sub_editor(type):
70 73
 		nodes['extra_editor'].visible = true
71 74
 
72 75
 
73
-func get_definition(key: String, default):
74
-	if current_section != '':
75
-		return DialogicResources.get_default_definition_key(current_section, key, default)
76
-	else:
77
-		return default
78
-
79
-
80 76
 func new_definition():
81
-	var section = DialogicUtil.generate_random_id()
82
-	DialogicResources.add_default_definition_variable(section, 'New definition', 0, '')
83
-	master_tree.add_definition({'section': section,'name': 'New definition', 'type': 0}, true)
77
+	var id = DialogicUtil.generate_random_id()
78
+	DialogicResources.set_default_definition_variable(id, 'New definition', '')
79
+	master_tree.add_definition({'id': id, 'name': 'New definition', 'type': 0}, true)
84 80
 
85 81
 
86 82
 func save_definition():
87
-	if current_section != '':
83
+	if current_definition['id'] != '':
88 84
 		var type: int = nodes['type'].selected
89 85
 		if type == 0:
90
-			DialogicResources.set_default_definition_variable(current_section, nodes['name'].text, nodes['value'].text)
86
+			DialogicResources.set_default_definition_variable(current_definition['id'], nodes['name'].text, nodes['value'].text)
91 87
 		if type == 1:
92
-			DialogicResources.set_default_definition_glossary(current_section, nodes['name'].text, nodes['extra_title'].text, nodes['extra_text'].text, nodes['extra_extra'].text)
88
+			DialogicResources.set_default_definition_glossary(current_definition['id'], nodes['name'].text, nodes['extra_title'].text, nodes['extra_text'].text, nodes['extra_extra'].text)

+ 4
- 4
addons/dialogic/Editor/EditorView.gd View File

@@ -67,9 +67,9 @@ func _on_TimelinePopupMenu_id_pressed(id):
67 67
 
68 68
 func _on_RemoveTimelineConfirmation_confirmed():
69 69
 	var dir = Directory.new()
70
-	var target = $MainPanel/TimelineEditor.working_timeline_file
70
+	var target = $MainPanel/TimelineEditor.timeline_file
71 71
 	print('target: ', target)
72
-	dir.remove(target)
72
+	DialogicResources.delete_timeline(target)
73 73
 	$MainPanel/MasterTree.remove_selected()
74 74
 	$MainPanel/MasterTree.hide_all_editors(true)
75 75
 
@@ -99,7 +99,7 @@ func _on_DefinitionPopupMenu_id_pressed(id):
99 99
 
100 100
 
101 101
 func _on_RemoveDefinitionConfirmation_confirmed():
102
-	var target = $MainPanel/DefinitionEditor.current_section
102
+	var target = $MainPanel/DefinitionEditor.current_definition['id']
103 103
 	DialogicResources.delete_default_definition(target)
104 104
 	$MainPanel/MasterTree.remove_selected()
105 105
 	$MainPanel/MasterTree.hide_all_editors(true)
@@ -114,7 +114,7 @@ func _on_RemoveCharacterConfirmation_confirmed():
114 114
 
115 115
 func _on_RemoveThemeConfirmation_confirmed():
116 116
 	var filename = $MainPanel/MasterTree.get_selected().get_metadata(0)['file']
117
-	DialogicResources.delete_timeline(filename)
117
+	DialogicResources.delete_theme(filename)
118 118
 	$MainPanel/MasterTree.remove_selected()
119 119
 	$MainPanel/MasterTree.hide_all_editors(true)
120 120
 

+ 2
- 2
addons/dialogic/Editor/MasterTree/MasterTree.gd View File

@@ -69,7 +69,7 @@ func _ready():
69 69
 		add_character(c)
70 70
 	
71 71
 	# Adding Definitions
72
-	for d in DialogicUtil.get_default_definition_list():
72
+	for d in DialogicUtil.get_default_definitions_list():
73 73
 		add_definition(d)
74 74
 	
75 75
 	# Adding Themes
@@ -155,7 +155,7 @@ func _on_item_selected():
155 155
 		character_editor.load_character(metadata['file'])
156 156
 	if metadata['editor'] == 'Definition':
157 157
 		definition_editor.visible = true
158
-		definition_editor.load_definition(metadata['section'])
158
+		definition_editor.load_definition(metadata['id'])
159 159
 	if metadata['editor'] == 'Theme':
160 160
 		theme_editor.load_theme(metadata['file'])
161 161
 		theme_editor.visible = true

+ 10
- 11
addons/dialogic/Editor/Pieces/Common/DefinitionPicker.gd View File

@@ -12,13 +12,12 @@ func _ready():
12 12
 func _on_MenuButton_about_to_show():
13 13
 	get_popup().clear()
14 14
 	var index = 0
15
-	for d in DialogicUtil.get_default_definition_list():
16
-		if d['type'] == 0:
17
-			get_popup().add_item(d['name'])
18
-			get_popup().set_item_metadata(index, {
19
-				'section': d['section'],
20
-			})
21
-			index += 1
15
+	for d in DialogicResources.get_default_definitions()['variables']:
16
+		get_popup().add_item(d['name'])
17
+		get_popup().set_item_metadata(index, {
18
+			'id': d['id'],
19
+		})
20
+		index += 1
22 21
 
23 22
 
24 23
 func _on_entry_selected(index):
@@ -27,10 +26,10 @@ func _on_entry_selected(index):
27 26
 	text = _text
28 27
 
29 28
 
30
-func load_definition(section):
31
-	if section != '':
32
-		for d in DialogicUtil.get_default_definition_list():
33
-			if d['section'] == section:
29
+func load_definition(id):
30
+	if id != '':
31
+		for d in DialogicResources.get_default_definitions()['variables']:
32
+			if d['id'] == id:
34 33
 				text = d['name']
35 34
 	else:
36 35
 		text = default_text

+ 1
- 1
addons/dialogic/Editor/Pieces/IfCondition.gd View File

@@ -36,7 +36,7 @@ func load_data(data):
36 36
 
37 37
 func _on_definition_entry_selected(index):
38 38
 	var metadata = nodes['definition_picker'].get_popup().get_item_metadata(index)
39
-	event_data['definition'] = metadata['section']
39
+	event_data['definition'] = metadata['id']
40 40
 
41 41
 
42 42
 func _on_condition_entry_selected(index):

+ 1
- 1
addons/dialogic/Editor/Pieces/SetValue.gd View File

@@ -21,7 +21,7 @@ func _ready():
21 21
 
22 22
 func _on_definition_entry_selected(index):
23 23
 	var metadata = nodes['definition_picker'].get_popup().get_item_metadata(index)
24
-	event_data['definition'] = metadata['section']
24
+	event_data['definition'] = metadata['id']
25 25
 
26 26
 
27 27
 func load_data(data):

+ 1
- 1
addons/dialogic/Editor/ThemeEditor/ThemeEditor.gd View File

@@ -323,4 +323,4 @@ func _on_Alignment_item_selected(index):
323 323
 
324 324
 
325 325
 func _on_Preview_text_changed():
326
-	DialogicUtil.set_theme_value(current_theme, 'text', 'preview', n['text_preview'].text)
326
+	DialogicResources.set_theme_value(current_theme, 'text', 'preview', n['text_preview'].text)

+ 64
- 44
addons/dialogic/Nodes/dialog_node.gd View File

@@ -10,15 +10,20 @@ var waiting_for_answer: bool = false
10 10
 var waiting_for_input: bool = false
11 11
 var waiting = false
12 12
 var preview = false
13
-var definitions
13
+var definitions = {}
14 14
 var definition_visible = false
15 15
 
16 16
 var settings
17 17
 var current_theme
18
+var current_timeline := ''
18 19
 
20
+## The timeline to load when starting the scene
19 21
 export(String, "TimelineDropdown") var timeline: String
22
+## Should we clear saved data (definitions and timeline progress) on start?
20 23
 export(bool) var reset_saves = true
24
+## Should we show debug information when running?
21 25
 export(bool) var debug_mode = true
26
+
22 27
 signal event_start(type, event)
23 28
 signal event_end(type)
24 29
 signal dialogic_signal(value)
@@ -35,13 +40,15 @@ func _ready():
35 40
 	# Loading the config files
36 41
 	load_config_files()
37 42
 	
38
-	# Make sure saves are ready
39
-	DialogicResources.init_definitions_saves(reset_saves)
40
-	
41 43
 	# Checking if the dialog should read the code from a external file
42
-	if timeline != '':
43
-		dialog_script = set_current_dialog(timeline + '.json')
44
-
44
+	if not timeline.empty():
45
+		dialog_script = set_current_dialog(timeline)
46
+	elif dialog_script.keys().size() == 0:
47
+		dialog_script = {
48
+			"events":[{"character":"","portrait":"",
49
+			"text":"[Dialogic Error] No timeline specified."}]
50
+		}
51
+	
45 52
 	# Connecting resize signal
46 53
 	get_viewport().connect("size_changed", self, "resize_main")
47 54
 	resize_main()
@@ -55,12 +62,17 @@ func _ready():
55 62
 	# Getting the character information
56 63
 	characters = DialogicUtil.get_character_list()
57 64
 
58
-	if Engine.is_editor_hint() == false:
65
+	if not Engine.is_editor_hint():
59 66
 		load_dialog()
60 67
 
61 68
 
62 69
 func load_config_files():
63
-	definitions = DialogicUtil.get_definition_list()
70
+	if not Engine.is_editor_hint():
71
+		# Make sure saves are ready
72
+		DialogicSingleton.init(reset_saves)
73
+		definitions = DialogicSingleton.get_definitions()
74
+	else:
75
+		definitions = DialogicResources.get_default_definitions()
64 76
 	settings = DialogicResources.get_settings_config()
65 77
 	var theme_file = 'res://addons/dialogic/Editor/ThemeEditor/default-theme.cfg'
66 78
 	if settings.has_section('theme'):
@@ -80,7 +92,8 @@ func resize_main():
80 92
 	$TextBubble.rect_position.y = (rect_size.y) - ($TextBubble.rect_size.y) - current_theme.get_value('box', 'bottom_gap', 40)
81 93
 
82 94
 
83
-func set_current_dialog(dialog_path):
95
+func set_current_dialog(dialog_path: String):
96
+	current_timeline = dialog_path
84 97
 	var dialog_script = DialogicResources.get_timeline_json(dialog_path)
85 98
 	# All this parse events should be happening in the same loop ideally
86 99
 	# But until performance is not an issue I will probably stay lazy
@@ -217,7 +230,6 @@ func parse_branches(dialog_script: Dictionary) -> Dictionary:
217 230
 
218 231
 func parse_definitions(text: String):
219 232
 	var words = []
220
-	var definition_list = DialogicUtil.get_definition_list()
221 233
 	if Engine.is_editor_hint():
222 234
 		# Loading variables again to avoid issues in the preview dialog
223 235
 		load_config_files()
@@ -229,11 +241,9 @@ func parse_definitions(text: String):
229 241
 
230 242
 func _insert_variable_definitions(text: String):
231 243
 	var final_text := text;
232
-	for d in definitions:
233
-		if d['type'] == 0:
234
-			var name : String = d['name'];
235
-			var value = DialogicUtil.get_var(name)
236
-			final_text = final_text.replace('[' + name + ']', value)
244
+	for d in definitions['variables']:
245
+		var name : String = d['name'];
246
+		final_text = final_text.replace('[' + name + ']', d['value'])
237 247
 	return final_text;
238 248
 	
239 249
 	
@@ -241,13 +251,12 @@ func _insert_glossary_definitions(text: String):
241 251
 	var color = self.current_theme.get_value('definitions', 'color', '#ffbebebe')
242 252
 	var final_text := text;
243 253
 	# I should use regex here, but this is way easier :)
244
-	for d in definitions:
245
-		if d['type'] == 1:
246
-			final_text = final_text.replace(d['name'],
247
-				'[url=' + d['section'] + ']' +
248
-				'[color=' + color + ']' + d['name'] + '[/color]' +
249
-				'[/url]'
250
-			)
254
+	for d in definitions['glossary']:
255
+		final_text = final_text.replace(d['name'],
256
+			'[url=' + d['id'] + ']' +
257
+			'[color=' + color + ']' + d['name'] + '[/color]' +
258
+			'[/url]'
259
+		)
251 260
 	return final_text;
252 261
 
253 262
 
@@ -309,13 +318,26 @@ func update_text(text):
309 318
 	return true
310 319
 
311 320
 
321
+func on_timeline_start():
322
+	if not Engine.is_editor_hint():
323
+		DialogicSingleton.save_definitions()
324
+		DialogicSingleton.set_current_timeline(current_timeline)
325
+	emit_signal("event_start", "timeline", current_timeline)
326
+
327
+
328
+func on_timeline_end():
329
+	if not Engine.is_editor_hint():
330
+		DialogicSingleton.save_definitions()
331
+		DialogicSingleton.set_current_timeline('')
332
+	emit_signal("event_end", "timeline")
333
+
312 334
 func load_dialog(skip_add = false):
313 335
 	# Emitting signals
314 336
 	if dialog_script.has('events'):
315 337
 		if dialog_index == 0:
316
-			emit_signal("event_start", "timeline", timeline)
338
+			on_timeline_start()
317 339
 		elif dialog_index == dialog_script['events'].size():
318
-			emit_signal("event_end", "timeline")
340
+			on_timeline_end()
319 341
 
320 342
 	# Hiding definitions popup
321 343
 	definition_visible = false
@@ -346,8 +368,6 @@ func get_character(character_id):
346 368
 func event_handler(event: Dictionary):
347 369
 	# Handling an event and updating the available nodes accordingly.
348 370
 	reset_dialog_extras()
349
-	# Updating the settings and definitions in case that they were modified by a timelien
350
-	load_config_files()
351 371
 	
352 372
 	dprint('[D] Current Event: ', event)
353 373
 	match event:
@@ -440,6 +460,7 @@ func event_handler(event: Dictionary):
440 460
 			go_to_next_event()
441 461
 		{'close_dialog'}:
442 462
 			emit_signal("event_start", "close_dialog", event)
463
+			on_timeline_end()
443 464
 			queue_free()
444 465
 		{'set_theme'}:
445 466
 			emit_signal("event_start", "set_theme", event)
@@ -458,11 +479,12 @@ func event_handler(event: Dictionary):
458 479
 			# Treating this conditional as an option on a regular question event
459 480
 			var def_value = null
460 481
 			var current_question = questions[event['question_id']]
461
-			for d in definitions:
462
-				if d['section'] == event['definition']:
463
-					def_value = DialogicUtil.get_var(d['name'])
464 482
 			
465
-			var condition_met = self._compare_definitions(def_value, event['value'], event['condition']);
483
+			for d in definitions['variables']:
484
+				if d['id'] == event['definition']:
485
+					def_value = d['value']
486
+			
487
+			var condition_met = def_value != null and _compare_definitions(def_value, event['value'], event['condition']);
466 488
 			
467 489
 			current_question['answered'] = !condition_met
468 490
 			if !condition_met:
@@ -474,7 +496,7 @@ func event_handler(event: Dictionary):
474 496
 				go_to_next_event()
475 497
 		{'set_value', 'definition'}:
476 498
 			emit_signal("event_start", "set_value", event)
477
-			DialogicResources.set_saved_definition_variable_value(event['definition'], event['set_value'])
499
+			DialogicSingleton.set_variable_from_id(event['definition'], event['set_value'])
478 500
 			go_to_next_event()
479 501
 		_:
480 502
 			visible = false
@@ -570,7 +592,6 @@ func _on_option_selected(option, variable, value):
570 592
 	waiting_for_answer = false
571 593
 	reset_options()
572 594
 	load_dialog()
573
-	#print(dialog_resource.custom_variables)
574 595
 	dprint('[!] Option selected: ', option.text, ' value= ' , value)
575 596
 
576 597
 
@@ -684,17 +705,16 @@ func load_theme(filename):
684 705
 
685 706
 func _on_RichTextLabel_meta_hover_started(meta):
686 707
 	var correct_type = false
687
-	for d in definitions:
688
-		if d['section'] == meta:
689
-			if d['type'] == 1:
690
-				$DefinitionInfo.load_preview({
691
-					'title': d['config'].get_value(d['section'], 'extra_title', ''),
692
-					'body': d['config'].get_value(d['section'], 'extra_text', ''),
693
-					'extra': d['config'].get_value(d['section'], 'extra_extra', ''),
694
-					'color': current_theme.get_value('definitions', 'color', '#ffbebebe'),
695
-				})
696
-				correct_type = true
697
-				print(d)
708
+	for d in definitions['glossary']:
709
+		if d['id'] == meta:
710
+			$DefinitionInfo.load_preview({
711
+				'title': d['title'],
712
+				'body': d['text'],
713
+				'extra': d['extra'],
714
+				'color': current_theme.get_value('definitions', 'color', '#ffbebebe'),
715
+			})
716
+			correct_type = true
717
+			print(d)
698 718
 
699 719
 	if correct_type:
700 720
 		definition_visible = true

+ 124
- 16
addons/dialogic/Other/DialogicClass.gd View File

@@ -1,29 +1,137 @@
1 1
 extends Node
2
+
3
+## Exposed and safe to use methods for Dialogic
4
+## See documentation here:
5
+## https://github.com/coppolaemilio/dialogic
6
+
7
+## ### /!\ ###
8
+## Do not use methods from other classes as it could break the plugin's integrity
9
+## ### /!\ ###
10
+##
11
+## Trying to follow this documentation convention: https://github.com/godotengine/godot/pull/41095
2 12
 class_name Dialogic
3 13
 
4 14
 
5
-static func start(timeline: String, dialog_scene_path: String="res://addons/dialogic/Dialog.tscn", debug_mode: bool=false):
6
-	var dialog = load(dialog_scene_path)
15
+## Starts the dialog for the given timeline and returns a Dialog node.
16
+## You must then add it manually to the scene to display the dialog.
17
+##
18
+## Example:
19
+## var new_dialog = Dialogic.start('Your Timeline Name Here')
20
+## add_child(new_dialog)
21
+##
22
+## This is exactly the same as using the editor:
23
+## you can drag and drop the scene located at /addons/dialogic/Dialog.tscn 
24
+## and set the current timeline via the inspector.
25
+##
26
+## @param timeline				The timeline to load. You can provide the timeline name or the filename.
27
+## @param reset_saves			True to reset dialogic saved data such as definitions.
28
+## @param dialog_scene_path		If you made a custom Dialog scene or moved it from its default path, you can specify its new path here.
29
+## @param debug_mode			Debug is disabled by default but can be enabled if needed.
30
+## @returns						A Dialog node to be added into the scene tree.
31
+static func start(timeline: String, reset_saves: bool=true, dialog_scene_path: String="res://addons/dialogic/Dialog.tscn", debug_mode: bool=false):
32
+
33
+	var dialog:  = load(dialog_scene_path)
7 34
 	var d = dialog.instance()
35
+	d.reset_saves = reset_saves
8 36
 	d.debug_mode = debug_mode
9
-	for t in DialogicUtil.get_timeline_list():
10
-		if t['name'] == timeline:
11
-			d.timeline = t['file'].replace('.json', '')
12
-			return d
13
-	d.dialog_script = {
14
-		"events":[{"character":"","portrait":"",
15
-		"text":"[Dialogic Error] Loading dialog [color=red]" + timeline + "[/color]. It seems like the timeline doesn't exists. Maybe the name is wrong?"}]
16
-	}
37
+	if not timeline.empty():
38
+		for t in DialogicUtil.get_timeline_list():
39
+			if t['name'] == timeline or t['file'] == timeline:
40
+				d.timeline = t['file']
41
+				return d
42
+		d.dialog_script = {
43
+			"events":[{"character":"","portrait":"",
44
+			"text":"[Dialogic Error] Loading dialog [color=red]" + timeline + "[/color]. It seems like the timeline doesn't exists. Maybe the name is wrong?"}]
45
+		}
17 46
 	return d
18 47
 
19 48
 
20
-static func reset_saves():
21
-	DialogicResources.init_definitions_saves(true)
49
+## Same as the start method above, but using the last timeline saved.
50
+## 
51
+## @param initial_timeline		The timeline to load in case no save is found.
52
+## @param dialog_scene_path		If you made a custom Dialog scene or moved it from its default path, you can specify its new path here.
53
+## @param debug_mode			Debug is disabled by default but can be enabled if needed.
54
+## @returns						A Dialog node to be added into the scene tree.
55
+static func start_from_save(initial_timeline: String, dialog_scene_path: String="res://addons/dialogic/Dialog.tscn", debug_mode: bool=false):
56
+	var current := get_current_timeline()
57
+	if current.empty():
58
+		current = initial_timeline
59
+	return start(current, false, dialog_scene_path, debug_mode)
60
+
61
+## Gets default values for definitions.
62
+## 
63
+## @returns						Dictionary in the format {'variables': [], 'glossary': []}
64
+static func get_default_definitions() -> Dictionary:
65
+	return DialogicSingleton.get_default_definitions()
66
+
67
+
68
+## Gets currently saved values for definitions.
69
+## 
70
+## @returns						Dictionary in the format {'variables': [], 'glossary': []}
71
+static func get_definitions() -> Dictionary:
72
+	return DialogicSingleton.get_definitions()
73
+
74
+
75
+## Save current definitions to the filesystem.
76
+## Definitions are automatically saved on timeline start/end
77
+## 
78
+## @returns						Error status, OK if all went well
79
+func save_definitions():
80
+	return DialogicSingleton.save_definitions()
81
+
82
+
83
+## Resets data to default values. This is the same as calling start with reset_saves to true
84
+func reset_saves():
85
+	DialogicSingleton.init(true)
86
+
87
+
88
+## Gets the value for the variable with the given name.
89
+## The returned value is a String but can be easily converted into a number 
90
+## using Godot built-in methods: 
91
+## [`is_valid_float`](https://docs.godotengine.org/en/stable/classes/class_string.html#class-string-method-is-valid-float)
92
+## [`float()`](https://docs.godotengine.org/en/stable/classes/class_float.html#class-float-method-float).
93
+##
94
+## @param name					The name of the variable to find.
95
+## @returns						The variable's value as string, or an empty string if not found.
96
+static func get_variable(name: String) -> String:
97
+	return DialogicSingleton.get_variable(name)
98
+
99
+
100
+## Sets the value for the variable with the given name.
101
+## The given value will be converted to string using the 
102
+## [`str()`](https://docs.godotengine.org/en/stable/classes/class_string.html) function.
103
+##
104
+## @param name					The name of the variable to edit.
105
+## @param value					The value of the variable to set.
106
+static func set_variable(name: String, value) -> void:
107
+	DialogicSingleton.set_variable(name, value)
108
+
109
+
110
+## Gets the glossary data for the definition with the given name.
111
+## Returned format:
112
+## { title': '', 'text' : '', 'extra': '' }
113
+##
114
+## @param name					The name of the glossary to find.
115
+## @returns						The glossary data as a Dictionary.
116
+## 								A structure with empty strings is returned if the glossary was not found. 
117
+static func get_glossary(name: String) -> Dictionary:
118
+	return DialogicSingleton.get_glossary(name)
22 119
 
23 120
 
24
-static func get_var(variable: String):
25
-	return DialogicUtil.get_var(variable)
121
+## Sets the data for the glossary of the given name.
122
+## 
123
+## @param name					The name of the glossary to edit.
124
+## @param title					The title to show in the information box.
125
+## @param text					The text to show in the information box.
126
+## @param extra					The extra information at the bottom of the box.
127
+static func set_glossary(name: String, title: String, text: String, extra: String) -> void:
128
+	DialogicSingleton.set_glossary(name, title, text, extra)
26 129
 
27 130
 
28
-static func set_var(variable: String, value):
29
-	DialogicUtil.set_var(variable, value)
131
+## Gets the currently saved timeline.
132
+## Timeline saves are set on timeline start, and cleared on end.
133
+## This means you can keep track of timeline changes and detect when the dialog ends.
134
+##
135
+## @returns						The current timeline filename, or an empty string if none was saved.
136
+static func get_current_timeline() -> String:
137
+	return DialogicSingleton.get_current_timeline()

+ 71
- 0
addons/dialogic/Other/DialogicDefinitionsUtil.gd View File

@@ -0,0 +1,71 @@
1
+extends Node
2
+class_name DialogicDefinitionsUtil
3
+
4
+
5
+static func get_definition_by_key(data: Dictionary, key: String, value: String):
6
+	var variables : Array = data['variables']
7
+	var glossary : Array = data['glossary']
8
+	for v in variables:
9
+		if v[key] == value:
10
+			return v
11
+	for g in glossary:
12
+		if g[key] == value:
13
+			return g
14
+	return null
15
+
16
+
17
+static func get_definition_by_id(data: Dictionary, id: String):
18
+	return get_definition_by_key(data, 'id', id)
19
+
20
+
21
+static func get_definition_by_name(data: Dictionary, id: String):
22
+	return get_definition_by_key(data, 'name', id)
23
+
24
+
25
+static func set_definition(section: String, data: Dictionary, elem: Dictionary):
26
+	delete_definition(data, elem['id'])
27
+	var array: Array = data[section]
28
+	var found = false;
29
+	for e in array:
30
+		if e['id'] == elem['id']:
31
+			found = true
32
+			array.erase(e)
33
+			array.append(elem)
34
+			break
35
+	if not found:
36
+		array.append(elem)
37
+
38
+
39
+static func set_definition_variable(data: Dictionary, id: String, name: String, value):
40
+	set_definition('variables', data, {
41
+		'id': id,
42
+		'name': name,
43
+		'value': value,
44
+		'type': 0
45
+	})
46
+
47
+
48
+static func set_definition_glossary(data: Dictionary, id: String, name: String,  title: String,  text: String,  extra: String):
49
+	set_definition('glossary', data, {
50
+		'id': id,
51
+		'name': name,
52
+		'title': title,
53
+		'text': text,
54
+		'extra': extra,
55
+		'type': 1
56
+	})
57
+
58
+
59
+static func delete_definition(data: Dictionary, id: String):
60
+	var variables : Array = data['variables']
61
+	var glossary : Array = data['glossary']
62
+	var item = get_definition_by_id(data, id);
63
+	if item != null:
64
+		if (item['type'] == 0):
65
+			variables.erase(item)
66
+		else:
67
+			glossary.erase(item)
68
+
69
+
70
+static func definitions_json_to_array(data: Dictionary) -> Array:
71
+	return data['variables'] + data['glossary']

+ 114
- 109
addons/dialogic/Other/DialogicResources.gd View File

@@ -6,24 +6,26 @@ const RESOURCES_DIR: String = "res://dialogic" # Readonly, used for static data
6 6
 const WORKING_DIR: String = "user://dialogic" # Readwrite, used for saves
7 7
 
8 8
 
9
-static func load_json(path: String) -> Dictionary:
9
+static func load_json(path: String, default: Dictionary={}) -> Dictionary:
10 10
 	# An easy function to load json files and handle common errors.
11
-	var file:File = File.new()
11
+	var file := File.new()
12 12
 	if file.open(path, File.READ) != OK:
13 13
 		file.close()
14
-		return {'error':'file read error'}
14
+		return default
15 15
 	var data_text: String = file.get_as_text()
16 16
 	file.close()
17
-	var data_parse:JSONParseResult = JSON.parse(data_text)
17
+	if data_text.empty():
18
+		return default
19
+	var data_parse: JSONParseResult = JSON.parse(data_text)
18 20
 	if data_parse.error != OK:
19
-		return {'error':'data parse error'}
21
+		return default
20 22
 
21 23
 	var final_data = data_parse.result
22 24
 	if typeof(final_data) == TYPE_DICTIONARY:
23 25
 		return final_data
24 26
 	
25 27
 	# If everything else fails
26
-	return {'error':'data parse error'}
28
+	return default
27 29
 
28 30
 
29 31
 static func init_dialogic_files() -> void:
@@ -57,43 +59,68 @@ static func get_working_directories() -> Dictionary:
57 59
 static func get_config_files_paths() -> Dictionary:
58 60
 	return {
59 61
 		'SETTINGS_FILE': RESOURCES_DIR + "/settings.cfg",
60
-		'DEFAULT_DEFINITIONS_FILE': RESOURCES_DIR + "/definitions.cfg",
61
-		'SAVED_DEFINITIONS_FILE': WORKING_DIR + "/definitions.cfg",
62
+		'DEFAULT_DEFINITIONS_FILE': RESOURCES_DIR + "/definitions.json",
63
+		'SAVED_DEFINITIONS_FILE': WORKING_DIR + "/definitions.json",
64
+		'SAVED_STATE_FILE': WORKING_DIR + "/state.json",
62 65
 	}
63 66
 
64 67
 
68
+static func init_saves(overwrite: bool=true):
69
+	var err = init_working_dir()
70
+	var paths := get_config_files_paths()
71
+	
72
+	if err == OK:
73
+		init_state_saves(overwrite)
74
+		init_definitions_saves(overwrite)
75
+	else:
76
+		print('Error creating working directory: ' + str(err))
77
+
78
+
79
+static func init_working_dir():
80
+	var directory := Directory.new()
81
+	return directory.make_dir_recursive(get_working_directories()['WORKING_DIR'])
82
+
83
+
84
+static func init_state_saves(overwrite: bool=true):
85
+	var file := File.new()
86
+	var paths := get_config_files_paths()
87
+	
88
+	if not file.file_exists(paths["SAVED_STATE_FILE"]) or overwrite:
89
+		var err = file.open(paths["SAVED_STATE_FILE"], File.WRITE)
90
+		if err == OK:
91
+			file.store_string('')
92
+			file.close()
93
+		else:
94
+			print('Error opening saved state file: ' + str(err))
95
+
96
+
65 97
 static func init_definitions_saves(overwrite: bool=true):
66 98
 	var directory := Directory.new()
67 99
 	var source := File.new()
68 100
 	var sink := File.new()
69 101
 	var paths := get_config_files_paths()
102
+	var err
103
+	if not directory.file_exists(paths["SAVED_DEFINITIONS_FILE"]):
104
+		err = sink.open(paths["SAVED_DEFINITIONS_FILE"], File.WRITE)
105
+		print('Saved definitions not present, creating file: ' + str(err))
106
+		if err == OK:
107
+			sink.store_string('')
108
+			sink.close()
109
+		else:
110
+			print('Error opening saved definitions file: ' + str(err))
70 111
 	
71
-	var err := directory.make_dir_recursive(get_working_directories()['WORKING_DIR'])
72
-	
112
+	err = sink.open(paths["SAVED_DEFINITIONS_FILE"], File.READ_WRITE)
73 113
 	if err == OK:
74
-		if not directory.file_exists(paths["SAVED_DEFINITIONS_FILE"]):
75
-			err = sink.open(paths["SAVED_DEFINITIONS_FILE"], File.WRITE)
76
-			print('Saved definitions not present, creating file: ' + str(err))
114
+		if overwrite or sink.get_len() == 0:
115
+			err = source.open(paths["DEFAULT_DEFINITIONS_FILE"], File.READ)
77 116
 			if err == OK:
78
-				sink.store_string('')
79
-				sink.close()
117
+				sink.store_string(source.get_as_text())
80 118
 			else:
81
-				print('Error opening saved definitions file: ' + str(err))
82
-		
83
-		err = sink.open(paths["SAVED_DEFINITIONS_FILE"], File.READ_WRITE)
84
-		if err == OK:
85
-			if overwrite or sink.get_len() == 0:
86
-				err = source.open(paths["DEFAULT_DEFINITIONS_FILE"], File.READ)
87
-				if err == OK:
88
-					sink.store_string(source.get_as_text())
89
-				else:
90
-					print('Error opening default definitions file: ' + str(err))
91
-			else:
92
-				print('Did not overwrite previous saved definitions')
119
+				print('Error opening default definitions file: ' + str(err))
93 120
 		else:
94
-			print('Error opening saved definitions file: ' + str(err))
121
+			print('Did not overwrite previous saved definitions')
95 122
 	else:
96
-		print('Error creating working directory: ' + str(err))
123
+		print('Error opening saved definitions file: ' + str(err))
97 124
 	
98 125
 	source.close()
99 126
 	sink.close()
@@ -163,30 +190,26 @@ static func remove_file(path: String):
163 190
 # JSON UTIL
164 191
 
165 192
 
166
-static func get_json(dir_id: String, path: String):
167
-	return load_json(get_path(dir_id, path))
168
-
169
-
170
-static func set_json(dir_id: String, path: String, data: Dictionary):
171
-	var directory = Directory.new()
172
-	var base_path := get_path(dir_id)
173
-	if not directory.dir_exists(base_path):
174
-		directory.make_dir_recursive(base_path)
193
+static func set_json(path: String, data: Dictionary):
175 194
 	var file = File.new()
176
-	file.open(get_path(dir_id, path), File.WRITE)
177
-	file.store_line(to_json(data))
178
-	file.close()
195
+	var err = file.open(path, File.WRITE)
196
+	if err == OK:
197
+		file.store_line(to_json(data))
198
+		file.close()
199
+	return err
179 200
 
180 201
 
181 202
 # TIMELINE
203
+# Can only be edited in the editor
204
+
182 205
 
183 206
 static func get_timeline_json(path: String):
184
-	return get_json('TIMELINE_DIR', path)
207
+	return load_json(get_path('TIMELINE_DIR', path))
185 208
 
186 209
 
187 210
 static func set_timeline(timeline: Dictionary):
188 211
 	# WARNING: For use in the editor only
189
-	set_json('TIMELINE_DIR', timeline['metadata']['file'], timeline)
212
+	set_json(get_path('TIMELINE_DIR', timeline['metadata']['file']), timeline)
190 213
 
191 214
 
192 215
 static func delete_timeline(filename: String):
@@ -195,15 +218,16 @@ static func delete_timeline(filename: String):
195 218
 
196 219
 
197 220
 # CHARACTER
221
+# Can only be edited in the editor
198 222
 
199 223
 
200 224
 static func get_character_json(path: String):
201
-	return get_json('CHAR_DIR', path)
225
+	return load_json(get_path('CHAR_DIR', path))
202 226
 
203 227
 
204 228
 static func set_character(character: Dictionary):
205 229
 	# WARNING: For use in the editor only
206
-	set_json('CHAR_DIR', character['id'], character)
230
+	set_json(get_path('CHAR_DIR', character['id']), character)
207 231
 
208 232
 
209 233
 static func delete_character(filename: String):
@@ -212,6 +236,7 @@ static func delete_character(filename: String):
212 236
 
213 237
 
214 238
 # THEME
239
+# Can only be edited in the editor
215 240
 
216 241
 
217 242
 static func get_theme_config(filename: String):
@@ -228,8 +253,6 @@ static func get_theme_config(filename: String):
228 253
 
229 254
 static func set_theme_value(filename, section, key, value):
230 255
 	# WARNING: For use in the editor only
231
-	print('=> theme update')
232
-	print(filename)
233 256
 	var config = get_theme_config(filename)
234 257
 	config.set_value(section, key, value)
235 258
 	config.save(get_path('THEME_DIR', filename))
@@ -239,10 +262,14 @@ static func add_theme(filename: String):
239 262
 	create_empty_file(get_path('THEME_DIR', filename))
240 263
 
241 264
 
265
+static func delete_theme(filename: String):
266
+	remove_file(get_path('THEME_DIR', filename))
267
+
242 268
 # SETTINGS
269
+# Can only be edited in the editor
243 270
 
244 271
 
245
-static func get_settings_config():
272
+static func get_settings_config() -> ConfigFile:
246 273
 	return get_config("SETTINGS_FILE")
247 274
 
248 275
 
@@ -252,98 +279,76 @@ static func set_settings_value(section: String, key: String, value):
252 279
 	config.save(get_config_files_paths()['SETTINGS_FILE'])
253 280
 
254 281
 
255
-# DEFINITIONS UTIL
256
-# used by default and saved definitions
257
-
258
-static func get_definition_key(config_id: String, section: String, key: String, default):
259
-	var config = get_config(config_id)
260
-	if config.has_section(section):
261
-		return config.get_value(section, key, default)
262
-	else:
263
-		return default
282
+# STATE
264 283
 
265 284
 
266
-static func set_definition_variable(config_id: String, section: String, name: String,  value):
267
-	var config = get_config(config_id)
268
-	config.set_value(section, 'name', name)
269
-	config.set_value(section, 'type', 0)
270
-	config.set_value(section, 'value', str(value))
271
-	return config.save(get_config_files_paths()[config_id])
285
+static func get_saved_state() -> Dictionary:
286
+	return load_json(get_config_files_paths()['SAVED_STATE_FILE'], {'general': {}})
272 287
 
273 288
 
274
-static func set_definition_glossary(config_id: String, section: String, name: String,  extra_title: String,  extra_text: String,  extra_extra: String):
275
-	var config = get_config(config_id)
276
-	config.set_value(section, 'name', name)
277
-	config.set_value(section, 'type', 1)
278
-	config.set_value(section, 'extra_title', extra_title)
279
-	config.set_value(section, 'extra_text', extra_text)
280
-	config.set_value(section, 'extra_extra', extra_extra)
281
-	return config.save(get_config_files_paths()[config_id])
289
+static func save_saved_state_config(data: Dictionary):
290
+	set_json(get_config_files_paths()['SAVED_STATE_FILE'], data)
282 291
 
283 292
 
284
-static func add_definition_variable(config_id: String, section: String, name: String, type: int, value):
285
-	var config = get_config(config_id)
286
-	config.set_value(section, 'name', name)
287
-	config.set_value(section, 'type', type)
288
-	config.set_value(section, 'value', str(value))
289
-	return config.save(get_config_files_paths()[config_id])
290
-
293
+static func get_saved_state_general_key(key: String) -> String:
294
+	var data = get_saved_state()
295
+	if key in data['general'].keys():
296
+		return data['general'][key]
297
+	else:
298
+		return ''
291 299
 
292
-static func delete_definition(config_id: String, section: String):
293
-	var config = get_config(config_id)
294
-	config.erase_section(section)
295
-	return config.save(get_config_files_paths()[config_id])
296 300
 
301
+static func set_saved_state_general_key(key: String, value):
302
+	var data = get_saved_state()
303
+	data['general'][key] = str(value)
304
+	save_saved_state_config(data)
297 305
 
298 306
 
299 307
 # DEFAULT DEFINITIONS
300 308
 # Can only be edited in the editor
301 309
 
302
-static func get_default_definitions_config():
303
-	return get_config('DEFAULT_DEFINITIONS_FILE')
304 310
 
311
+static func get_default_definitions() -> Dictionary:
312
+	return load_json(get_config_files_paths()['DEFAULT_DEFINITIONS_FILE'], {'variables': [], 'glossary': []})
305 313
 
306
-static func get_default_definition_key(section: String, key: String, default):
307
-	return get_definition_key('DEFAULT_DEFINITIONS_FILE', section, key, default)
308 314
 
315
+static func save_default_definitions(data: Dictionary):
316
+	set_json(get_config_files_paths()['DEFAULT_DEFINITIONS_FILE'], data)
309 317
 
310
-static func set_default_definition_variable(section: String, name: String,  value):
311
-	# WARNING: For use in the editor only
312
-	return set_definition_variable('DEFAULT_DEFINITIONS_FILE', section, name, value)
313 318
 
319
+static func get_default_definition_item(id: String):
320
+	var data = get_default_definitions()
321
+	return DialogicDefinitionsUtil.get_definition_by_id(data, id)
314 322
 
315
-static func set_default_definition_glossary(section: String, name: String,  extra_title: String,  extra_text: String,  extra_extra: String):
323
+
324
+static func set_default_definition_variable(id: String, name: String, value):
316 325
 	# WARNING: For use in the editor only
317
-	return set_definition_glossary('DEFAULT_DEFINITIONS_FILE', section, name, extra_title, extra_text, extra_extra)
326
+	var data = get_default_definitions()
327
+	DialogicDefinitionsUtil.set_definition_variable(data, id, name, value)
328
+	save_default_definitions(data)
318 329
 
319 330
 
320
-static func add_default_definition_variable(section: String, name: String, type: int, value):
331
+static func set_default_definition_glossary(id: String, name: String, extra_title: String,  extra_text: String,  extra_extra: String):
321 332
 	# WARNING: For use in the editor only
322
-	return add_definition_variable('DEFAULT_DEFINITIONS_FILE', section, name, type, value)
333
+	var data = get_default_definitions()
334
+	DialogicDefinitionsUtil.set_definition_glossary(data, id, name, extra_title, extra_text, extra_extra)
335
+	save_default_definitions(data)
323 336
 
324 337
 
325
-static func delete_default_definition(section: String):
338
+static func delete_default_definition(id: String):
326 339
 	# WARNING: For use in the editor only
327
-	return delete_definition('DEFAULT_DEFINITIONS_FILE', section)
340
+	var data = get_default_definitions()
341
+	DialogicDefinitionsUtil.delete_definition(data, id)
342
+	save_default_definitions(data)
328 343
 
329 344
 
330 345
 # SAVED DEFINITIONS
331 346
 # Can be edited at runtime, and will persist across runs
332 347
 
333 348
 
334
-static func get_saved_definitions_config():
335
-	return get_config("SAVED_DEFINITIONS_FILE")
336
-
337
-
338
-static func set_saved_definition_variable(section: String, name: String,  value):
339
-	return set_definition_variable('SAVED_DEFINITIONS_FILE', section, name, value)
340
-
341
-
342
-static func set_saved_definition_variable_value(section: String, value):
343
-	var config = get_saved_definitions_config()
344
-	return set_definition_variable('SAVED_DEFINITIONS_FILE', section, config.get_value(section, 'name', section), value)
345
-
349
+static func get_saved_definitions() -> Dictionary:
350
+	return load_json(get_config_files_paths()['SAVED_DEFINITIONS_FILE'], {'variables': [], 'glossary': []})
346 351
 
347
-static func set_saved_definition_glossary(section: String, name: String,  extra_title: String,  extra_text: String,  extra_extra: String):
348
-	return set_definition_glossary('SAVED_DEFINITIONS_FILE', section, name, extra_title, extra_text, extra_extra)
349 352
 
353
+static func save_saved_definitions(data: Dictionary):
354
+	return set_json(get_config_files_paths()['SAVED_DEFINITIONS_FILE'], data)

+ 86
- 0
addons/dialogic/Other/DialogicSingleton.gd View File

@@ -0,0 +1,86 @@
1
+extends Node
2
+
3
+var current_definitions := {}
4
+var default_definitions := {}
5
+
6
+var current_timeline := ''
7
+
8
+func _init() -> void:
9
+	init(false)
10
+
11
+
12
+func init(reset: bool=false) -> void:
13
+	# Loads saved definitions into memory
14
+	DialogicResources.init_saves(reset)
15
+	current_definitions = DialogicResources.get_saved_definitions()
16
+	default_definitions = DialogicResources.get_default_definitions()
17
+	current_timeline = DialogicResources.get_saved_state_general_key('timeline')
18
+
19
+
20
+func get_definitions_list() -> Array:
21
+	return DialogicDefinitionsUtil.definitions_json_to_array(current_definitions)
22
+
23
+
24
+func get_definitions() -> Dictionary:
25
+	return current_definitions
26
+
27
+
28
+func get_default_definitions() -> Dictionary:
29
+	return default_definitions
30
+
31
+
32
+func get_default_definitions_list() -> Array:
33
+	return DialogicDefinitionsUtil.definitions_json_to_array(default_definitions)
34
+
35
+
36
+func save_definitions():
37
+	return DialogicResources.save_saved_definitions(current_definitions)
38
+
39
+
40
+func get_variable(name: String) -> String:
41
+	for d in current_definitions['variables']:
42
+		if d['name'] == name:
43
+			return d['value']
44
+	return ''
45
+
46
+
47
+func set_variable(name: String, value) -> void:
48
+	for d in current_definitions['variables']:
49
+		if d['name'] == name:
50
+			d['value'] = str(value)
51
+
52
+
53
+func set_variable_from_id(id: String, value) -> void:
54
+	for d in current_definitions['variables']:
55
+		if d['id'] == id:
56
+			d['value'] = str(value)
57
+
58
+
59
+func get_glossary(name: String) -> Dictionary:
60
+	for d in current_definitions['glossary']:
61
+		if d['name'] == name:
62
+			return d
63
+	return { 
64
+		'title': '',
65
+		'text': '',
66
+		'extra': ''
67
+	}
68
+
69
+
70
+func set_glossary(name: String, title: String, text: String, extra: String) -> void:
71
+	for d in current_definitions['glossary']:
72
+		if d['name'] == name:
73
+			d['title'] = title
74
+			d['text'] = text
75
+			d['extra'] = extra
76
+
77
+
78
+func set_current_timeline(timeline: String):
79
+	current_timeline = timeline
80
+	DialogicResources.set_saved_state_general_key('timeline', timeline)
81
+
82
+
83
+func get_current_timeline() -> String:
84
+	return current_timeline
85
+
86
+

+ 2
- 37
addons/dialogic/Other/DialogicUtil.gd View File

@@ -68,43 +68,8 @@ static func get_theme_list() -> Array:
68 68
 	return themes
69 69
 
70 70
 
71
-static func get_default_definition_list() -> Array:
72
-	var definitions: Array = []
73
-	var config = DialogicResources.get_default_definitions_config()
74
-	for section in config.get_sections():
75
-		definitions.append({
76
-			'section': section,
77
-			'name': config.get_value(section, 'name', section),
78
-			'config': config,
79
-			'type': config.get_value(section, 'type', 0),
80
-		})
81
-	return definitions
82
-
83
-
84
-static func get_definition_list() -> Array:
85
-	var definitions: Array = []
86
-	var config = DialogicResources.get_saved_definitions_config()
87
-	for section in config.get_sections():
88
-		definitions.append({
89
-			'section': section,
90
-			'name': config.get_value(section, 'name', section),
91
-			'config': config,
92
-			'type': config.get_value(section, 'type', 0),
93
-		})
94
-	return definitions
95
-
96
-
97
-static func get_var(variable: String) -> String:
98
-	for d in get_definition_list():
99
-		if d['name'] == variable:
100
-			return d['config'].get_value(d['section'], 'value')
101
-	return ''
102
-
103
-
104
-static func set_var(variable: String, value) -> void:
105
-	for d in get_definition_list():
106
-		if d['name'] == variable:
107
-			DialogicResources.set_saved_definition_variable(d['section'], d['name'], value)
71
+static func get_default_definitions_list() -> Array:
72
+	return DialogicDefinitionsUtil.definitions_json_to_array(DialogicResources.get_default_definitions())
108 73
 
109 74
 
110 75
 static func generate_random_id() -> String:

+ 2
- 2
addons/dialogic/Other/timeline_picker.gd View File

@@ -36,7 +36,7 @@ func _about_to_show_menu():
36 36
 func _on_timeline_selected(index):
37 37
 	var text = timelines_dropdown.get_popup().get_item_text(index)
38 38
 	var metadata = timelines_dropdown.get_popup().get_item_metadata(index)
39
-	current_value = metadata['file'].replace('.json', '')
39
+	current_value = metadata['file']
40 40
 	timelines_dropdown.text = text
41 41
 	emit_changed(get_edited_property(), current_value)
42 42
 
@@ -52,6 +52,6 @@ func update_property():
52 52
 	current_value = new_value
53 53
 	# Checking for the display name
54 54
 	for c in DialogicUtil.get_timeline_list():
55
-		if c['file'].replace('.json', '') == current_value:
55
+		if c['file'] == current_value:
56 56
 			timelines_dropdown.text = c['name']
57 57
 	updating = false

+ 7
- 2
addons/dialogic/dialogic.gd View File

@@ -4,6 +4,13 @@ extends EditorPlugin
4 4
 var _editor_view
5 5
 var _parts_inspector
6 6
 
7
+func _init():
8
+	if Engine.editor_hint:
9
+		# Make sure the core files exist 
10
+		DialogicResources.init_dialogic_files()
11
+	add_autoload_singleton('DialogicSingleton', "res://addons/dialogic/Other/DialogicSingleton.gd")
12
+
13
+
7 14
 func _enter_tree() -> void:
8 15
 	_parts_inspector = load("res://addons/dialogic/Other/inspector_timeline_picker.gd").new()
9 16
 	add_inspector_plugin(_parts_inspector)
@@ -14,8 +21,6 @@ func _enter_tree() -> void:
14 21
 
15 22
 func _ready():
16 23
 	if Engine.editor_hint:
17
-		# Make sure the core files exist 
18
-		DialogicResources.init_dialogic_files()
19 24
 		# Force Godot to show the dialogic folder
20 25
 		get_editor_interface().get_resource_filesystem().scan()
21 26
 	

Loading…
Cancel
Save