2
0
Fork 0

Update to e7d0a9d9a68bc29cab9f512ec064b5ca31e1d9ce

This commit is contained in:
JeremyStar™ 2024-04-23 21:35:23 +02:00
parent 99efd65300
commit ea1a361112
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
4 changed files with 127 additions and 43 deletions

View file

@ -24,7 +24,7 @@ class_name CoreTypes
## Available version types, following the StarOpenSource Versioning Specification (SOSVS) version 1. ## Available version types, following the StarOpenSource Versioning Specification (SOSVS) version 1.
enum VersionType { RELEASE, RELEASECANDIDATE, BETA, ALPHA } enum VersionType { RELEASE, RELEASECANDIDATE, BETA, ALPHA }
## Available log levels, followingthe StarOpenSource Logging Specification (SOSLS) version 1. ## 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. ## Available scene types.
enum SceneType { NONE, DEBUG, CUTSCENE, MENU, MAIN, BACKGROUND } enum SceneType { NONE, DEBUG, CUTSCENE, MENU, MAIN, BACKGROUND }
## To what degree [i]something[/i] should be blocked. ## To what degree [i]something[/i] should be blocked.

View file

@ -59,12 +59,21 @@ var storage: CoreBaseModule
var basepath: String var basepath: String
# Contains a list of all registered cleanup hooks. # Contains a list of all registered cleanup hooks.
var cleanup_hooks: Dictionary = {} var cleanup_hooks: Dictionary = {}
## Internal, don't modify.
# Contains a list of all loaded custom modules. # Contains a list of all loaded custom modules.
var custom_modules: Dictionary = {} var custom_modules: Dictionary = {}
## Internal, don't modify.
# Contains the node holding all custom modules as children. # Contains the node holding all custom modules as children.
var custom_modules_node: Node var custom_modules_node: Node
## Internal, don't modify.
# The CORE Object's logger instance. # The CORE Object's logger instance.
var loggeri: CoreLoggerInstance 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 +++ # +++ initialization +++
func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void: func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
@ -86,6 +95,7 @@ func _ready() -> void:
get_tree().auto_accept_quit = false get_tree().auto_accept_quit = false
# Initializes all built-in modules during the preinitialization phase. # Initializes all built-in modules during the preinitialization phase.
## Internal, don't call.
func initialize_modules() -> void: func initialize_modules() -> void:
for module in modules: for module in modules:
set(module, CoreBaseModule.new()) set(module, CoreBaseModule.new())
@ -96,9 +106,11 @@ func initialize_modules() -> void:
get(module)._initialize() get(module)._initialize()
# Injects CORE's builtin modules into the SceneTree. # Injects CORE's builtin modules into the SceneTree.
## Internal, don't call.
func inject_modules() -> void: for module in modules: add_child(get(module)) func inject_modules() -> void: for module in modules: add_child(get(module))
# Initializes the framework scheduler. # Initializes the framework scheduler.
## Internal, don't call.
func initialize_scheduler() -> void: func initialize_scheduler() -> void:
scheduler = Timer.new() scheduler = Timer.new()
scheduler.name = "Scheduler" scheduler.name = "Scheduler"
@ -117,7 +129,7 @@ func initialize_scheduler() -> void:
## [br] ## [br]
## This ensures that all modules are fully initialized and ready for usage.[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] ## [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_builtin: Array[String] = ["workaround"]
var modsinit_custom: Array[String] = ["workaround"] var modsinit_custom: Array[String] = ["workaround"]
@ -142,7 +154,20 @@ func complete_init(no_success_message: bool = false) -> void:
# Initialization complete # Initialization complete
await get_tree().process_frame 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 <https://www.gnu.org/licenses/>.
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 +++ # +++ configuration +++
## Loads a (new) configuration object and applies it to all modules. ## 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() if initialized: apply_configuration()
# Applies a new configuration. # Applies a new configuration.
## Internal, don't call.
func apply_configuration() -> void: func apply_configuration() -> void:
if loggeri != null: loggeri.verb("Applying configuration") 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!") 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() queue_free()
# Generates a new cleanup hook id # Generates a new cleanup hook id
## Internal, don't call.
func _generate_hook_id() -> int: func _generate_hook_id() -> int:
var id = randi() var id = randi()
if cleanup_hooks.has(id): if cleanup_hooks.has(id):
@ -357,7 +384,7 @@ func determine_basepath() -> bool:
elif FileAccess.file_exists("res://addons/CORE/.corebasepath"): elif FileAccess.file_exists("res://addons/CORE/.corebasepath"):
basepath = "res://addons/CORE/" basepath = "res://addons/CORE/"
else: 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 false
return true return true
@ -367,7 +394,7 @@ func check_godot_version() -> bool:
match(version["major"]): match(version["major"]):
4: pass 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 return false
match(version["minor"]): 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.") 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.") printerr("The CORE Framework does not support Godot versions newer than 4.2.x. Please downgrade to Godot 4.2.x.")
return false return false
if version["status"] != "stable": 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 false
return true return true
@ -391,6 +418,7 @@ func quit_safely(exitcode: int = 0) -> void:
get_tree().quit(exitcode) get_tree().quit(exitcode)
# Just ignore this. # Just ignore this.
## Internal, don't call.
func _notification(what) -> void: func _notification(what) -> void:
match(what): match(what):
NOTIFICATION_WM_CLOSE_REQUEST: NOTIFICATION_WM_CLOSE_REQUEST:

