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_category("Global")
|
||||||
@export var headless: bool
|
@export var headless: bool
|
||||||
@export_category("Debugging")
|
@export var debugging: bool
|
||||||
@export var debug_allow: bool
|
@export var custom_modules: bool
|
||||||
@export_category("Logger")
|
@export_category("Logger")
|
||||||
@export var logger_level: CoreTypes.LoggerLevel
|
@export var logger_level: CoreTypes.LoggerLevel
|
||||||
@export var logger_colored: bool
|
@export var logger_colored: bool
|
||||||
|
@ -43,8 +43,9 @@ class_name CoreConfiguration
|
||||||
func _init() -> void:
|
func _init() -> void:
|
||||||
# Global
|
# Global
|
||||||
headless = false
|
headless = false
|
||||||
# Debugging
|
debugging = false
|
||||||
debug_allow = false
|
custom_modules = false
|
||||||
|
|
||||||
# Logger
|
# Logger
|
||||||
logger_level = CoreTypes.LoggerLevel.INFO
|
logger_level = CoreTypes.LoggerLevel.INFO
|
||||||
logger_colored = true
|
logger_colored = true
|
||||||
|
|
29
src/core.gd
29
src/core.gd
|
@ -57,8 +57,6 @@ func _ready() -> void:
|
||||||
custom_modules_node.name = "Custom Modules"
|
custom_modules_node.name = "Custom Modules"
|
||||||
add_child(custom_modules_node)
|
add_child(custom_modules_node)
|
||||||
logger.info("Initialized CORE successfully")
|
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
|
# Initialize modules
|
||||||
func initialize_modules() -> void:
|
func initialize_modules() -> void:
|
||||||
|
@ -102,11 +100,14 @@ func inject_modules() -> void:
|
||||||
add_child(edl)
|
add_child(edl)
|
||||||
|
|
||||||
# Registers a custom module
|
# 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 + "\"")
|
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):
|
if custom_modules.has(module_name):
|
||||||
logger.error("Registering module failed: A custom module with the name \"" + module_name + "\" already exists.")
|
logger.error("Registering module failed: A custom module with the name \"" + module_name + "\" already exists.")
|
||||||
return
|
return false
|
||||||
module_class.name = module_name
|
module_class.name = module_name
|
||||||
logger.diag("Adding module to SceneTree")
|
logger.diag("Adding module to SceneTree")
|
||||||
custom_modules_node.add_child(module_class)
|
custom_modules_node.add_child(module_class)
|
||||||
|
@ -116,6 +117,7 @@ func register_custom_module(module_name: String, module_class: CoreBaseModule) -
|
||||||
module_class._initialize()
|
module_class._initialize()
|
||||||
logger.diag("Updating custom module configuration")
|
logger.diag("Updating custom module configuration")
|
||||||
module_class._pull_config()
|
module_class._pull_config()
|
||||||
|
return true
|
||||||
|
|
||||||
# Unregisters a custom module
|
# Unregisters a custom module
|
||||||
func unregister_custom_module(module_name: String) -> void:
|
func unregister_custom_module(module_name: String) -> void:
|
||||||
|
@ -147,14 +149,20 @@ func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new(
|
||||||
# Call _pull_config() functions
|
# Call _pull_config() functions
|
||||||
func apply_configuration() -> void:
|
func apply_configuration() -> void:
|
||||||
logger.verb("Applying configuration")
|
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()
|
logger._pull_config()
|
||||||
misc._pull_config()
|
misc._pull_config()
|
||||||
sms._pull_config()
|
sms._pull_config()
|
||||||
logui._pull_config()
|
logui._pull_config()
|
||||||
edl._pull_config()
|
if config.custom_modules:
|
||||||
for module in custom_modules:
|
for module in custom_modules:
|
||||||
logger.diag("Updating configuration for custom module \"" + module.name + "\"")
|
logger.diag("Updating configuration for custom module \"" + module.name + "\"")
|
||||||
module._pull_config()
|
module._pull_config()
|
||||||
|
|
||||||
# Determines CORE's installation/base path
|
# Determines CORE's installation/base path
|
||||||
func determine_basepath() -> bool:
|
func determine_basepath() -> bool:
|
||||||
|
@ -171,7 +179,7 @@ func determine_basepath() -> bool:
|
||||||
|
|
||||||
# Return development mode status
|
# Return development mode status
|
||||||
func is_devmode() -> bool:
|
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
|
# Replaces variables with human-friendly strings
|
||||||
func get_formatted_string(string: String) -> String:
|
func get_formatted_string(string: String) -> String:
|
||||||
|
@ -200,6 +208,9 @@ func get_formatted_string(string: String) -> String:
|
||||||
# Headless mode
|
# Headless mode
|
||||||
if config.headless: string = string.replace("%headless%", "Enabled")
|
if config.headless: string = string.replace("%headless%", "Enabled")
|
||||||
else: string = string.replace("%headless%", "Disabled")
|
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 string
|
||||||
|
|
||||||
# Return CORE's version in the semantic versioning scheme
|
# Return CORE's version in the semantic versioning scheme
|
||||||
|
|
Loading…
Reference in a new issue