Add 'initialized' var & waiting code

This commit is contained in:
JeremyStar™ 2024-03-22 21:12:11 +01:00
parent a46687590a
commit 05ebb62641
5 changed files with 49 additions and 3 deletions

View file

@ -35,7 +35,7 @@ func _ready() -> void:
# Inject CORE
await get_tree().process_frame
add_child(core)
await get_tree().process_frame
await core.complete_init()
# Print information about CORE
core.logger.info("Test.gd", await core.get_formatted_string("""Version information:
Release (semantic) = %release_semantic%

View file

@ -71,7 +71,6 @@ func _ready() -> void:
inject_modules()
custom_modules_node.name = "Custom Modules"
add_child(custom_modules_node)
logger.infof("Core", "Initialized CORE successfully")
# Initialize modules
## Initializes all modules during the first initialization phase.[br]
@ -126,6 +125,45 @@ func inject_modules() -> void:
add_child(edl)
add_child(storage)
# Wait for all modules to be fully initialized
## Wait for all builtin modules to be fully initialized.[br]
## [br]
## This ensures that all of CORE's builtin modules are fully initialized and ready.
## [b]Not calling this function during startup may lead to runtime issues.[/b]
func complete_init(no_success: bool = false) -> void:
var modsinit_builtin: Array[String] = ["workaround"]
var modsinit_custom: Array[String] = ["workaround"]
while modsinit_builtin.size() != 0 and modsinit_custom.size() != 0:
# Clear arrays
modsinit_builtin = []
modsinit_custom = []
# Check builtin modules
if !logger.initialized: modsinit_builtin.append("logger")
if !misc.initialized: modsinit_builtin.append("misc")
if !sms.initialized: modsinit_builtin.append("sms")
if !logui.initialized: modsinit_builtin.append("logui")
if !edl.initialized: modsinit_builtin.append("edl")
if !storage.initialized: modsinit_builtin.append("storage")
# Check custom modules
for module_name in custom_modules:
if !custom_modules[module_name].initialized: modsinit_custom.append(module_name)
# Print and sleep
if modsinit_builtin.size() != 0 or modsinit_custom.size() != 0:
print("Waiting for modules to finish initialization:")
if modsinit_builtin.size() != 0:
print(" Builtin: " + str(modsinit_builtin))
if modsinit_custom.size() != 0:
print(" Custom: " + str(modsinit_custom))
await get_tree().create_timer(1).timeout
# Initialization complete
await get_tree().process_frame
if !no_success: logger.infof("Core", "Initialized CORE successfully")
# Registers a custom module
## Registers a new custom module.
func register_custom_module(module_name: String, module_class: CoreBaseModule) -> bool:

View file

@ -55,6 +55,9 @@ func _initialize() -> void:
logrtl.add_theme_font_override("bold_font", font_bold)
logrtl.add_theme_font_size_override("normal_font_size", 14)
logrtl.add_theme_font_size_override("bold_font_size", 14)
# Mark as initialized
initialized = true
func _pull_config() -> void:
background.visible = !core.config.headless and core.config.logui_enabled

View file

@ -41,6 +41,9 @@ func _initialize() -> void:
add_child(scenes_menu)
add_child(scenes_cutscene)
add_child(scenes_debug)
# Mark as initialized
initialized = true
func _pull_config() -> void:
if core.config.headless:

View file

@ -30,10 +30,12 @@ var core: Core
## [br]
## Will be set before [method Node._ready]
@onready var logger: CoreBaseModule = core.logger
## Marks a module as fully initialized and ready.
var initialized: bool = false
## CORE's replacement for [method Object._init] and [method Node._ready]
## It's [b]strongly[/b] recommended to initialize your module here.
func _initialize() -> void: pass
func _initialize() -> void: initialized = true
## Called by [method Core.apply_configuration].
## This should be used to update your module configuration.
func _pull_config() -> void: pass