Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@tool functionality #5

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions addons/LogDuck/LogDuck.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@tool
extends LogDuckSettings
const VERSION = "v0.9"
const VERSION = "v0.9.1"

## Use LogDuck.d(), .e(), or .w() for logging debug, error, or warning messages.
## Supports up to 6 arguments (or 7, if not starting with a string message).
Expand Down Expand Up @@ -100,6 +101,8 @@ func argument_to_string(arg) -> String:


func extract_class_name_from_gdscript(path) -> String:
if path == null: return "LogDuck" #

var file = FileAccess.open(path, FileAccess.READ)
if not file:
class_name_dict[path] = "File Open Error"
Expand Down Expand Up @@ -131,11 +134,14 @@ func extract_class_name_from_gdscript(path) -> String:


func _output(level : LogLevel, msg, arg1, arg2, arg3, arg4, arg5, arg6):

var frame : Array = [
str(stack_frame()['source']),
str(stack_frame()['line']),
str(stack_frame()['function'])]
var frame : Array
if not Engine.is_editor_hint():
frame = [
str(stack_frame()['source']),
str(stack_frame()['line']),
str(stack_frame()['function'])]
else: # Since this is called inside the editor, get_stack() returns []
frame = [null,null,null]

var _class : String

Expand Down
2 changes: 2 additions & 0 deletions addons/LogDuck/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ extends EditorPlugin
## Adjust the singleton name if you prefer something more classic like "Log"
const SingletonName : String = "LogDuck"

@onready var LogDuckSingleton = get_node("/root/LogDuck");

func _enter_tree():
add_autoload_singleton(SingletonName, "res://addons/LogDuck/LogDuck.gd")
7 changes: 7 additions & 0 deletions test_scene.gd
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
@tool
extends Control
class_name TestScene

@onready var debug_msg_line_edit: LineEdit = $CenterContainer/VBoxContainer/LineEdit
@onready var check_box: CheckBox = $CenterContainer/VBoxContainer/CheckBox
@onready var checkbox_rich_output: CheckBox = $"CenterContainer/VBoxContainer/Checkbox Rich Output"

const SingletonName : String = "LogDuck"

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
LogDuck.print_rich = checkbox_rich_output.button_pressed
if Engine.is_editor_hint():
LogDuck.d("Calling LogDuck in the editor / inside @tool script");
else:
LogDuck.d("Calling LogDuck during runtime");

func _on_button_debug_pressed() -> void:
LogDuck.print_rich = checkbox_rich_output.button_pressed
Expand Down