Improve custom modules support
This commit is contained in:
parent
9c9c72e4ce
commit
645a4ba981
1 changed files with 16 additions and 1 deletions
17
src/core.gd
17
src/core.gd
|
@ -38,11 +38,13 @@ var logui: CoreBaseModule
|
|||
var basepath: String
|
||||
var config: CoreConfiguration
|
||||
var custom_modules: Dictionary = {}
|
||||
var custom_modules_node: Node
|
||||
|
||||
# Preinitialization
|
||||
func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
|
||||
name = "CORE"
|
||||
if !determine_basepath(): queue_free()
|
||||
custom_modules_node = Node.new()
|
||||
reload_configuration(new_config)
|
||||
initialize_modules()
|
||||
apply_configuration()
|
||||
|
@ -50,6 +52,7 @@ func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
|
|||
# Initialization
|
||||
func _ready() -> void:
|
||||
inject_modules()
|
||||
add_child(custom_modules_node)
|
||||
logger.info("Initialized CORE successfully")
|
||||
if is_devmode(): logger.warn("The CORE Framework is in development mode. Here be dragons!")
|
||||
if config.headless: logger.warn("CORE is in headless mode. Certain modules will not work as expected.")
|
||||
|
@ -89,8 +92,14 @@ func register_custom_module(module_name: String, module_class: CoreBaseModule) -
|
|||
if custom_modules.has(module_name):
|
||||
logger.error("Registering module failed: A custom module with the name \"" + module_name + "\" already exists.")
|
||||
return
|
||||
module_class.name = module_name
|
||||
logger.diag("Adding module to SceneTree")
|
||||
custom_modules_node.add_child(module_class)
|
||||
logger.diag("Merging module with custom_modules")
|
||||
custom_modules.merge({ module_name: module_class })
|
||||
logger.diag("Initializing custom module")
|
||||
module_class._initialize()
|
||||
logger.diag("Updating custom module configuration")
|
||||
module_class._pull_config()
|
||||
|
||||
# Unregisters a custom module
|
||||
|
@ -99,6 +108,7 @@ func unregister_custom_module(module_name: String) -> void:
|
|||
if !custom_modules.has(module_name):
|
||||
logger.error("Unregistering module failed: A custom module with the name \"" + module_name + "\" does not exist.")
|
||||
return
|
||||
custom_modules_node.remove_child(get_custom_module(module_name))
|
||||
custom_modules.erase(module_name)
|
||||
|
||||
# Returns a custom module
|
||||
|
@ -112,17 +122,22 @@ func get_custom_module(module_name: String) -> CoreBaseModule:
|
|||
# (Re-)Load configuration
|
||||
func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
|
||||
var initialized = config != null
|
||||
if initialized: logger.info("Reloading CORE's configuration")
|
||||
if initialized: logger.verb("Reloading CORE's configuration")
|
||||
config = new_config
|
||||
if is_devmode(): # Override configuration in development mode
|
||||
config.logger_level = CoreTypes.LoggerLevel.VERB
|
||||
if initialized: logger.verb("Overrode configuration (development mode)")
|
||||
if initialized: apply_configuration()
|
||||
|
||||
# Call _pull_config() functions
|
||||
func apply_configuration() -> void:
|
||||
logger.verb("Applying configuration")
|
||||
logger._pull_config()
|
||||
misc._pull_config()
|
||||
logui._pull_config()
|
||||
for module in custom_modules:
|
||||
logger.diag("Updating configuration for custom module \"" + module.name + "\"")
|
||||
module._pull_config()
|
||||
|
||||
# Determines CORE's installation/base path
|
||||
func determine_basepath() -> bool:
|
||||
|
|
Loading…
Reference in a new issue