2
0
Fork 0

Update to 2e9cce8f27651b3a334a58c7ca8122257dcb335c

This commit is contained in:
JeremyStar™ 2024-04-14 15:09:27 +02:00
parent e2e69764f7
commit e31309e347
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
3 changed files with 31 additions and 4 deletions

View file

@ -17,11 +17,19 @@ class_name CoreConfiguration
@export var development: bool @export var development: bool
## Allows or disallows custom modules. ## Allows or disallows custom modules.
@export var custom_modules: bool @export var custom_modules: bool
## If [method Core.quit_safely] (and by extension [method Core.cleanup]) should be called when pressing the X.
@export var automatic_shutdown: bool
@export_category("Logger") @export_category("Logger")
## The minimum log level you want to be displayed. ## The minimum log level you want to be displayed.
@export var logger_level: CoreTypes.LoggerLevel @export var logger_level: CoreTypes.LoggerLevel
## Determines if the logger's output should be colored. ## Determines if the logger's output should be colored.
@export var logger_colored: bool @export var logger_colored: bool
## Determines if the logger should check if running in verbose mode (see [method OS.is_stdout_verbose]).[br]
## Comes with a huge performance penalty on startup, delaying startup by about one to two seconds.[br]
## Update [code]verbose_mode[/code] accordingly yourself if you've disabled this, or diagnostic log messages might appear messed up.[br]
## [b]Warning: [i]Updating this during runtime does nothing.[/i][/b]
@export var logger_detect_verbose_mode: bool
## The template for all log messages.[br] ## The template for all log messages.[br]
## Available placeholders are: [code]%time%[/code], [code]%time_ms%[/code], [code]%level%[/code], [code]%color%[/code], [code]%message%[/code], [code]%source%[/code], [code]%source_raw%[/code], [code]%function%[/code] and [code]%line%[/code] ## Available placeholders are: [code]%time%[/code], [code]%time_ms%[/code], [code]%level%[/code], [code]%color%[/code], [code]%message%[/code], [code]%source%[/code], [code]%source_raw%[/code], [code]%function%[/code] and [code]%line%[/code]
@export var logger_format: String @export var logger_format: String
@ -29,6 +37,7 @@ class_name CoreConfiguration
@export var logger_newlines_override: bool @export var logger_newlines_override: bool
## The maximum amount of characters excluding the message before newlines are no longer idented. Set to [code]-1[/code] to disable this behaviour. ## The maximum amount of characters excluding the message before newlines are no longer idented. Set to [code]-1[/code] to disable this behaviour.
@export var logger_newlines_sizelimit: int @export var logger_newlines_sizelimit: int
@export_category("Log UI") @export_category("Log UI")
## Enables or disables Log UI. ## Enables or disables Log UI.
@export var logui_enabled: bool @export var logui_enabled: bool
@ -46,10 +55,12 @@ func _init() -> void:
headless = false headless = false
development = false development = false
custom_modules = false custom_modules = false
automatic_shutdown = true
# Logger # Logger
logger_level = CoreTypes.LoggerLevel.INFO logger_level = CoreTypes.LoggerLevel.INFO
logger_colored = true logger_colored = true
logger_detect_verbose_mode = false
logger_format = "%color%[%time%] [%level% %origin%] %message%" logger_format = "%color%[%time%] [%level% %origin%] %message%"
logger_newlines_override = true logger_newlines_override = true
logger_newlines_sizelimit = 40 logger_newlines_sizelimit = 40

View file

