1- tool
1+ @ tool
22extends EditorPlugin
33
44const ADDONS_PATH = "res://addons/"
@@ -11,15 +11,15 @@ var plugin_config = ConfigFile.new()
1111var refresher
1212
1313func _enter_tree ():
14- refresher = preload ("plugin_refresher.tscn" ).instance ()
14+ refresher = preload ("plugin_refresher.tscn" ).instantiate ()
1515 add_control_to_container (CONTAINER_TOOLBAR , refresher )
1616
1717 # Watch whether any plugin is changed, added or removed on the filesystem
1818 var efs = get_editor_interface ().get_resource_filesystem ()
19- efs .connect ("filesystem_changed" , self , " _on_filesystem_changed" )
19+ efs .filesystem_changed . connect (_on_filesystem_changed )
2020
21- refresher .connect ("request_refresh_plugin" , self , " _on_request_refresh_plugin" )
22- refresher .connect ("confirm_refresh_plugin" , self , " _on_confirm_refresh_plugin" )
21+ refresher .request_refresh_plugin . connect (_on_request_refresh_plugin )
22+ refresher .confirm_refresh_plugin . connect (_on_confirm_refresh_plugin )
2323
2424 _reload_plugins_list ()
2525 _load_settings ()
@@ -35,63 +35,63 @@ func _reload_plugins_list():
3535 var plugins = {}
3636 var origins = {}
3737
38- var dir = Directory .new ()
39- dir .open (ADDONS_PATH )
40- dir .list_dir_begin (true , true )
41- var file = dir .get_next ()
42- while file :
43- var addon_dir = ADDONS_PATH .plus_file (file )
44- if dir .dir_exists (addon_dir ) and file != refresher_dir :
45- var display_name = file
46- var plugin_config_path = addon_dir .plus_file ("plugin.cfg" )
47- if not dir .file_exists (plugin_config_path ):
48- file = dir .get_next ()
49- continue # not a plugin
50- var plugin_cfg = ConfigFile .new ()
51- plugin_cfg .load (plugin_config_path )
52- display_name = plugin_cfg .get_value ("plugin" , "name" , file )
53- if not display_name in origins :
54- origins [display_name ] = [file ]
55- else :
56- origins [display_name ].append (file )
57- plugins [file ] = display_name
58- file = dir .get_next ()
59-
60- # Specify the exact plugin name in parenthesis in case of naming collisions.
61- for display_name in origins :
62- var plugin_names = origins [display_name ]
63- if plugin_names .size () > 1 :
64- for n in plugin_names :
65- plugins [n ] = "%s (%s )" % [display_name , n ]
66-
67- refresher .update_items (plugins )
68-
38+ var dir = DirAccess .open (ADDONS_PATH )
39+ if dir :
40+ dir .list_dir_begin ()
41+ var file_name = dir .get_next ()
42+ while file_name != "" :
43+
44+ var addon_dir = ADDONS_PATH .path_join (file_name )
45+ if dir .dir_exists (addon_dir ) and file_name != refresher_dir :
46+ var display_name = file_name
47+
48+ var plugin_config_path = addon_dir .path_join ("plugin.cfg" )
49+ if not dir .file_exists (plugin_config_path ):
50+ file_name = dir .get_next ()
51+ continue # not a plugin
52+ var plugin_cfg = ConfigFile .new ()
53+ plugin_cfg .load (plugin_config_path )
54+ display_name = plugin_cfg .get_value ("plugin" , "name" , file_name )
55+ if not display_name in origins :
56+ origins [display_name ] = [file_name ]
57+ else :
58+ origins [display_name ].append (file_name )
59+ plugins [file_name ] = display_name
60+ file_name = dir .get_next ()
61+
62+ # Specify the exact plugin name in parenthesis in case of naming collisions.
63+ for display_name in origins :
64+ var plugin_names = origins [display_name ]
65+ if plugin_names .size () > 1 :
66+ for n in plugin_names :
67+ plugins [n ] = "%s (%s )" % [display_name , n ]
68+
69+ refresher .update_items (plugins )
6970
7071func _load_settings ():
7172 var path = get_config_path ()
7273
73- var fs = Directory .new ()
74- if not fs .file_exists (path ):
74+ if not FileAccess .file_exists (path ):
7575 # Create new if running for the first time
7676 var config = ConfigFile .new ()
77- fs . make_dir_recursive (path .get_base_dir ())
77+ DirAccess . make_dir_recursive_absolute (path .get_base_dir ())
7878 config .save (path )
7979 else :
8080 plugin_config .load (path )
8181
82-
8382func _save_settings ():
8483 plugin_config .save (get_config_path ())
8584
8685
87- func get_config_path ():
88- var dir = get_editor_interface ().get_editor_settings ().get_project_settings_dir ()
89- var home = dir .plus_file (PLUGIN_CONFIG_DIR )
90- var path = home .plus_file (PLUGIN_CONFIG )
86+ func get_config_path () -> String :
87+ var editor_paths = EditorInterface .get_editor_paths ()
88+ var dir = editor_paths .get_project_settings_dir ()
89+
90+ var home = dir .path_join (PLUGIN_CONFIG_DIR )
91+ var path = home .path_join (PLUGIN_CONFIG )
9192
9293 return path
9394
94-
9595func _on_filesystem_changed ():
9696 if refresher :
9797 _reload_plugins_list ()
@@ -107,7 +107,7 @@ func get_recent_plugin():
107107
108108
109109func _on_request_refresh_plugin (p_name ):
110- assert (not p_name .empty ())
110+ assert (not p_name .is_empty ())
111111
112112 var disabled = not get_editor_interface ().is_plugin_enabled (p_name )
113113 if disabled :
0 commit comments