Add automatic cleanup (fixes #25)

This commit is contained in:
JeremyStar™ 2024-04-14 14:23:05 +02:00
parent 12aebc5dd9
commit b05d1428a5
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
3 changed files with 12 additions and 0 deletions

View file

@ -17,6 +17,8 @@ Puts the framework into development mode. \
Unlocks experimental features. Unlocks experimental features.
### *bool* <u>custom_modules</u> = *false* ### *bool* <u>custom_modules</u> = *false*
Allows or disallows custom modules. Allows or disallows custom modules.
### *bool* <u>automatic_shutdown</u> = *true*
If `quit_safely` (and by extension `Core.cleanup`) should be called when pressing the X.
## Logger ## Logger
### *CoreTypes.LoggerLevel* <u>logger_level</u> = *CoreTypes.LoggerLevel.INFO* ### *CoreTypes.LoggerLevel* <u>logger_level</u> = *CoreTypes.LoggerLevel.INFO*

View file

@ -17,6 +17,8 @@ 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
@ -46,6 +48,7 @@ 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

View file

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