@ -26,9 +26,9 @@ class_name Core
## The version number ## The version number
const version_version: int = 1 const version_version: int = 1
## The version type. See [enum CoreTypes.VersionType] for more information. ## The version type. See [enum CoreTypes.VersionType] for more information.
const version_type: CoreTypes.VersionType = CoreTypes.VersionType.RELEASECANDIDATE const version_type: CoreTypes.VersionType = CoreTypes.VersionType.RELEASE
## The version type number. Resets on every new version and version type. ## The version type number. Resets on every new version and version type.
const version_typerelease: int = 1 const version_typerelease: int = 0
# Modules # Modules
## Used internally for loading, managing and unloading modules. ## Used internally for loading, managing and unloading modules.
@ -87,6 +87,7 @@ func _ready() -> void:
add_child(custom_modules_node) add_child(custom_modules_node)
loggeri = logger.get_instance(basepath.replace("res://", "") + "src/core.gd", self) loggeri = logger.get_instance(basepath.replace("res://", "") + "src/core.gd", self)
add_child(scheduler) add_child(scheduler)
get_tree().auto_accept_quit = false
## Initializes all built-in modules during the preinitialization phase.[br] ## Initializes all built-in modules during the preinitialization phase.[br]
## [b]Danger: [i]Don't call this.[/i][/b] ## [b]Danger: [i]Don't call this.[/i][/b]
@ -142,7 +143,7 @@ func complete_init(no_success_message: bool = false) -> void:
# Print and sleep # Print and sleep
if modsinit_builtin.size() != 0 or modsinit_custom.size() != 0: if modsinit_builtin.size() != 0 or modsinit_custom.size() != 0:
print("Waiting for modules to finish initialization:") print("Waiting for modules to finish initialization:")
if modsinit_builtin.size() != 0: print(" Builtin: " + str(modsinit_builtin)) if modsinit_builtin.size() != 0: print(" Built-in: " + str(modsinit_builtin))
if modsinit_custom.size() != 0: print(" Custom: " + str(modsinit_custom)) if modsinit_custom.size() != 0: print(" Custom: " + str(modsinit_custom))
await get_tree().create_timer(1).timeout await get_tree().create_timer(1).timeout
@ -338,3 +339,9 @@ func quit_safely(exitcode: int = 0) -> void:
await get_tree().create_timer(0.25).timeout await get_tree().create_timer(0.25).timeout
await cleanup() await cleanup()
get_tree().quit(exitcode) get_tree().quit(exitcode)
func _notification(what) -> void:
match(what):
NOTIFICATION_WM_CLOSE_REQUEST:
if config.automatic_shutdown:
await quit_safely(0)

View file

@ -28,6 +28,10 @@ signal log_event
## [b]Danger: [i]Don't modify this.[/i][/b] ## [b]Danger: [i]Don't modify this.[/i][/b]
var instances: Array[CoreLoggerInstance] = [] var instances: Array[CoreLoggerInstance] = []
## Used to determine if running in verbose/command line mode.[br]
## Makes diagnostic log messages display correctly (workaround for Godot's ANSI true color limitation).
var verbose_mode: bool = false
## The minimum log level you want to be displayed. ## The minimum log level you want to be displayed.
var config_level: CoreTypes.LoggerLevel var config_level: CoreTypes.LoggerLevel
## Determines if the logger's output should be colored. ## Determines if the logger's output should be colored.
@ -41,6 +45,10 @@ var config_newlines_override: bool
var config_newlines_sizelimit: int var config_newlines_sizelimit: int
# +++ module +++ # +++ module +++
func _initialize() -> void:
if core.config.logger_detect_verbose_mode and OS.is_stdout_verbose():
verbose_mode = true
func _cleanup() -> void: func _cleanup() -> void:
_schedule() _schedule()
await get_tree().process_frame await get_tree().process_frame
@ -77,7 +85,8 @@ func _log(level: CoreTypes.LoggerLevel, origin: String, message: String) -> void
CoreTypes.LoggerLevel.DIAG: CoreTypes.LoggerLevel.DIAG:
format = format.replace("%level%", "DIAG") format = format.replace("%level%", "DIAG")
format_newline = format_newline.replace("%level%", "DIAG") format_newline = format_newline.replace("%level%", "DIAG")
format = format.replace("%color%", "[color=dark_gray]") if verbose_mode: format = format.replace("%color%", "[color=gray]")
else: format = format.replace("%color%", "[color=dark_gray]")
CoreTypes.LoggerLevel.VERB: CoreTypes.LoggerLevel.VERB:
format = format.replace("%level%", "VERB") format = format.replace("%level%", "VERB")
format_newline = format_newline.replace("%level%", "VERB") format_newline = format_newline.replace("%level%", "VERB")