Add CoreLoggerInstance variable to CoreBaseModule

This commit is contained in:
JeremyStar™ 2024-03-31 11:22:57 +02:00
parent e2da829970
commit f97fddcb97
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
4 changed files with 13 additions and 7 deletions

View file

@ -30,6 +30,8 @@ var core: Core
## [br]
## Will be set before [method Node._ready]
@onready var logger: CoreBaseModule = core.logger
## Reference to a matching [class CoreLoggerInstance].
var loggeri: CoreLoggerInstance
## Marks a module as fully initialized and ready.
var initialized: bool = false

View file

@ -82,6 +82,7 @@ func cleanup() -> void:
modules_reverse.reverse()
for module in modules_reverse:
await get(module)._cleanup()
get(module).loggeri.queue_free()
get(module).queue_free()
for module in custom_modules_node.get_children(): unregister_custom_module(module.name)
remove_child(custom_modules_node)
@ -98,6 +99,7 @@ func initialize_modules() -> void:
get(module).name = module
get(module).set_script(load(basepath + "src/" + module + ".gd"))
get(module).core = self
get(module).loggeri = logger.get_instance(basepath.replace("res://", "") + "src/" + module + ".gd")
get(module)._initialize()
# Inject modules into the SceneTree
@ -140,7 +142,7 @@ func complete_init(no_success: bool = false) -> void:
# Registers a 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_origin: String, module_class: CoreBaseModule) -> bool:
logger.verbf("Core", "Registering new custom module \"" + module_name + "\"")
if !config.custom_modules:
logger.errorf("Core", "Registering module failed: Custom module support is disabled.")
@ -148,9 +150,10 @@ func register_custom_module(module_name: String, module_class: CoreBaseModule) -
if custom_modules.has(module_name):
logger.errorf("Core", "Registering module failed: A custom module with the name \"" + module_name + "\" already exists.")
return false
module_class.name = module_name
logger.diagf("Core", "Updating variables")
module_class.name = module_name
module_class.core = self
module_class.loggeri = logger.get_instance(module_origin)
logger.diagf("Core", "Adding module to SceneTree")
custom_modules_node.add_child(module_class)
logger.diagf("Core", "Merging module with custom_modules")
@ -170,6 +173,7 @@ func unregister_custom_module(module_name: String) -> void:
return
var module: Node = get_custom_module(module_name)
await module._cleanup()
module.loggeri.queue_free()
custom_modules_node.remove_child(module)
custom_modules.erase(module_name)
module.queue_free()

View file

@ -3,14 +3,14 @@ extends CoreBaseModule
@onready var suite: BessereTestsTest = get_node_or_null("/root/suite_core")
func _initialize() -> void:
logger.info("tests/custom_module.gd", "Module has been initialized")
loggeri.info("Module has been initialized")
suite.callback = "_initialize"
func _cleanup() -> void:
logger.info("tests/custom_module.gd", "Cleaning module")
loggeri.info("Cleaning module")
func _pull_config() -> void:
logger.info("tests/custom_module.gd", "The configuration has been updated")
loggeri.info("The configuration has been updated")
suite.callback = "_pull_config"
func hello_test() -> String:

View file

@ -21,10 +21,10 @@ func test_custom_module_support() -> void:
# Load module
var module: CoreBaseModule = CoreBaseModule.new()
module.set_script(load("res://tests/custom_module.gd"))
module.set_script(load("res://tests/test_resources/custom_module.gd"))
# Register module
core_test.register_custom_module("test_module", module)
core_test.register_custom_module("test_module", "tests/test_resources/custom_module.gd", module)
await wait_process_time()
# Check if registered