From ea1a361112ba16b7da6759a5811a1864e177c874 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 23 Apr 2024 21:35:23 +0200 Subject: [PATCH] Update to e7d0a9d9a68bc29cab9f512ec064b5ca31e1d9ce --- src/classes/types.gd | 2 +- src/core.gd | 38 +++++++++++-- src/logger.gd | 4 ++ src/misc.gd | 126 ++++++++++++++++++++++++++++++------------- 4 files changed, 127 insertions(+), 43 deletions(-) diff --git a/src/classes/types.gd b/src/classes/types.gd index 4d083da..d6fa67c 100644 --- a/src/classes/types.gd +++ b/src/classes/types.gd @@ -24,7 +24,7 @@ class_name CoreTypes ## Available version types, following the StarOpenSource Versioning Specification (SOSVS) version 1. enum VersionType { RELEASE, RELEASECANDIDATE, BETA, ALPHA } ## Available log levels, followingthe StarOpenSource Logging Specification (SOSLS) version 1. -enum LoggerLevel { NONE, ERROR, WARN, INFO, VERB, DIAG } +enum LoggerLevel { NONE, SPECIAL, ERROR, WARN, INFO, VERB, DIAG } ## Available scene types. enum SceneType { NONE, DEBUG, CUTSCENE, MENU, MAIN, BACKGROUND } ## To what degree [i]something[/i] should be blocked. diff --git a/src/core.gd b/src/core.gd index 37c6a6c..c25a1eb 100644 --- a/src/core.gd +++ b/src/core.gd @@ -59,12 +59,21 @@ var storage: CoreBaseModule var basepath: String # Contains a list of all registered cleanup hooks. var cleanup_hooks: Dictionary = {} +## Internal, don't modify. # Contains a list of all loaded custom modules. var custom_modules: Dictionary = {} +## Internal, don't modify. # Contains the node holding all custom modules as children. var custom_modules_node: Node +## Internal, don't modify. # The CORE Object's logger instance. var loggeri: CoreLoggerInstance +## Internal, don't modify. +# Makes CORE inaccessible if true. +var disabled: bool = false +## Internal, don't modify. +# Displays the ✨ special ✨ welcome message if true +var welcomed: bool = false # +++ initialization +++ func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void: @@ -86,6 +95,7 @@ func _ready() -> void: get_tree().auto_accept_quit = false # Initializes all built-in modules during the preinitialization phase. +## Internal, don't call. func initialize_modules() -> void: for module in modules: set(module, CoreBaseModule.new()) @@ -96,9 +106,11 @@ func initialize_modules() -> void: get(module)._initialize() # Injects CORE's builtin modules into the SceneTree. +## Internal, don't call. func inject_modules() -> void: for module in modules: add_child(get(module)) # Initializes the framework scheduler. +## Internal, don't call. func initialize_scheduler() -> void: scheduler = Timer.new() scheduler.name = "Scheduler" @@ -117,7 +129,7 @@ func initialize_scheduler() -> void: ## [br] ## This ensures that all modules are fully initialized and ready for usage.[br] ## [i][b]Not calling this function during startup may lead to runtime issues.[/b][/i] -func complete_init(no_success_message: bool = false) -> void: +func complete_init() -> void: var modsinit_builtin: Array[String] = ["workaround"] var modsinit_custom: Array[String] = ["workaround"] @@ -142,7 +154,20 @@ func complete_init(no_success_message: bool = false) -> void: # Initialization complete await get_tree().process_frame - if !no_success_message: loggeri.info("Initialized CORE successfully") + if !welcomed: + welcomed = true + logger._log(CoreTypes.LoggerLevel.SPECIAL, basepath.replace("res://", "") + "src/core.gd", """_________________________________ __________ ______ +__ ____/_ __ \\__ __ \\__ ____/ ___ ____/____________ _______ ___________ _________________ /__ +_ / _ / / /_ /_/ /_ __/ __ /_ __ ___/ __ `/_ __ `__ \\ _ \\_ | /| / / __ \\_ ___/_ //_/ +/ /___ / /_/ /_ _, _/_ /___ _ __/ _ / / /_/ /_ / / / / / __/_ |/ |/ // /_/ / / _ ,< +\\____/ \\____/ /_/ |_| /_____/ /_/ /_/ \\__,_/ /_/ /_/ /_/\\___/____/|__/ \\____//_/ /_/|_| +Copyright (c) 2023-2024 The StarOpenSource Project & Contributors. +Licensed under the GNU Affero General Public License v3 WITHOUT ANY WARRANTY. +You should have recieved a copy of the GNU Affero General Public License +along with this program. If not, see . + +Consider contributing to the CORE Framework to make it even better... and remember: #TransRightsAreHumanRights +Thank you for using the CORE Framework to develop your application or game!""") # +++ configuration +++ ## Loads a (new) configuration object and applies it to all modules. @@ -157,6 +182,7 @@ func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new( if initialized: apply_configuration() # Applies a new configuration. +## Internal, don't call. func apply_configuration() -> void: if loggeri != null: loggeri.verb("Applying configuration") if is_devmode() and loggeri != null: loggeri.warn("The CORE Framework is in development mode. Here be dragons!") @@ -249,6 +275,7 @@ func cleanup() -> void: queue_free() # Generates a new cleanup hook id +## Internal, don't call. func _generate_hook_id() -> int: var id = randi() if cleanup_hooks.has(id): @@ -357,7 +384,7 @@ func determine_basepath() -> bool: elif FileAccess.file_exists("res://addons/CORE/.corebasepath"): basepath = "res://addons/CORE/" else: - assert(false, "CORE is not located at 'res://CORE/', aborting initialization") + printerr("CORE is not located at 'res://CORE/' or 'res://addons/CORE', aborting initialization.") return false return true @@ -367,7 +394,7 @@ func check_godot_version() -> bool: match(version["major"]): 4: pass _: - printerr("The CORE Framework does not support Godot versions older or newer than 4.x.x") + printerr("The CORE Framework does not support Godot versions older or newer than 4.x.x.") return false match(version["minor"]): 0: printerr("The CORE Framework does not support Godot versions older than 4.2.x. Please update to Godot 4.2.x to ensure full compatibility.") @@ -377,7 +404,7 @@ func check_godot_version() -> bool: printerr("The CORE Framework does not support Godot versions newer than 4.2.x. Please downgrade to Godot 4.2.x.") return false if version["status"] != "stable": - printerr("The CORE Framework does not support unstable Godot versions. Please switch to Godot stable 4.2.x.") + printerr("The CORE Framework does not support unstable Godot versions. Please switch to Godot 4.2.x.stable to ensure full compatibility.") return false return true @@ -391,6 +418,7 @@ func quit_safely(exitcode: int = 0) -> void: get_tree().quit(exitcode) # Just ignore this. +## Internal, don't call. func _notification(what) -> void: match(what): NOTIFICATION_WM_CLOSE_REQUEST: diff --git a/src/logger.gd b/src/logger.gd index 5631d13..37e1062 100644 --- a/src/logger.gd +++ b/src/logger.gd @@ -101,6 +101,10 @@ func _log(level: CoreTypes.LoggerLevel, origin: String, message: String) -> void format = format.replace("%level%", "ERR!") format_newline = format_newline.replace("%level%", "ERR!") format = format.replace("%color%", "[color=red]") + CoreTypes.LoggerLevel.SPECIAL: + format = format.replace("%level%", "UWU!") + format_newline = format_newline.replace("%level%", "HI:3") + format = format.replace("%color%", "[color=purple]") CoreTypes.LoggerLevel.NONE: format = format.replace("%level%", "CRSH") format_newline = format_newline.replace("%level%", "CRSH") diff --git a/src/misc.gd b/src/misc.gd index b14988b..b2bc7f4 100644 --- a/src/misc.gd +++ b/src/misc.gd @@ -167,18 +167,35 @@ func stringify_variables(template: String, variables: Dictionary, no_quotes: boo match(typeof(value)): # Primitives - Variant.Type.TYPE_NIL: replacement = "null" - Variant.Type.TYPE_BOOL: replacement = str(value) - Variant.Type.TYPE_INT: replacement = str(value) - Variant.Type.TYPE_FLOAT: replacement = str(value) - Variant.Type.TYPE_STRING: replacement = "\"" + value + "\"" - Variant.Type.TYPE_STRING_NAME: replacement = "\"" + value + "\"" + Variant.Type.TYPE_NIL: + replacement = "null" + type = "" + Variant.Type.TYPE_BOOL: + replacement = str(value) + type = "bool" + Variant.Type.TYPE_INT: + replacement = str(value) + type = "int" + Variant.Type.TYPE_FLOAT: + replacement = str(value) + type = "float" + Variant.Type.TYPE_STRING: + replacement = "\"" + value + "\"" + type = "String" + Variant.Type.TYPE_STRING_NAME: + replacement = "\"" + value + "\"" + type = "StringName" # Non-primitives - Variant.Type.TYPE_OBJECT: replacement = str(value) + Variant.Type.TYPE_OBJECT: + replacement = str(value) + type = "Object" Variant.Type.TYPE_COLOR: if config_stringify_color_range8: replacement = "r=" + _sa(value.r8) + " g=" + _sa(value.g8) + " b=" + _sa(value.b8) + " a=" + _sa(value.a8) else: replacement = "r=" + _sa(value.r) + " g=" + _sa(value.g) + " b=" + _sa(value.b) + " a=" + _sa(value.a) - Variant.Type.TYPE_RID: replacement = "id=" + _sa(value.get_id()) + " valid=" + _sa(value.is_valid()) + type = "Color" + Variant.Type.TYPE_RID: + replacement = "id=" + _sa(value.get_id()) + " valid=" + _sa(value.is_valid()) + type = "RID" Variant.Type.TYPE_ARRAY: if config_stringify_array: if value.size() == 0: @@ -190,6 +207,10 @@ func stringify_variables(template: String, variables: Dictionary, no_quotes: boo else: replacement += ", " + _sa(item) replacement += " ]" else: replacement = str(value) + if value.get_typed_builtin() != TYPE_NIL: + type = "Array[" + type_string(typeof(value.get_typed_builtin())) + "]" + else: + type = "Array" Variant.Type.TYPE_DICTIONARY: if config_stringify_dictionary: if value.size() == 0: replacement = "{}" @@ -200,44 +221,75 @@ func stringify_variables(template: String, variables: Dictionary, no_quotes: boo else: replacement += ", " + _sa(key) replacement += " }" else: replacement = str(value) + type = "Dictionary" # TODO: Packed Arrays # Nodes & scripting - Variant.Type.TYPE_NODE_PATH: replacement = str(value) - Variant.Type.TYPE_CALLABLE: replacement = "valid=" + _sa(value.is_valid()) + " standard=" + _sa(value.is_standard()) + " object=" + _sa(value.get_object() ) + " method=" + value.get_method() + " args=" + _sa(value.get_bound_arguments()) - Variant.Type.TYPE_SIGNAL: replacement = "name=" + _sa(value.get_name()) + " object=" + _sa(value.get_object()) + Variant.Type.TYPE_NODE_PATH: + replacement = str(value) + type = "NodePath" + Variant.Type.TYPE_CALLABLE: + replacement = "valid=" + _sa(value.is_valid()) + " standard=" + _sa(value.is_standard()) + " object=" + _sa(value.get_object() ) + " method=" + value.get_method() + " args=" + _sa(value.get_bound_arguments()) + type = "Callable" + Variant.Type.TYPE_SIGNAL: + replacement = "name=" + _sa(value.get_name()) + " object=" + _sa(value.get_object()) + type = "Signal" # 2D - Variant.Type.TYPE_VECTOR2: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) - Variant.Type.TYPE_VECTOR2I: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) - Variant.Type.TYPE_RECT2: replacement = "size=" + _sa(value.size) + " pos=" + _sa(value.position) + " end=" + _sa(value.end) - Variant.Type.TYPE_RECT2I: replacement = "size=" + _sa(value.size) + " pos=" + _sa(value.position) + " end=" + _sa(value.end) - Variant.Type.TYPE_TRANSFORM2D: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " origin=" + _sa(value.origin) + Variant.Type.TYPE_VECTOR2: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + type = "Vector2" + Variant.Type.TYPE_VECTOR2I: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + type = "Vector2i" + Variant.Type.TYPE_RECT2: + replacement = "size=" + _sa(value.size) + " pos=" + _sa(value.position) + " end=" + _sa(value.end) + type = "Rect2" + Variant.Type.TYPE_RECT2I: + replacement = "size=" + _sa(value.size) + " pos=" + _sa(value.position) + " end=" + _sa(value.end) + type = "Rect2i" + Variant.Type.TYPE_TRANSFORM2D: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " origin=" + _sa(value.origin) + type = "Transform2D" # 3D - Variant.Type.TYPE_VECTOR3: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) - Variant.Type.TYPE_VECTOR3I: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) - Variant.Type.TYPE_PLANE: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " d=" + _sa(value.d) + " normal=" + _sa(value.normal) - Variant.Type.TYPE_QUATERNION: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) - Variant.Type.TYPE_AABB: replacement = "size=" + _sa(value.size) + " pos=" + _sa(value.position) + " end=" + _sa(value.end) - Variant.Type.TYPE_TRANSFORM3D: replacement = "basis=" + _sa(value.basis) + " origin=" + _sa(value.origin) - Variant.Type.TYPE_BASIS: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) - Variant.Type.TYPE_PROJECTION: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) + Variant.Type.TYPE_VECTOR3: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + type = "Vector3" + Variant.Type.TYPE_VECTOR3I: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + type = "Vector3i" + Variant.Type.TYPE_PLANE: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " d=" + _sa(value.d) + " normal=" + _sa(value.normal) + type = "Plane" + Variant.Type.TYPE_QUATERNION: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) + type = "Quaternion" + Variant.Type.TYPE_AABB: + replacement = "size=" + _sa(value.size) + " pos=" + _sa(value.position) + " end=" + _sa(value.end) + type = "AABB" + Variant.Type.TYPE_TRANSFORM3D: + replacement = "basis=" + _sa(value.basis) + " origin=" + _sa(value.origin) + type = "Transform3D" + Variant.Type.TYPE_BASIS: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + type = "Basis" + Variant.Type.TYPE_PROJECTION: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) + type = "Projection" # 4D - Variant.Type.TYPE_VECTOR4: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) - Variant.Type.TYPE_VECTOR4I: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) - # etc - Variant.Type.TYPE_MAX: replacement = str(value) + Variant.Type.TYPE_VECTOR4: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) + type = "Vector4" + Variant.Type.TYPE_VECTOR4I: + replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) + type = "Vector4i" _: replacement = str(value) - type = "(unknown) " + type = "unknown" # Replace - if config_stringify_show_type and type == "": - match(typeof(value)): - Variant.Type.TYPE_NIL: type = "" - Variant.Type.TYPE_MAX: type = "(invalid) " - Variant.Type.TYPE_ARRAY: - if value.get_typed_builtin() != TYPE_NIL: - type = "(" + type_string(typeof(value)).to_lower() + "[" + type_string(typeof(value.get_typed_builtin())).to_lower() + "]) " - _: type = "(" + type_string(typeof(value)).to_lower() + ") " # something is causing almost everything to be displayed as a boolean, which is not true. i don't know what's the problem here however. + if config_stringify_show_type: + if type != "": type = "(" + type.to_lower() + ") " + else: + type = "" var quote: String = "'" if !no_quotes else "" template = template.replace("%" + placeholder + "%", quote + type + replacement + quote) return template