From 1607fe62ccdcf3071a8c12a8c53d8ca14c30f101 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Tue, 3 Dec 2024 12:52:14 +0100 Subject: [PATCH] Added a simple Logging system and enforced static typing in all files. --- project.godot | 49 ++++++++++++++++++++++++++++++++++++++++++++ scripts/utils/log.gd | 39 +++++++++++++++++++++++++++++++++++ test.tscn | 3 +++ 3 files changed, 91 insertions(+) create mode 100644 scripts/utils/log.gd create mode 100644 test.tscn diff --git a/project.godot b/project.godot index d53c797..2f994a3 100644 --- a/project.godot +++ b/project.godot @@ -13,3 +13,52 @@ config_version=5 config/name="Hotel Madness" config/features=PackedStringArray("4.3", "Forward Plus") config/icon="res://icon.svg" + +[autoload] + +Log="*res://scripts/utils/log.gd" + +[debug] + +gdscript/warnings/unassigned_variable=2 +gdscript/warnings/unassigned_variable_op_assign=2 +gdscript/warnings/unused_variable=2 +gdscript/warnings/unused_local_constant=2 +gdscript/warnings/unused_private_class_variable=2 +gdscript/warnings/unused_parameter=2 +gdscript/warnings/unused_signal=2 +gdscript/warnings/shadowed_variable=2 +gdscript/warnings/shadowed_variable_base_class=2 +gdscript/warnings/shadowed_global_identifier=2 +gdscript/warnings/unreachable_code=2 +gdscript/warnings/unreachable_pattern=2 +gdscript/warnings/standalone_expression=2 +gdscript/warnings/standalone_ternary=2 +gdscript/warnings/incompatible_ternary=2 +gdscript/warnings/untyped_declaration=2 +gdscript/warnings/inferred_declaration=2 +gdscript/warnings/unsafe_property_access=2 +gdscript/warnings/unsafe_method_access=2 +gdscript/warnings/unsafe_cast=2 +gdscript/warnings/unsafe_call_argument=2 +gdscript/warnings/unsafe_void_return=2 +gdscript/warnings/return_value_discarded=2 +gdscript/warnings/static_called_on_instance=2 +gdscript/warnings/redundant_static_unload=2 +gdscript/warnings/redundant_await=2 +gdscript/warnings/assert_always_true=2 +gdscript/warnings/assert_always_false=2 +gdscript/warnings/integer_division=2 +gdscript/warnings/narrowing_conversion=2 +gdscript/warnings/int_as_enum_without_cast=2 +gdscript/warnings/int_as_enum_without_match=2 +gdscript/warnings/enum_variable_without_default=2 +gdscript/warnings/empty_file=2 +gdscript/warnings/deprecated_keyword=2 +gdscript/warnings/confusable_identifier=2 +gdscript/warnings/confusable_local_declaration=2 +gdscript/warnings/confusable_local_usage=2 +gdscript/warnings/confusable_capture_reassignment=2 +gdscript/warnings/property_used_as_function=2 +gdscript/warnings/constant_used_as_function=2 +gdscript/warnings/function_used_as_property=2 diff --git a/scripts/utils/log.gd b/scripts/utils/log.gd new file mode 100644 index 0000000..ccf4750 --- /dev/null +++ b/scripts/utils/log.gd @@ -0,0 +1,39 @@ +extends Node + +# This tells the game what the logmode is. +# 0 -> None +# 1 -> Errors +# 2 -> Errors/Warnings +# 3 -> Errors/Warnings/Infos +# 4 -> All +var logmode: int = 4 + +func _ready() -> void: + debug("Test") + info("Test") + warning("Test") + error("Test", "Test Message") + +# Used for errors. +func error(message: String, alert_message: String) -> void: + if logmode >= 1: + printerr("[ERROR] " + message) + OS.alert(alert_message, "Error!") + else: + OS.alert("An error has occured. The program will now exit.", "Error!") + get_tree().quit() + +# Used for warnings. +func warning(message: String) -> void: + if logmode >= 2: + printerr("[WARNING] " + message) + +# Used for simple info. +func info(message: String) -> void: + if logmode >= 3: + print("[INFO] " + message) + +# Used for debugging. +func debug(message: String) -> void: + if logmode >= 4: + print("[DEBUG] " + message) diff --git a/test.tscn b/test.tscn new file mode 100644 index 0000000..453f319 --- /dev/null +++ b/test.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://dhi34ugxtgmlg"] + +[node name="Test" type="Node2D"]