]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Core/index_class.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Core / index_class.gd
1 @tool
2 class_name DialogicIndexer
3 extends RefCounted
4
5 ## Script that indexes events, subsystems, settings pages and more. [br]
6 ## Place a script of this type in every folder in "addons/Events". [br]
7 ## Overwrite the methods to return the contents of that folder.
8
9
10 var this_folder: String = get_script().resource_path.get_base_dir()
11
12 ## Overwrite if this module contains any events. [br]
13 ## Return an array with all the paths to the event scripts.[br]
14 ## You can use the [property this_folder].path_join('my_event.gd')
15 func _get_events() -> Array:
16         if ResourceLoader.exists(this_folder.path_join('event.gd')):
17                 return [this_folder.path_join('event.gd')]
18         return []
19
20
21 ## Overwrite if this module contains any subsystems.
22 ## Should return an array of dictionaries each with the following keys: [br]
23 ## "name"               -> name for this subsystem[br]
24 ## "script"     -> array of preview images[br]
25 func _get_subsystems() -> Array[Dictionary]:
26         return []
27
28
29 func _get_editors() -> Array[String]:
30         return []
31
32
33 func _get_settings_pages() -> Array:
34         return []
35
36
37 func _get_character_editor_sections() -> Array:
38         return []
39
40
41 #region TEXT EFFECTS & MODIFIERS
42
43 ## Should return array of dictionaries with the following keys:[br]
44 ## "command"    -> the text e.g. "speed"[br]
45 ## "node_path" or "subsystem" -> whichever contains your effect method[br]
46 ## "method"     -> name of the effect method[br]
47 func _get_text_effects() -> Array[Dictionary]:
48         return []
49
50
51 ## Should return array of dictionaries with the same arguments as _get_text_effects()
52 func _get_text_modifiers() -> Array[Dictionary]:
53         return []
54
55 #endregion
56
57
58 ## Return a list of resources, scripts, etc.
59 ## These can later be retrieved with DialogicResourceUtil.
60 ## Each dictionary should contain (at least "type" and "path").
61 ##              E.g. {"type":"Animation", "path": "res://..."}
62 func _get_special_resources() -> Dictionary:
63         return {}
64
65
66 ## Return a list of dictionaries, each
67 func _get_portrait_scene_presets() -> Array[Dictionary]:
68         return []
69
70
71 #region HELPERS
72 ################################################################################
73
74 func list_dir(subdir:='') -> Array:
75         return Array(DirAccess.get_files_at(this_folder.path_join(subdir))).map(func(file):return this_folder.path_join(subdir).path_join(file))
76
77
78 func list_special_resources(subdir:='', extension:="") -> Dictionary:
79         var dict := {}
80         for i in list_dir(subdir):
81                 if extension.is_empty() or i.ends_with(extension):
82                         dict[DialogicUtil.pretty_name(i).to_lower()] = {"path":i}
83         return dict
84
85
86 func list_animations(subdir := "") -> Dictionary:
87         var full_animation_list := {}
88         for path in list_dir(subdir):
89                 if not path.ends_with(".gd") and not path.ends_with(".gdc"):
90                         continue
91                 var anim_object: DialogicAnimation = load(path).new()
92                 var versions := anim_object._get_named_variations()
93                 for version_name in versions:
94                         full_animation_list[version_name] = versions[version_name]
95                         full_animation_list[version_name]["path"] = path
96                 anim_object.queue_free()
97         return full_animation_list
98
99 #endregion
100
101
102 #region STYLES & LAYOUTS
103 ################################################################################
104
105 func _get_style_presets() -> Array[Dictionary]:
106         return []
107
108
109 ## Should return an array of dictionaries with the following keys:[br]
110 ## "path"               -> the path to the scene[br]
111 ## "name"               -> name for this layout[br]
112 ## "description"-> description of this layout. list what features/events are supported[br]
113 ## "preview_image"-> array of preview images[br]
114 func _get_layout_parts() -> Array[Dictionary]:
115         return []
116
117
118 ## Helper that allows scanning sub directories that might be layout parts or styles
119 func scan_for_layout_parts() -> Array[Dictionary]:
120         var dir := DirAccess.open(this_folder)
121         var style_list: Array[Dictionary] = []
122         if !dir:
123                 return style_list
124         dir.list_dir_begin()
125         var dir_name := dir.get_next()
126         while dir_name != "":
127                 if !dir.current_is_dir() or !dir.file_exists(dir_name.path_join('part_config.cfg')):
128                         dir_name = dir.get_next()
129                         continue
130                 var config := ConfigFile.new()
131                 config.load(this_folder.path_join(dir_name).path_join('part_config.cfg'))
132                 var default_image_path: String = this_folder.path_join(dir_name).path_join('preview.png')
133                 style_list.append(
134                         {
135                                 'type': config.get_value('style', 'type', 'Unknown type'),
136                                 'name': config.get_value('style', 'name', 'Unnamed Layout'),
137                                 'path': this_folder.path_join(dir_name).path_join(config.get_value('style', 'scene', '')),
138                                 'author': config.get_value('style', 'author', 'Anonymous'),
139                                 'description': config.get_value('style', 'description', 'No description'),
140                                 'preview_image': [config.get_value('style', 'image', default_image_path)],
141                                 'style_path':config.get_value('style', 'style_path', ''),
142                                 'icon':this_folder.path_join(dir_name).path_join(config.get_value('style', 'icon', '')),
143                         })
144
145                 if not style_list[-1].style_path.begins_with('res://'):
146                         style_list[-1].style_path = this_folder.path_join(dir_name).path_join(style_list[-1].style_path)
147
148                 dir_name = dir.get_next()
149
150         return style_list
151
152 #endregion