Move quit_safely() method into Core

This commit is contained in:
JeremyStar™ 2024-04-08 21:42:03 +02:00
parent 62602416d3
commit b37e4d98ae
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
6 changed files with 24 additions and 12 deletions

View file

@ -115,3 +115,9 @@ Returns the CORE version in the semantic versioning scheme. The first integer co
Do not call this.
:::
Determines CORE's installation/base path.
### *void* <u>quit_safely</u>(*int* <u>exitcode</u> = *0*)
:::note[Awaiting required]
Using the `await` keyword is required for this function.
:::
Makes sure for all log messages to be flushed and that CORE is correctly cleaned up.
Using `get_tree().quit()` directly may cause various issues.

View file

@ -12,8 +12,10 @@ This module contains many methods that don't fit into any other module and gener
:::note[Awaiting required]
Using the `await` keyword is required for this function.
:::
Makes sure for all log messages to be flushed and that CORE is correctly cleaned up.
Using `get_tree().quit()` directly may cause various issues.
:::warning[Deprecated]
This method has been deprecated and should no longer be used.
:::
Moved to `Core.quit_safely`.
### *float* <u>byte2mib</u>(*int* <u>bytes</u>, *bool* flatten = *true*)
Converts a number of bytes into mebibytes.

View file

@ -22,4 +22,4 @@ The old name for the [`ERM`](#erm) module. Stood for `Easy DownLoader`.
No, it does not stand for **Short Message Service**, but for **Scene Management System**. It manages your scenes.
## CMS
Stands for **Custom Module Support**.
Stands for **Custom Module Support**.

View file

@ -309,3 +309,12 @@ func check_godot_version() -> bool:
printerr("The CORE Framework does not support unstable Godot versions. Please switch to Godot stable 4.2.x.")
return false
return true
## Makes sure for all log messages to be flushed and that CORE is correctly cleaned up.[br]
## Using [method SceneTree.quit] directly may cause various issues.[br]
## [b]Note: [i]Using the [code]await[/code] keyword is required for this function.[/i][/b]
func quit_safely(exitcode: int = 0) -> void:
loggeri.info("Shutting down (code " + str(exitcode) + ")")
await get_tree().create_timer(0.25).timeout
await cleanup()
get_tree().quit(exitcode)

View file

@ -194,7 +194,7 @@ STACKTRACE
# Print crash message
_log(CoreTypes.LoggerLevel.NONE, origin, crash_message)
# Shutdown
await core.misc.quit_safely(69)
await core.quit_safely(69)
# +++ etc +++
## Checks if the specified log level is allowed by the current configuration.

View file

@ -125,11 +125,6 @@ func stringarray_to_array(array: Array[String]) -> Array:
func get_center(parent_size: Vector2, child_size: Vector2) -> Vector2:
return Vector2(parent_size.x/2-child_size.x/2, parent_size.y/2-child_size.y/2)
## Makes sure for all log messages to be flushed and that CORE is correctly cleaned up.[br]
## Using [method SceneTree.quit] directly may cause various issues.[br]
## [b]Note: [i]Using the [code]await[/code] keyword is required for this function.[/i][/b]
func quit_safely(exitcode: int = 0) -> void:
loggeri.info("Shutting down (code " + str(exitcode) + ")")
await get_tree().create_timer(0.25).timeout
await core.cleanup()
get_tree().quit(exitcode)
## Moved to [method Core.quit_safely].
## @deprecated
func quit_safely(exitcode: int = 0) -> void: await core.quit_safely(exitcode)