Skip to content

Commit

Permalink
Update shared addons code.
Browse files Browse the repository at this point in the history
  • Loading branch information
raldone01 committed Feb 29, 2024
1 parent cddf3dd commit 4c6fe61
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
29 changes: 24 additions & 5 deletions addons_shared_gen/addons_panel_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ class AddonsPanelManager:
const ADDONS_DOCK_NAME = "addons_dock_2c39d5937171140c1faaadb702029b32"
static var _addons_dock: Control
var _editor_plugin: EditorPlugin
var _plugin_name: String
var _main_panel: Control
var _tree: SceneTree

func _init(p_editor_plugin) -> void:
func _init(p_editor_plugin: EditorPlugin, p_plugin_name: String) -> void:
_editor_plugin = p_editor_plugin
_plugin_name = p_plugin_name
_tree = EditorInterface.get_editor_main_screen().get_tree()

func _find_addons_dock() -> Control:
Expand All @@ -18,26 +20,43 @@ class AddonsPanelManager:
return group[0]
return null

func add_main_panel(p_panel) -> void:
func add_main_panel(p_panel: Node) -> void:
var show_setting_name = "addons/" + _plugin_name + "/show_in_addons_dock"

if not ProjectSettings.has_setting(show_setting_name):
ProjectSettings.set_setting(show_setting_name, true)
ProjectSettings.add_property_info({
"name": show_setting_name,
"type": TYPE_BOOL,
"hint_string": "Show in Addons Dock",
})
ProjectSettings.set_as_basic(show_setting_name, true)
ProjectSettings.set_as_internal(show_setting_name, false)
ProjectSettings.set_initial_value(show_setting_name, true)
ProjectSettings.set_restart_if_changed(show_setting_name, true)

if not ProjectSettings.get_setting(show_setting_name):
return

if not _addons_dock:
_addons_dock = _find_addons_dock()
if not _addons_dock:
_addons_dock = preload("res://addons/gdlogging/addons_shared_gen/addons_panel_manager/scenes/ui_addons_dock.tscn").instantiate()
_addons_dock = preload ("res://addons/gdlogging/addons_shared_gen/addons_panel_manager/scenes/ui_addons_dock.tscn").instantiate()
_addons_dock.add_to_group(ADDONS_DOCK_NAME)
_editor_plugin.add_control_to_dock(EditorPlugin.DOCK_SLOT_RIGHT_UL, _addons_dock)

_main_panel = p_panel
_addons_dock.child_container.add_child(p_panel)
_sort_children_alphabetically(_addons_dock.child_container)

func _sort_children_alphabetically(p_container) -> void:
func _sort_children_alphabetically(p_container: Node) -> void:
const LABEL_NAME = "AddonTitle"
var children: Array[Dictionary] = []
for child in p_container.get_children():
var label = child.find_child(LABEL_NAME)
children.append({"label": label, "node": child})

var sorter := func (p_a: Dictionary, p_b: Dictionary):
var sorter := func(p_a: Dictionary, p_b: Dictionary):
var a_label: Label = p_a["label"]
var b_label: Label = p_b["label"]

Expand Down
6 changes: 3 additions & 3 deletions funcs/logger.gd
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class BroadcastPipe extends LogSink:
for sink in _sinks:
sink.close()

class BufferedSink extends LogSink:
class BufferedPipe extends LogSink:
var _sink: LogSink

var _buffer_log_records: Array[Dictionary] = []
Expand All @@ -165,7 +165,7 @@ class BufferedSink extends LogSink:
# At most 1 second between buffer flushes
var _buffer_flush_interval_usec: int = 1000 * 1000 * 1

## Creates a new BufferedSink.
## Creates a new BufferedPipe.
##
## [param sink]: The sink to write to.
## [param buffer_size]: The size of the buffer. If 0, the buffer will be disabled.
Expand All @@ -174,7 +174,7 @@ class BufferedSink extends LogSink:
func _init(p_sink: LogSink, p_buffer_size: int=42) -> void:
if p_buffer_size < 0:
p_buffer_size = 0
Log._logger_direct_console.warning("BufferedSink: Buffer size must be equal or greater than 0.")
Log._logger_direct_console.warning("BufferedPipe: Buffer size must be equal or greater than 0.")
_buffer_size = p_buffer_size
_sink = p_sink

Expand Down
4 changes: 2 additions & 2 deletions main_gdlogging.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var addons_panel_manager: Variant

func _enter_tree() -> void:
add_autoload_singleton("Log", "res://addons/gdlogging/funcs/logger.gd")
addons_panel_manager = load("res://addons/gdlogging/addons_shared_gen/addons_panel_manager.gd").AddonsPanelManager.new(self)
addons_panel_manager = load("res://addons/gdlogging/addons_shared_gen/addons_panel_manager.gd").AddonsPanelManager.new(self, "gdlogging")
main_panel = load("res://addons/gdlogging/scenes_editor/ui_addon_panel.tscn").instantiate()
addons_panel_manager.add_main_panel(main_panel)

Expand All @@ -15,7 +15,7 @@ func _exit_tree() -> void:
addons_panel_manager.remove_main_panel()

func _get_plugin_icon() -> Texture2D:
return preload("res://addons/gdlogging/assets/icons_editor/plugin_icon_white.svg")
return preload ("res://addons/gdlogging/assets/icons_editor/plugin_icon_white.svg")

func _get_plugin_name() -> String:
return "gdlogging"

0 comments on commit 4c6fe61

Please sign in to comment.