diff --git a/docs/docs/reference/core.md b/docs/docs/reference/core.md index 79642ab..ff94819 100644 --- a/docs/docs/reference/core.md +++ b/docs/docs/reference/core.md @@ -1,21 +1,23 @@ --- -sidebar_position: 1 +sidebar_position: 0 +description: Initializes and manages the framework. --- # `CORE` -The **CORE Object** is the class you use to initialize the CORE Framework. +The **CORE Object** is responsible for initializing, managing and serving the CORE Framework. -## Constants +## Versioning ### *int* version_release -CORE's release number +CORE's version number. ### *CoreTypes.VersionType* version_type -CORE's release type. See [`CoreTypes.VersionType`](/reference/coretypes#versiontype) for more information. +CORE's version type. See [`CoreTypes.VersionType`](/reference/coretypes#versiontype) for more information. ### *int* version_typerelease -CORE's typerelease number +CORE's version type number. Resets on every new version and version type. +### *Array[String]* modules = *[ "logger", "misc", "sms", "logui", "erm", "storage" ]* ## Modules Use these to access CORE's modules. -- [`config`](/reference/coreconfiguration) (**NEVER access this yourself. To change the configuration, use [`reload_configuration()`](#void-reload_configurationcoreconfiguration-new_config) instead**) +- [`config`](/reference/coreconfiguration) (**NEVER access this yourself. To change the configuration, use `reload_configuration()` instead**) - [`logger`](/reference/logger) - [`misc`](/reference/misc) - `logui` (not important for developers, displays the log graphically) @@ -25,40 +27,90 @@ Use these to access CORE's modules. ## Variables ### *String* basepath +::danger[Don't modify] +Do not modify this. +:: Stores the path to CORE's installation directory. +### *Dictionary* custom_modules = *{}* +### *void* _ready() +::danger[Don't modify] +Do not modify this. +:: +Contains a list of all loaded custom modules. +### *Node* custom_modules_node +::danger[Don't modify] +Do not modify this. +:: +Contains the node holding all custom modules as children. ## Functions ### *void* _init(*CoreConfiguration* new_config) -Determines the base path, loads the configuration file and initializes all modules. -### *bool* register_custom_module(*String* module_name, *CoreBaseModule* module_class) +::danger[Don't call] +Do not call this (except you're using `Core.new()`). +:: +Handles the preinitialization part. Does stuff like checking the engine version, loading the config and loading all modules into memory. +### *void* _ready() +::danger[Don't call] +Do not call this. +:: +Handles the initialization part. Injects the builtin modules into the SceneTree and makes sure custom modules can be loaded properly. \ +### *void* initialize_modules() +::danger[Don't call] +Do not call this. +:: +Initializes all built-in modules during the preinitialization phase. +### *void* inject_modules() +::danger[Don't call] +Do not call this. +:: +Injects CORE's built-in modules into the SceneTree. +### *void* complete_init(*bool* no_success_message = *false*) +Waits for all built-in and custom modules to fully initialize. \ + \ +This ensures that all modules are fully initialized and ready for usage. \ +***Not calling this function during startup may lead to runtime issues.*** +### *bool* register_custom_module(*String* module_name, *String* module_origin, *CoreBaseModule* module_class) Registers a custom module. - -Returns `true` if successful. ### *void* unregister_custom_module(*String* module_name) -Unregisters a custom module. +Unregisters a custom module, making it no longer available. ### *CoreBaseModule* get_custom_module(*String* module_name) Returns a registered custom module. \ -Please note that you can't get CORE's builtin modules with this function. -### *void* reload_configuration(*CoreConfiguration* new_config) -Loads a new CoreConfiguration class and applies it's settings. +Please note that you can't get CORE's built-in modules with this function. +### *void* reload_configuration(*CoreConfiguration* new_config = *CoreConfiguration.new()*) +Loads a (new) configuration object and applies it to all modules. +### *void* apply_configuration() +::danger[Don't call] +Do not call this. +:: +Applies the a configuration. +### *void* cleanup() +Makes sure that CORE does not leak memory on shutdown/unload. \ +Unloads all custom modules, built-in modules, frees any of CORE's classes and lastly itself. ### *bool* is_devmode() -Returns the development mode status. +Returns if the CORE Framework is in development mode. ### *String* get_format_string(*String* string) -Replaces placeholders with human-friendly strings \ +Replaces placeholders with human-friendly strings. \ You can use the following placeholders: -- `%release%` - Returns the release number. -- `%release_type%` - Returns the typerelease number -- `%release_semantic%` - Returns the result of [`get_version_semantic()`](#arrayint-get_version_semantic), example *5.2.3* -- `%type%` - Returns the release type as a word, for example *Release Candidate* -- `%type_technical%` - Returns the release type as one or two lowercase letters, for example *rc* +- `%version%` + Returns the version number. +- `%version_type%` + Returns the version type number +- `%version_semantic%` + Returns the result of `get_version_semantic()`, example *5.2.3* +- `%version_type%` + Returns the version type as a word, for example *Release Candidate* +- `%version_type_technical%` + Returns the version type as one or two lowercase letters, for example *rc* - `%devmode%` Returns the development mode status - `%headless%` Returns the headless mode status +- `%custommodules%` + Returns if custom module support is enabled ### *Array[int]* get_version_semantic() -Returns the CORE version in the semantic versioning scheme. The first integer contains the release number, the second integer contains the release type (0 for alpha, 1 for beta, 2 for rc and 3 for release) and the last integer contains the typerelease number. +Returns the CORE version in the semantic versioning scheme. The first integer contains the version number, the second integer contains the version type (`0` for alpha, `1` for beta, `2` for rc and `3` for release) and the last integer contains the version type number. +### *bool* determine_basepath() +::danger[Don't call] +Do not call this. +:: +Determines CORE's installation/base path. diff --git a/docs/docs/reference/corebasemodule.md b/docs/docs/reference/corebasemodule.md new file mode 100644 index 0000000..3168d53 --- /dev/null +++ b/docs/docs/reference/corebasemodule.md @@ -0,0 +1,30 @@ +--- +sidebar_position: 3 +description: Template for CORE modules +--- + +# `CoreBaseModule` +Provides a basic template and a common foundation for building CORE modules. \ +It provides common functions and variables used in all CORE modules. + +## Variables +### *Core* core +Contains a reference to the [CORE Object](/reference/core). +### *CoreBaseModule* logger = *core.logger* +Set to CORE's logger implementation. +### *CoreLoggerInstance* loggeri +Set to a logger instance with the path you supplied to `core.register_custom_module`. You should use this over `logger`. +### *bool* initialized = *false* +Marks a module as fully initialized and ready. **Don't forget to set this!** + +## Functions +### *void* _initialize() +CORE's replacement for `Object._init` and `Node._ready`. \ +It's **strongly** recommended to initialize your module here or stuff might break. +### *void* _cleanup() +Called when CORE is about to cleanup. \ +Use this function to remove any children from the SceneTree and free any nodes. \ +If not done you might cause a memory leak. +### *void* _pull_config() +Called after CORE's configuration got updated. \ +Probably useless to your module, unless you want to modify another module's settings. diff --git a/docs/docs/reference/coreconfiguration.md b/docs/docs/reference/coreconfiguration.md index f20d727..a1d6351 100644 --- a/docs/docs/reference/coreconfiguration.md +++ b/docs/docs/reference/coreconfiguration.md @@ -1,5 +1,5 @@ --- -sidebar_position: 6 +sidebar_position: 1 --- # `CoreConfiguration` @@ -17,6 +17,7 @@ This will not enable the development mode automatically, only if you're developi Allows debugging functionality if set to `true`, or not if set to `false`. ### *bool* custom_modules = *false* Allows or disallows custom modules. + ## Logger ### *CoreTypes.LoggerLevel* logger_level = *CoreTypes.LoggerLevel.INFO* I don't have to explain this, do I? @@ -37,6 +38,7 @@ with a newline! ``` ### *int* logger_newlines_sizelimit = *40* The maximum amount of characters than can appear before `%message%` before newlines won't be overriden. Setting this variable to `-1` disables this behaviour. + ## LogUI ### *bool* logui_enabled = *true* Determines if [`LogUI`](/terminology#logui) should be visible or not. diff --git a/docs/docs/reference/coretypes.md b/docs/docs/reference/coretypes.md index 639308d..2d99def 100644 --- a/docs/docs/reference/coretypes.md +++ b/docs/docs/reference/coretypes.md @@ -1,14 +1,15 @@ --- -sidebar_position: 5 +sidebar_position: 2 +description: Contains various enums. --- # `CoreTypes` Contains globaly accessible custom enums and types used throughout the CORE Framework's source code. ## Enums -### VersionType -RELEASE, RELEASECANDIDATE, BETA, ALPHA -### LoggerLevel -NONE, ERROR, WARN, INFO, VERB, DIAG -### SceneType -NONE, DEBUG, CUTSCENE, MENU, MAIN, BACKGROUND +### VersionType{ RELEASE, RELEASECANDIDATE, BETA, ALPHA } +Available version types, following the StarOpenSource Versioning Specification (SOSVS) version 1. +### LoggerLevel{ NONE, ERROR, WARN, INFO, VERB, DIAG } +Available log levels, followingthe StarOpenSource Logging Specification (SOSLS) version 1. +### SceneType{ NONE, DEBUG, CUTSCENE, MENU, MAIN, BACKGROUND } +Available scene types. diff --git a/docs/docs/reference/logger.md b/docs/docs/reference/logger.md index efc49e5..b1acfba 100644 --- a/docs/docs/reference/logger.md +++ b/docs/docs/reference/logger.md @@ -1,5 +1,5 @@ --- -sidebar_position: 2 +sidebar_position: 4 --- # `Logger` diff --git a/docs/docs/reference/loggerinstance.md b/docs/docs/reference/loggerinstance.md index 2770428..a9dc91e 100644 --- a/docs/docs/reference/loggerinstance.md +++ b/docs/docs/reference/loggerinstance.md @@ -1,21 +1,33 @@ --- -sidebar_position: 3 +sidebar_position: 5 +description: Passes `origin` for you. --- # `LoggerInstance` -Passes origin for you. +Pretty much a wrapper around CORE's logging implementation. \ +CoreLoggerInstance's only job is to save you some effort aka. \ +you not needing to pass the `origin` argument to each \ +and every log call, which is extremely annoying. Thank us later ;) + +## Variables +### *CoreBaseModule* logger +Reference to CORE's logger module. +### *String* origin +The origin argument. ## Functions +### *void* _init(*CoreBaseModule* logger_new, *String* origin_new) +The instance constructor. ### *void* diag(*String* message) -Prints a diagnostic message +Prints a diagnostic message. ### *void* verb(*String* message) -Prints a verbose message +Prints a verbose message. ### *void* info(*String* message) -Prints an informational message +Prints an informational message. ### *void* warn(*String* message) -Prints a warning message +Prints a warning message. ### *void* error(*String* message) -Prints an error message +Prints an error message. ### *void* crash(*String* message) :::note[Awaiting required] Using the `await` keyword is required for this function. diff --git a/docs/docs/reference/misc.md b/docs/docs/reference/misc.md index 0faa682..c856a4a 100644 --- a/docs/docs/reference/misc.md +++ b/docs/docs/reference/misc.md @@ -1,5 +1,5 @@ --- -sidebar_position: 4 +sidebar_position: 6 --- # `Miscellaneous` diff --git a/docs/docs/terminology.md b/docs/docs/terminology.md index 434f779..b19d1cd 100644 --- a/docs/docs/terminology.md +++ b/docs/docs/terminology.md @@ -7,9 +7,11 @@ You don't know a word? Look it up here. ## CORE Object aka. `CORE` The **CORE Object** is the class you use to initialize the CORE Framework. -## `LogUI` +## `Log UI` Displays the log/console output graphically in the background. +## `ERM` +Stands for **Easy Request Maker** and allows you to download stuff. ## `EDL` -Stands for **Easy DownLoader** and allows you to download stuff. +The old name for the [`ERM`](#erm) module, which was called `Easy DownLoader` previously. ## `SMS` No, it does not stand for **Short Message Service**, but for **Scene Management System**. It manages your scenes. diff --git a/docs/package.json b/docs/package.json index cd36bf7..617ba1e 100644 --- a/docs/package.json +++ b/docs/package.json @@ -15,23 +15,23 @@ "typecheck": "tsc" }, "dependencies": { - "@docusaurus/core": "3.1.1", - "@docusaurus/plugin-client-redirects": "^3.1.1", - "@docusaurus/plugin-content-docs": "^3.1.1", - "@docusaurus/plugin-sitemap": "^3.1.1", - "@docusaurus/preset-classic": "3.1.1", - "@mdx-js/react": "^3.0.0", - "clsx": "^2.0.0", - "prism-react-renderer": "^2.3.0", - "react": "^18.0.0", - "react-dom": "^18.0.0" + "@docusaurus/core": "3.2.1", + "@docusaurus/plugin-client-redirects": "^3.2.1", + "@docusaurus/plugin-content-docs": "^3.2.1", + "@docusaurus/plugin-sitemap": "^3.2.1", + "@docusaurus/preset-classic": "3.2.1", + "@mdx-js/react": "^3.0.1", + "clsx": "^2.1.0", + "prism-react-renderer": "^2.3.1", + "react": "^18.2.0", + "react-dom": "^18.2.0" }, "devDependencies": { - "@docusaurus/module-type-aliases": "3.1.1", - "@docusaurus/tsconfig": "3.1.1", - "@docusaurus/types": "3.1.1", - "@types/node": "^20.11.0", - "typescript": "~5.2.2" + "@docusaurus/module-type-aliases": "3.2.1", + "@docusaurus/tsconfig": "3.2.1", + "@docusaurus/types": "3.2.1", + "@types/node": "^20.12.5", + "typescript": "~5.4.4" }, "browserslist": { "production": [ diff --git a/src/classes/basemodule.gd b/src/classes/basemodule.gd index 947e828..7b7464e 100644 --- a/src/classes/basemodule.gd +++ b/src/classes/basemodule.gd @@ -22,25 +22,22 @@ extends Node class_name CoreBaseModule -## Contains a reference to the CORE Object[br] -## [br] -## Set before loading the module into the SceneTree. +## Contains a reference to the CORE Object. var core: Core -## Reference to CORE's logger implementation.[br] -## [br] -## Will be set before [method Node._ready] +## Set to CORE's logger implementation. @onready var logger: CoreBaseModule = core.logger -## Reference to a matching [class CoreLoggerInstance]. +## Set to a [class CoreLoggerInstance] with the path you supplied to [method Core.register_custom_module]. You should use this over [code]logger[/code]. var loggeri: CoreLoggerInstance -## Marks a module as fully initialized and ready. +## Marks a module as fully initialized and ready. **Don't forget to set this!** var initialized: bool = false -## CORE's replacement for [method Object._init] and [method Node._ready] -## It's [b]strongly[/b] recommended to initialize your module here. +## CORE's replacement for [method Object._init] and [method Node._ready]. +## It's [b]strongly[/b] recommended to initialize your module here or stuff might break. func _initialize() -> void: initialized = true -## Called when CORE is about to cleanup -## Use this function to free any children +## Called when CORE is about to cleanup.[br] +## Use this function to remove any children from the SceneTree and free any nodes.[br] +## If not done you might cause a memory leak. func _cleanup() -> void: pass -## Called by [method Core.apply_configuration]. -## This should be used to update your module configuration. +## Called after CORE's configuration got updated.[br] +## Probably useless to your module, unless you want to modify another module's settings. func _pull_config() -> void: pass diff --git a/src/classes/config.gd b/src/classes/config.gd index af3dc96..9d16a6d 100644 --- a/src/classes/config.gd +++ b/src/classes/config.gd @@ -8,7 +8,7 @@ extends Node class_name CoreConfiguration @export_category("Global") -## Controls CORE's functionality. +## Controls CORE's functionality.[br] ## Renders GUI-related modules useless when set to [code]false[/code], which is the recommended behaviour on servers. For CORE's full functionality, set this to [code]true[/code]. @export var headless: bool ## Allows debugging functionality if set to [code]true[/code], or not if set to [code]false[/code].[br] @@ -24,7 +24,7 @@ class_name CoreConfiguration @export var logger_colored: bool ## The format string the logger will operate on. Available placeholders are: [code]%time%[/code], [code]%time_ms%[/code], [code]%level%[/code], [code]%color%[/code], [code]%message%[/code], [code]%source%[/code], [code]%source_raw%[/code], [code]%function%[/code] and [code]%line%[/code] @export var logger_format: String -## This example should make it clear, what this does: +## This example should make it clear, what this does:[br] ## [codeblock] ## logger_newlines_override = true: ## [09:47:00] [INFO Test.gd:69] This is a test message... diff --git a/src/classes/loggerinstance.gd b/src/classes/loggerinstance.gd index 70a1639..fb3f910 100644 --- a/src/classes/loggerinstance.gd +++ b/src/classes/loggerinstance.gd @@ -24,23 +24,26 @@ extends Node class_name CoreLoggerInstance -## Class name +## Reference to CORE's logger module. var logger: CoreBaseModule +## The origin argument. var origin: String +## The instance constructor. func _init(logger_new: CoreBaseModule, origin_new: String) -> void: logger = logger_new origin = origin_new -## Prints a diagnostic message +## Prints a diagnostic message. func diag(message: String) -> void: logger.diag(origin, message) -## Prints a verbose message +## Prints a verbose message. func verb(message: String) -> void: logger.verb(origin, message) -## Prints a informational message +## Prints a informational message. func info(message: String) -> void: logger.info(origin, message) -## Prints a warning message +## Prints a warning message. func warn(message: String) -> void: logger.warn(origin, message) -## Prints a error message +## Prints a error message. func error(message: String) -> void: logger.error(origin, message) ## Handles crashes. Will terminate your game/application immediately. +## Note: Awaiting required. func crash(message: String) -> void: await logger.crash(origin, message) diff --git a/src/classes/types.gd b/src/classes/types.gd index 9d6c1e9..a4e8698 100644 --- a/src/classes/types.gd +++ b/src/classes/types.gd @@ -19,9 +19,9 @@ extends Node class_name CoreTypes -## Available version types, following the StarOpenSource Versioning Specification (SOSVS) version 1 +## Available version types, following the StarOpenSource Versioning Specification (SOSVS) version 1. enum VersionType { RELEASE, RELEASECANDIDATE, BETA, ALPHA } -## Available log levels, followingthe StarOpenSource Logging Specification (SOSLS) version 1 +## Available log levels, followingthe StarOpenSource Logging Specification (SOSLS) version 1. enum LoggerLevel { NONE, ERROR, WARN, INFO, VERB, DIAG } -## Available scene types +## Available scene types. enum SceneType { NONE, DEBUG, CUTSCENE, MENU, MAIN, BACKGROUND } diff --git a/src/core.gd b/src/core.gd index c4a65ab..f6f76a3 100644 --- a/src/core.gd +++ b/src/core.gd @@ -18,46 +18,50 @@ ## Initializes and manages the framework. ## ## The [b]CORE Object[/b] is responsible for initializing, managing and -## serving the CORE Framework to the developer. +## serving the CORE Framework. extends Node class_name Core -# Constants +# Versioning ## The version number const version_version: int = 1 -## The version type +## The version type. See [enum CoreTypes.VersionType] for more information. const version_type: CoreTypes.VersionType = CoreTypes.VersionType.BETA ## The version type number. Resets on every new version and version type. -const version_typerelease: int = 4 +const version_typerelease: int = 6 # Modules +## Used internally for loading, managing and unloading modules. const modules: Array[String] = [ "logger", "misc", "sms", "logui", "erm", "storage" ] -## Use this to access CORE's logging implementation. +## CORE's configuration object.[br] +## [b]NEVER access this yourself! To change the configuration use [method reload_configuration] instead.[/b] +var config: CoreConfiguration +## The 'Logger' module var logger: CoreBaseModule -## Use this to access various useful functions. +## The 'Miscellaneous' module var misc: CoreBaseModule -## Use this to access the scene management system. +## The 'Scene Management System' module var sms: CoreBaseModule -## Use this to access the graphical log. Serves no importance to you (probably). +## The 'Log UI' module. Not important for you, it just displays the log graphically :3 var logui: CoreBaseModule -## Use this to access CORE's builtin HTTP request maker. +## The 'Easy Request Maker' module (formerly 'Easy DownLoader') var erm: CoreBaseModule -## Use this to access configuration and settings files easily. +## The 'Storage' module var storage: CoreBaseModule -# Variables -## Contains CORE's load path +# /etc/ +## Stores the path to CORE's installation directory.[br] +## Danger: Don't modify this. var basepath: String -## Holds the configuration[br] -## [br] -## [b]NEVER access this yourself. To change the configuration file, use [method Core.reload_configuration] instead.[/b] -var config: CoreConfiguration -## Contains all loaded custom modules. +## Contains a list of all loaded custom modules.[br] +## Danger: Don't modify this. var custom_modules: Dictionary = {} -## Contains the custom modules node. +## Contains the node holding all custom modules as children.[br] +## Danger: Don't modify this. var custom_modules_node: Node -# Preinitialization +# +++ initialization +++ +## Handles the preinitialization part. Does stuff like checking the engine version, loading the config and loading all modules into memory. func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void: name = "CORE" if !check_godot_version(): return @@ -67,32 +71,15 @@ func _init(new_config: CoreConfiguration = CoreConfiguration.new()) -> void: initialize_modules() apply_configuration() -# Initialization +## Handles the initialization part. Injects the builtin modules into the SceneTree and makes sure custom modules can be loaded properly.[br] +## Danger: Don't call this. func _ready() -> void: inject_modules() custom_modules_node.name = "Custom Modules" add_child(custom_modules_node) -# Cleanup -# Particularily useful during testing to cleanup stuff, or if you want to do some stupid stuff with CORE during runtime -func cleanup() -> void: - logger.infof("core", "Cleaning up") - config.queue_free() - var modules_reverse: Array[String] = modules.duplicate() - 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) - custom_modules_node.queue_free() - queue_free() - -# Initialize modules -## Initializes all modules during the first initialization phase.[br] -## [br] -## [b]NEVER call this yourself! You will break everything and risk a crash![/b] +## Initializes all built-in modules during the preinitialization phase.[br] +## Danger: Don't call this. func initialize_modules() -> void: for module in modules: set(module, CoreBaseModule.new()) @@ -102,18 +89,15 @@ func initialize_modules() -> void: get(module).loggeri = logger.get_instance(basepath.replace("res://", "") + "src/" + module + ".gd") get(module)._initialize() -# Inject modules into the SceneTree ## Injects CORE's builtin modules into the SceneTree.[br] -## [br] -## [b]NEVER call this yourself! You will break everything and risk a crash![/b] +## Danger: Don't call this. func inject_modules() -> void: for module in modules: add_child(get(module)) -# Wait for all modules to be fully initialized -## Wait for all builtin modules to be fully initialized.[br] +## Waits for all modules to fully initialize.[br] ## [br] -## This ensures that all of CORE's builtin modules are fully initialized and ready. -## [b]Not calling this function during startup may lead to runtime issues.[/b] -func complete_init(no_success: bool = false) -> void: +## This ensures that all modules are fully initialized and ready for usage.[br] +## [i][b]Not calling this function during startup may lead to runtime issues.[/b][/i] +func complete_init(no_success_message: bool = false) -> void: var modsinit_builtin: Array[String] = ["workaround"] var modsinit_custom: Array[String] = ["workaround"] @@ -138,9 +122,9 @@ func complete_init(no_success: bool = false) -> void: # Initialization complete await get_tree().process_frame - if !no_success: logger.infof("core", "Initialized CORE successfully") + if !no_success_message: logger.infof("core", "Initialized CORE successfully") -# Registers a custom module +# +++ custom module support +++ ## Registers a new custom module. func register_custom_module(module_name: String, module_origin: String, module_class: CoreBaseModule) -> bool: logger.verbf("core", "Registering new custom module \"" + module_name + "\"") @@ -164,8 +148,7 @@ func register_custom_module(module_name: String, module_origin: String, module_c module_class._pull_config() return true -# Unregisters a custom module -## Unregisters a custom module, making it no longer function. +## Unregisters a custom module, making it no longer available. func unregister_custom_module(module_name: String) -> void: logger.verbf("core", "Unregistering custom module \"" + module_name + "\"") if !custom_modules.has(module_name): @@ -178,8 +161,8 @@ func unregister_custom_module(module_name: String) -> void: custom_modules.erase(module_name) module.queue_free() -# Returns a custom module -## Returns a loaded custom module for access. +## Returns a registered custom module.[br] +## Please note that you can't get CORE's built-in modules with this function. func get_custom_module(module_name: String) -> CoreBaseModule: logger.diagf("core", "Getting custom module \"" + module_name + "\"") if !custom_modules.has(module_name): @@ -187,8 +170,8 @@ func get_custom_module(module_name: String) -> CoreBaseModule: return null return custom_modules[module_name] -# (Re-)Load configuration -## Loads a (new) configuration file and applies it to all modules. +# +++ configuration +++ +## Loads a (new) configuration object and applies it to all modules. func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new()) -> void: var initialized = config != null if initialized: logger.verbf("core", "Reloading CORE's configuration") @@ -199,10 +182,8 @@ func reload_configuration(new_config: CoreConfiguration = CoreConfiguration.new( if initialized: logger.verbf("core", "Overrode configuration (development mode)") if initialized: apply_configuration() -# Call _pull_config() functions -## Applies the newly applied configuration.[br] -## [br] -## [b]NEVER call this yourself unless you know what you are doing![/b] +## Applies the a configuration.[br] +## Danger: Don't call this. func apply_configuration() -> void: logger.verbf("core", "Applying configuration") if is_devmode(): logger.warnf("core", "The CORE Framework is in development mode. Here be dragons!") @@ -216,20 +197,37 @@ func apply_configuration() -> void: logger.diagf("core", "Updating configuration for custom module \"" + module.name + "\"") module._pull_config() -# Return development mode status +# +++ etc ++ +## Makes sure that CORE does not leak memory on shutdown/unload.[br] +## Unloads all custom modules, built-in modules, frees any of CORE's classes and lastly itself. +func cleanup() -> void: + logger.infof("core", "Cleaning up") + config.queue_free() + var modules_reverse: Array[String] = modules.duplicate() + 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) + custom_modules_node.queue_free() + queue_free() + ## Returns if the CORE Framework is in development mode. func is_devmode() -> bool: return config.debugging and basepath == "res://" and OS.is_debug_build() -# Replaces variables with human-friendly strings -## Replaces placeholders with human-friendly strings You can use the following placeholders:[br] -## - [code]%release%[/code]: Returns the release number.[br] -## - [code]%release_type%[/code]: Returns the typerelease number[br] -## - [code]%release_semantic%[/code]: Returns the result of [method Core.get_version_semantic], example [i]5.2.3[/i][br] -## - [code]%type%[/code]: Returns the release type as a word, for example [i]Release Candidate[/i][br] -## - [code]%type_technical%[/code]: Returns the release type as one or two lowercase letters, for example [i]rc[/i][br] +## Replaces placeholders with human-friendly strings.[br] +## You can use the following placeholders:[br] +## - [code]%version%[/code]: Returns the version number.[br] +## - [code]%version_type%[/code]: Returns the version type number[br] +## - [code]%version_semantic%[/code]: Returns the result of [method Core.get_version_semantic], example [i]5.2.3[/i][br] +## - [code]%version_type%[/code]: Returns the version type as a word, for example [i]Release Candidate[/i][br] +## - [code]%version_type_technical%[/code]: Returns the version type as one or two lowercase letters, for example [i]rc[/i][br] ## - [code]%devmode%[/code]: Returns the development mode status[br] -## - [code]%headless%[/code]: Returns the headless mode status +## - [code]%headless%[/code]: Returns the headless mode status[br] +## - [code]%custommodules%[/code]: Returns if custom module support is enabled func get_formatted_string(string: String) -> String: # Version strings string = string.replace("%version%", str(version_version)) @@ -238,17 +236,17 @@ func get_formatted_string(string: String) -> String: string = string.replace("%version_semantic%", str(semantic_version[0]) + "." + str(semantic_version[1]) + "." + str(semantic_version[2])) match(version_type): CoreTypes.VersionType.RELEASE: - string = string.replace("%type%", "Release") - string = string.replace("%type_technical%", "r") + string = string.replace("%version_type%", "Release") + string = string.replace("%version_type_technical%", "r") CoreTypes.VersionType.RELEASECANDIDATE: - string = string.replace("%type%", "Release Candidate") - string = string.replace("%type_technical%", "rc") + string = string.replace("%version_type%", "Release Candidate") + string = string.replace("%version_type_technical%", "rc") CoreTypes.VersionType.BETA: - string = string.replace("%type%", "Beta") - string = string.replace("%type_technical%", "b") + string = string.replace("%version_type%", "Beta") + string = string.replace("%version_type_technical%", "b") CoreTypes.VersionType.ALPHA: - string = string.replace("%type%", "Alpha") - string = string.replace("%type_technical%", "a") + string = string.replace("%version_type%", "Alpha") + string = string.replace("%version_type_technical%", "a") _: await logger.crashf("core", "Invalid version type " + str(version_type), true) # Development mode if is_devmode(): string = string.replace("%devmode%", "Enabled") @@ -261,9 +259,8 @@ func get_formatted_string(string: String) -> String: else: string = string.replace("%custommodules%", "Disabled") return string -# Return CORE's version in the semantic versioning scheme ## Returns CORE's versioning scheme into the semantic versioning scheme.[br] -## The first integer contains the release number, the second integer contains the release type ([code]0[/code] for alpha, [code]1[/code] for beta, [code]2[/code] for rc and [code]3[/code] for release and the last integer contains the typerelease number. +## The first integer contains the version number, the second integer contains the version type ([code]0[/code] for alpha, [code]1[/code] for beta, [code]2[/code] for rc and [code]3[/code] for release and the last integer contains the version type number. func get_version_semantic() -> Array[int]: var version_type_int: int match(version_type): @@ -273,10 +270,8 @@ func get_version_semantic() -> Array[int]: CoreTypes.VersionType.ALPHA: version_type_int = 0 return [version_version, version_type_int, version_typerelease] -# Determines CORE's installation/base path -## Determines CORE's installation/base path[br] -## [br] -## [b]Calling this function is likely to be safe, but shouldn't be done nonetheless![/b] +## Determines CORE's installation/base path.[br] +## Danger: Do not call. func determine_basepath() -> bool: if FileAccess.file_exists("res://.corebasepath"): basepath = "res://"