View file

@ -101,6 +101,10 @@ func _log(level: CoreTypes.LoggerLevel, origin: String, message: String) -> void
format = format.replace("%level%", "ERR!") format = format.replace("%level%", "ERR!")
format_newline = format_newline.replace("%level%", "ERR!") format_newline = format_newline.replace("%level%", "ERR!")
format = format.replace("%color%", "[color=red]") 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: CoreTypes.LoggerLevel.NONE:
format = format.replace("%level%", "CRSH") format = format.replace("%level%", "CRSH")
format_newline = format_newline.replace("%level%", "CRSH") format_newline = format_newline.replace("%level%", "CRSH")

View file

@ -167,18 +167,35 @@ func stringify_variables(template: String, variables: Dictionary, no_quotes: boo
match(typeof(value)): match(typeof(value)):
# Primitives # Primitives
Variant.Type.TYPE_NIL: replacement = "null" Variant.Type.TYPE_NIL:
Variant.Type.TYPE_BOOL: replacement = str(value) replacement = "null"
Variant.Type.TYPE_INT: replacement = str(value) type = ""
Variant.Type.TYPE_FLOAT: replacement = str(value) Variant.Type.TYPE_BOOL:
Variant.Type.TYPE_STRING: replacement = "\"" + value + "\"" replacement = str(value)
Variant.Type.TYPE_STRING_NAME: replacement = "\"" + 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 # Non-primitives
Variant.Type.TYPE_OBJECT: replacement = str(value) Variant.Type.TYPE_OBJECT:
replacement = str(value)
type = "Object"
Variant.Type.TYPE_COLOR: 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) 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) 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: Variant.Type.TYPE_ARRAY:
if config_stringify_array: if config_stringify_array:
if value.size() == 0: if value.size() == 0:
@ -190,6 +207,10 @@ func stringify_variables(template: String, variables: Dictionary, no_quotes: boo
else: replacement += ", " + _sa(item) else: replacement += ", " + _sa(item)
replacement += " ]" replacement += " ]"
else: replacement = str(value) 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: Variant.Type.TYPE_DICTIONARY:
if config_stringify_dictionary: if config_stringify_dictionary:
if value.size() == 0: replacement = "{}" if value.size() == 0: replacement = "{}"
@ -200,44 +221,75 @@ func stringify_variables(template: String, variables: Dictionary, no_quotes: boo
else: replacement += ", " + _sa(key) else: replacement += ", " + _sa(key)
replacement += " }" replacement += " }"
else: replacement = str(value) else: replacement = str(value)
type = "Dictionary"
# TODO: Packed Arrays # TODO: Packed Arrays
# Nodes & scripting # Nodes & scripting
Variant.Type.TYPE_NODE_PATH: replacement = str(value) Variant.Type.TYPE_NODE_PATH:
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()) replacement = str(value)
Variant.Type.TYPE_SIGNAL: replacement = "name=" + _sa(value.get_name()) + " object=" + _sa(value.get_object()) 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 # 2D
Variant.Type.TYPE_VECTOR2: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) Variant.Type.TYPE_VECTOR2:
Variant.Type.TYPE_VECTOR2I: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) 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) type = "Vector2"
Variant.Type.TYPE_RECT2I: replacement = "size=" + _sa(value.size) + " pos=" + _sa(value.position) + " end=" + _sa(value.end) Variant.Type.TYPE_VECTOR2I:
Variant.Type.TYPE_TRANSFORM2D: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " origin=" + _sa(value.origin) 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 # 3D
Variant.Type.TYPE_VECTOR3: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) Variant.Type.TYPE_VECTOR3:
Variant.Type.TYPE_VECTOR3I: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) 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) type = "Vector3"
Variant.Type.TYPE_QUATERNION: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) Variant.Type.TYPE_VECTOR3I:
Variant.Type.TYPE_AABB: replacement = "size=" + _sa(value.size) + " pos=" + _sa(value.position) + " end=" + _sa(value.end) replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z)
Variant.Type.TYPE_TRANSFORM3D: replacement = "basis=" + _sa(value.basis) + " origin=" + _sa(value.origin) type = "Vector3i"
Variant.Type.TYPE_BASIS: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) Variant.Type.TYPE_PLANE:
Variant.Type.TYPE_PROJECTION: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) 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 # 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_VECTOR4:
Variant.Type.TYPE_VECTOR4I: replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w) replacement = "x=" + _sa(value.x) + " y=" + _sa(value.y) + " z=" + _sa(value.z) + " w=" + _sa(value.w)
# etc type = "Vector4"
Variant.Type.TYPE_MAX: replacement = str(value) 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) replacement = str(value)
type = "(unknown) " type = "unknown"
# Replace # Replace
if config_stringify_show_type and type == "": if config_stringify_show_type:
match(typeof(value)): if type != "": type = "(" + type.to_lower() + ") "
Variant.Type.TYPE_NIL: type = "" else:
Variant.Type.TYPE_MAX: type = "(invalid) " type = ""
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.
var quote: String = "'" if !no_quotes else "" var quote: String = "'" if !no_quotes else ""
template = template.replace("%" + placeholder + "%", quote + type + replacement + quote) template = template.replace("%" + placeholder + "%", quote + type + replacement + quote)
return template return template