GdlrModule¶
Inherits: RefCounted < Object
Base class for modules.
Description¶
A module declares what it imports, what it provides, and what it exports. Godular reads four optional static members from the module script:
class_name GameModule
extends GdlrModule
# Modules this module depends on. Godular registers and enables them first.
static var IMPORTS = [SettingsModule, AudioModule]
# How to build each token. Keys are capabilities or other tokens.
static var PROVIDERS = {
CapScore: {"use": SvcScore, "inject": [CapSettings]},
}
# Tokens that modules importing this module can consume.
static var EXPORTS = [CapScore]
# Tokens resolved at start and available through GdlrModuleManager.request().
static var TREE_EXPORTS = [CapScore]
A module script can also be a plain script that holds the static members and an inner class that extends GdlrModule. See GdlrModuleDefinition.get_module_class().
Provider configuration. Each entry in PROVIDERS maps a token to a dictionary with these keys:
use: a script, a callable, or a plain value. Godular callsnew()on a script and calls a callable. It uses any other value as is. A callable can return a GdbPromise for asynchronous work.inject: tokens passed as positional arguments, in order. Godular resolves them from this module’s providers first, then from the exports of imported modules.use_existing: another token. The provider resolves to the value of that token. Use it to alias a capability.
Each token resolves once per module and Godular caches the value.
Injection. Before register() runs, Godular sets every typed property whose type extends GdlrCapability to the resolved value of that capability. For tokens that are not capability classes, declare a static INJECT array:
static var INJECT = [{"token": &"settings", "property": "settings"}]
var settings: Dictionary
Lifecycle. Godular creates each module once with its imports created first. It then calls register(), resolves every tree export, and finally calls enable() on each module in dependency order. A module waits for the enable() calls of its imports. Each enable() call must finish within GdlrModuleGraph.DEFAULT_MODULE_ENABLE_TIMEOUT_S seconds.
Tutorials¶
Methods¶
void |
register() |
void |
enable() |
void |
inject_dependencies(instance: Object) |
void |
register_debug_plugin(plugin_name: String, plugin: GdlrModuleGraph.DebugPlugin) |
Method Descriptions¶
void register() 🔗
Runs once after Godular injects the module dependencies and registers the imported modules. Override it to register handlers, jobs, or other data. Keep it synchronous. Use enable() for asynchronous work.
void enable() 🔗
Runs after every imported module is enabled. Override it to start the module. The method can await. Modules that import this module wait until it returns.
void inject_dependencies(instance: Object) 🔗
Copies the dependencies of this module into instance. The object declares what it needs in the same way as a module: typed properties whose type extends GdlrCapability, or a static INJECT array. Godular only copies tokens that this module also declares. It reports an error for each token it cannot find.
void register_debug_plugin(plugin_name: String, plugin: GdlrModuleGraph.DebugPlugin) 🔗
Registers a debug view on the module graph. See GdlrModuleGraph.register_debug_plugin().