Added a simple Logging system and enforced static typing in all files.

This commit is contained in:
Patrick_Pluto 2024-12-03 12:52:14 +01:00
parent 907b338c0e
commit 1607fe62cc
3 changed files with 91 additions and 0 deletions

View file

@ -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

39
scripts/utils/log.gd Normal file
View file

@ -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)

3
test.tscn Normal file
View file

@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://dhi34ugxtgmlg"]
[node name="Test" type="Node2D"]