-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[plugin_reloader] Add plugin reloader
- Loading branch information
Showing
5 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
@tool | ||
extends MarginContainer | ||
|
||
@export var _reload_button: Button | ||
@export var _option_button: OptionButton | ||
|
||
var _last_selection: String = "" | ||
|
||
func _ready() -> void: | ||
if Engine.is_editor_hint(): | ||
self._reload_button.icon = self.get_theme_icon(&"Reload", &"EditorIcons") | ||
|
||
self._option_button.item_selected.connect(func(idx: int) -> void: | ||
self._last_selection = self._option_button.get_item_metadata(idx) | ||
) | ||
self._reload_button.pressed.connect(self._on_reload_pressed) | ||
|
||
EditorInterface.get_resource_filesystem().filesystem_changed.connect(self._reload_plugins) | ||
self._reload_plugins() | ||
|
||
func _reload_plugins() -> void: | ||
self._option_button.clear() | ||
for dir: String in DirAccess.get_directories_at("res://addons/"): | ||
self._add_plugin(dir) | ||
|
||
# subfolder | ||
for sub_dir: String in DirAccess.get_directories_at("res://addons/" + dir): | ||
self._add_plugin(dir + "/" + sub_dir) | ||
if self._last_selection == "": | ||
self._last_selection = self._option_button.get_item_metadata(0) | ||
|
||
|
||
func _add_plugin(plugin_id: String) -> void: | ||
# ignore the current plugin | ||
if plugin_id == "kenyoni/plugin_reloader": | ||
return | ||
|
||
var cfg_path: String = "res://addons/" + plugin_id + "/plugin.cfg" | ||
if !FileAccess.file_exists(cfg_path): | ||
return | ||
|
||
var plugin_cfg: ConfigFile = ConfigFile.new() | ||
plugin_cfg.load(cfg_path) | ||
var plugin_name: String = plugin_cfg.get_value("plugin", "name", plugin_id) | ||
self._option_button.add_item(plugin_name) | ||
self._option_button.set_item_metadata(self._option_button.get_item_count() - 1, plugin_id) | ||
self._option_button.set_item_tooltip(self._option_button.get_item_count() - 1, "res://addons/" + plugin_id + "/") | ||
if plugin_id == self._last_selection: | ||
self._option_button.select(self._option_button.get_item_count() - 1) | ||
|
||
func _on_reload_pressed() -> void: | ||
var cfg_path: String = "res://addons/" + self._last_selection + "/plugin.cfg" | ||
if EditorInterface.is_plugin_enabled(cfg_path): | ||
EditorInterface.set_plugin_enabled(cfg_path, false) | ||
EditorInterface.set_plugin_enabled(cfg_path, true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://dryoyuj4vl0l5"] | ||
|
||
[ext_resource type="Script" path="res://addons/kenyoni/plugin_reloader/internal/reloader.gd" id="1_kd7gg"] | ||
|
||
[node name="Reloader" type="MarginContainer" node_paths=PackedStringArray("_reload_button", "_option_button")] | ||
offset_right = 939.0 | ||
offset_bottom = 187.0 | ||
script = ExtResource("1_kd7gg") | ||
_reload_button = NodePath("HBoxContainer/reload_button") | ||
_option_button = NodePath("HBoxContainer/OptionButton") | ||
|
||
[node name="HBoxContainer" type="HBoxContainer" parent="."] | ||
layout_mode = 2 | ||
|
||
[node name="reload_button" type="Button" parent="HBoxContainer"] | ||
layout_mode = 2 | ||
|
||
[node name="OptionButton" type="OptionButton" parent="HBoxContainer"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[plugin] | ||
|
||
name="Plugin Reloader" | ||
description="Quickly reload plugins from the editor." | ||
author="Kenyoni Software" | ||
version="0.1.0" | ||
script="plugin.gd" | ||
license="MIT" | ||
repository="https://github.com/kenyoni-software/godot-addons" | ||
keywords=[ | ||
"tool" | ||
] | ||
classifiers=[ | ||
"Development Status :: 5 - Production/Stable", | ||
"License :: OSI Approved :: MIT License" | ||
] | ||
|
||
[plugin.dependencies] | ||
godot="==4.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@tool | ||
extends EditorPlugin | ||
|
||
const ReloaderScene: PackedScene = preload("res://addons/kenyoni/plugin_reloader/internal/reloader.tscn") | ||
const Reloader := preload("res://addons/kenyoni/plugin_reloader/internal/reloader.gd") | ||
|
||
var _reloader: Reloader | ||
|
||
func _get_plugin_name() -> String: | ||
return "Plugin Reloader" | ||
|
||
func _enter_tree() -> void: | ||
self._reloader = ReloaderScene.instantiate() | ||
self.add_control_to_container(CustomControlContainer.CONTAINER_TOOLBAR, self._reloader) | ||
# move before editor run bar | ||
self._reloader.get_parent().move_child(self._reloader, self._reloader.get_parent().find_child("@EditorRunBar@*", true, false).get_index()) | ||
|
||
func _exit_tree() -> void: | ||
self.remove_control_from_container(CustomControlContainer.CONTAINER_TOOLBAR, self._reloader) | ||
self._reloader.queue_free() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters