Add support for custom modules

https://yourdick.zip
This commit is contained in:
JeremyStar™ 2024-02-05 18:03:16 +01:00
parent ed4647c750
commit 538ba01aec
4 changed files with 38 additions and 5 deletions

View file

@ -43,6 +43,8 @@ Type (technical) = %type_technical%
Typerelease = %release_type% Typerelease = %release_type%
Development mode = %devmode% Development mode = %devmode%
Headless mode = %headless%""")) Headless mode = %headless%"""))
# Print hi
core.logger.info("Hi there!")
# Update CORE configuration # Update CORE configuration
func configure_core() -> void: func configure_core() -> void:

View file

@ -16,4 +16,4 @@ If you want to use the CORE Framework in a new project, then your answer is **ye
- [x] Logger implementation - [x] Logger implementation
- [ ] HTTP Request helper - [ ] HTTP Request helper
- [ ] Mod Loader - [ ] Mod Loader
- [ ] Support for custom modules - [x] Support for custom modules

View file

@ -26,10 +26,14 @@ Stores the path to CORE's installation directory.
## Functions ## Functions
### *void* <u>_init</u>(*CoreConfiguration* <u>new_config</u>) ### *void* <u>_init</u>(*CoreConfiguration* <u>new_config</u>)
:::note
This function will be called when calling `CORE.new()`.
:::
Determines the base path, loads the configuration file and initializes all modules. Determines the base path, loads the configuration file and initializes all modules.
### *void* <u>register_custom_module</u>(*String* <u>module_name</u>, *CoreBaseModule* <u>module_class</u>)
Registers a custom module.
### *void* <u>unregister_custom_module</u>(*String* <u>module_name</u>)
Unregisters a custom module.
### *CoreBaseModule* <u>get_custom_module</u>(*String* <u>module_name</u>)
Returns a registered custom module. \
Please note that you can't get CORE's builtin modules with this function.
### *void* <u>reload_configuration</u>(*CoreConfiguration* <u>new_config</u>) ### *void* <u>reload_configuration</u>(*CoreConfiguration* <u>new_config</u>)
Loads a new CoreConfiguration class and applies it's settings. Loads a new CoreConfiguration class and applies it's settings.
### *bool* <u>is_devmode</u>() ### *bool* <u>is_devmode</u>()

View file

@ -30,13 +30,14 @@ const version_type: CoreTypes.VersionType = CoreTypes.VersionType.ALPHA
const version_typerelease: int = 0 const version_typerelease: int = 0
# Modules # Modules
var config: CoreConfiguration
var logger: CoreBaseModule var logger: CoreBaseModule
var misc: CoreBaseModule var misc: CoreBaseModule
var logui: CoreBaseModule var logui: CoreBaseModule
# Variables # Variables
var basepath: String var basepath: String
var config: CoreConfiguration
var custom_modules: Dictionary = {}
# Preinitialization # Preinitialization
func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void: func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
@ -82,6 +83,32 @@ func inject_modules() -> void:
add_child(misc) add_child(misc)
add_child(logui) add_child(logui)
# Registers a custom module
func register_custom_module(module_name: String, module_class: CoreBaseModule) -> void:
logger.verb("Registering new custom module \"" + module_name + "\"")
if custom_modules.has(module_name):
logger.error("Registering module failed: A custom module with the name \"" + module_name + "\" already exists.")
return
custom_modules.merge({ module_name: module_class })
module_class._initialize()
module_class._pull_config()
# Unregisters a custom module
func unregister_custom_module(module_name: String) -> void:
logger.verb("Unregistering custom module \"" + module_name + "\"")
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.erase(module_name)
# Returns a custom module
func get_custom_module(module_name: String) -> CoreBaseModule:
logger.diag("Getting custom module \"" + module_name + "\"")
if !custom_modules.has(module_name):
logger.error("Getting module failed: A custom module with the name \"" + module_name + "\" does not exist.")
return
return custom_modules[module_name]
# (Re-)Load configuration # (Re-)Load configuration
func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new()) -> void: func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new()) -> void:
var initialized = config != null var initialized = config != null