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

Extend argument parsing #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 18 additions & 1 deletion addons/loggie/tools/loggie_tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static func concatenate_msg_and_args(msg : Variant, arg1 : Variant = null, arg2
var arguments = [arg1, arg2, arg3, arg4, arg5, arg6]
for arg in arguments:
if arg != null:
final_msg += (" " + convert_to_string(arg))
final_msg += ", [ %s ]" % convert_to_string(arg)
return final_msg

## Converts [param something] into a string.
Expand All @@ -31,6 +31,23 @@ static func convert_to_string(something : Variant) -> String:
result = JSON.new().stringify(something, " ", false, true)
elif something is LoggieMsg:
result = str(something.string())

elif something is Object:
return "%s: %s" % [something.get_class(), something.to_string()]

elif something is Vector2:
return "Vector2: %s" % str(something)
elif something is Vector2i:
return "Vector2i: %s" % str(something)
elif something is Vector3:
return "Vector3: %s" % str(something)
elif something is Vector3i:
return "Vector3i: %s" % str(something)

elif something is Color:
var html:String = something.to_html()
return "Color: {%s} [color=%s]#%s[/color]" % [str(something), html, html]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be the incorrect place to insert this BBCode, please confirm :)


else:
result = str(something)
return result
Expand Down
2 changes: 2 additions & 0 deletions test/test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func test_all_log_level_outputs():
Loggie.msg("Test logging methods").box(25).info()
Loggie.msg("Test info").info()
Loggie.msg("Test", "info", "multi", "argument").info()
Loggie.msg("Test", 50, get_viewport(), AudioServer).info()
Loggie.msg("Test", Color.RED, Vector2.UP, Vector2i.ONE).info()
Loggie.msg("Test error.").error()
Loggie.msg("Test warning.").warn()
Loggie.msg("Test notice.").notice()
Expand Down