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 # Inject CORE
await get_tree().process_frame await get_tree().process_frame
add_child(core) add_child(core)
await get_tree().process_frame await core.complete_init()
# Print information about CORE # Print information about CORE
core.logger.info("Test.gd", await core.get_formatted_string("""Version information: core.logger.info("Test.gd", await core.get_formatted_string("""Version information:
Release (semantic) = %release_semantic% Release (semantic) = %release_semantic%

View file

@ -71,7 +71,6 @@ func _ready() -> void:
inject_modules() inject_modules()
custom_modules_node.name = "Custom Modules" custom_modules_node.name = "Custom Modules"
add_child(custom_modules_node) add_child(custom_modules_node)
logger.infof("Core", "Initialized CORE successfully")
# Initialize modules # Initialize modules
## Initializes all modules during the first initialization phase.[br] ## Initializes all modules during the first initialization phase.[br]
@ -126,6 +125,45 @@ func inject_modules() -> void:
add_child(edl) add_child(edl)
add_child(storage) 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 custom module
## Registers a new custom module. ## Registers a new custom module.
func register_custom_module(module_name: String, module_class: CoreBaseModule) -> bool: func register_custom_module(module_name: String, module_class: CoreBaseModule) -> bool:

View file

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

View file

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

View file

@ -30,10 +30,12 @@ var core: Core
## [br] ## [br]
## Will be set before [method Node._ready] ## Will be set before [method Node._ready]
@onready var logger: CoreBaseModule = core.logger @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] ## CORE's replacement for [method Object._init] and [method Node._ready]
## It's [b]strongly[/b] recommended to initialize your module here. ## 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]. ## Called by [method Core.apply_configuration].
## This should be used to update your module configuration. ## This should be used to update your module configuration.
func _pull_config() -> void: pass func _pull_config() -> void: pass