Modify config, custom module support and init
This commit is contained in:
parent
6ec8ec785f
commit
ff0bd01e88
2 changed files with 25 additions and 13 deletions
|
@ -26,8 +26,8 @@ class_name CoreConfiguration
|
|||
|
||||
@export_category("Global")
|
||||
@export var headless: bool
|
||||
@export_category("Debugging")
|
||||
@export var debug_allow: bool
|
||||
@export var debugging: bool
|
||||
@export var custom_modules: bool
|
||||
@export_category("Logger")
|
||||
@export var logger_level: CoreTypes.LoggerLevel
|
||||
@export var logger_colored: bool
|
||||
|
@ -43,8 +43,9 @@ class_name CoreConfiguration
|
|||
func _init() -> void:
|
||||
# Global
|
||||
headless = false
|
||||
# Debugging
|
||||
debug_allow = false
|
||||
debugging = false
|
||||
custom_modules = false
|
||||
|
||||
# Logger
|
||||
logger_level = CoreTypes.LoggerLevel.INFO
|
||||
logger_colored = true
|
||||
|
|
23
src/core.gd
23
src/core.gd
|
@ -57,8 +57,6 @@ func _ready() -> void:
|
|||
custom_modules_node.name = "Custom 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.")
|
||||
|
||||
# Initialize modules
|
||||
func initialize_modules() -> void:
|
||||
|
@ -102,11 +100,14 @@ func inject_modules() -> void:
|
|||
add_child(edl)
|
||||
|
||||
# Registers a custom module
|
||||
func register_custom_module(module_name: String, module_class: CoreBaseModule) -> void:
|
||||
func register_custom_module(module_name: String, module_class: CoreBaseModule) -> bool:
|
||||
logger.verb("Registering new custom module \"" + module_name + "\"")
|
||||
if !config.custom_modules:
|
||||
logger.error("Registering module failed: Custom module support is disabled.")
|
||||
return false
|
||||
if custom_modules.has(module_name):
|
||||
logger.error("Registering module failed: A custom module with the name \"" + module_name + "\" already exists.")
|
||||
return
|
||||
return false
|
||||
module_class.name = module_name
|
||||
logger.diag("Adding module to SceneTree")
|
||||
custom_modules_node.add_child(module_class)
|
||||
|
@ -116,6 +117,7 @@ func register_custom_module(module_name: String, module_class: CoreBaseModule) -
|
|||
module_class._initialize()
|
||||
logger.diag("Updating custom module configuration")
|
||||
module_class._pull_config()
|
||||
return true
|
||||
|
||||
# Unregisters a custom module
|
||||
func unregister_custom_module(module_name: String) -> void:
|
||||
|
@ -147,11 +149,17 @@ func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new(
|
|||
# Call _pull_config() functions
|
||||
func apply_configuration() -> void:
|
||||
logger.verb("Applying configuration")
|
||||
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.")
|
||||
edl._pull_config()
|
||||
if !config.custom_modules:
|
||||
logger.verb("Removing all custom modules (custom modules support is disabled)")
|
||||
for module in custom_modules: unregister_custom_module(module)
|
||||
logger._pull_config()
|
||||
misc._pull_config()
|
||||
sms._pull_config()
|
||||
logui._pull_config()
|
||||
edl._pull_config()
|
||||
if config.custom_modules:
|
||||
for module in custom_modules:
|
||||
logger.diag("Updating configuration for custom module \"" + module.name + "\"")
|
||||
module._pull_config()
|
||||
|
@ -171,7 +179,7 @@ func determine_basepath() -> bool:
|
|||
|
||||
# Return development mode status
|
||||
func is_devmode() -> bool:
|
||||
return config.debug_allow and basepath == "res://" and OS.is_debug_build()
|
||||
return config.debugging and basepath == "res://" and OS.is_debug_build()
|
||||
|
||||
# Replaces variables with human-friendly strings
|
||||
func get_formatted_string(string: String) -> String:
|
||||
|
@ -200,6 +208,9 @@ func get_formatted_string(string: String) -> String:
|
|||
# Headless mode
|
||||
if config.headless: string = string.replace("%headless%", "Enabled")
|
||||
else: string = string.replace("%headless%", "Disabled")
|
||||
# Custom module support
|
||||
if config.custom_modules: string = string.replace("%custommodules%", "Enabled")
|
||||
else: string = string.replace("%custommodules%", "Disabled")
|
||||
return string
|
||||
|
||||
# Return CORE's version in the semantic versioning scheme
|
||||
|
|
Loading…
Reference in a new issue