From b37e4d98ae0ee8183f681ce3342241e167c14895 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Mon, 8 Apr 2024 21:42:03 +0200 Subject: [PATCH] Move quit_safely() method into Core --- docs/docs/reference/core.md | 6 ++++++ docs/docs/reference/misc.md | 6 ++++-- docs/docs/terminology.md | 2 +- src/core.gd | 9 +++++++++ src/logger.gd | 2 +- src/misc.gd | 11 +++-------- 6 files changed, 24 insertions(+), 12 deletions(-) diff --git a/docs/docs/reference/core.md b/docs/docs/reference/core.md index cef3508..8832658 100644 --- a/docs/docs/reference/core.md +++ b/docs/docs/reference/core.md @@ -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* quit_safely(*int* exitcode = *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. diff --git a/docs/docs/reference/misc.md b/docs/docs/reference/misc.md index 4fff9af..2a6ad86 100644 --- a/docs/docs/reference/misc.md +++ b/docs/docs/reference/misc.md @@ -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* byte2mib(*int* bytes, *bool* flatten = *true*) Converts a number of bytes into mebibytes. diff --git a/docs/docs/terminology.md b/docs/docs/terminology.md index aadf03e..3f33e0c 100644 --- a/docs/docs/terminology.md +++ b/docs/docs/terminology.md @@ -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**. \ No newline at end of file +Stands for **Custom Module Support**. diff --git a/src/core.gd b/src/core.gd index a2ca9f8..b23951a 100644 --- a/src/core.gd +++ b/src/core.gd @@ -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) diff --git a/src/logger.gd b/src/logger.gd index fdcc069..c1d8231 100644 --- a/src/logger.gd +++ b/src/logger.gd @@ -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. diff --git a/src/misc.gd b/src/misc.gd index 4b2c9ea..dc9e120 100644 --- a/src/misc.gd +++ b/src/misc.gd @@ -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)