ModuleSystem API
Estimated reading time: 4 minutesOverview
ModuleSystem is the framework’s module loading and dependency management system. It handles module registration, dependency resolution, and lifecycle initialization, so modules load and run in the correct order.
For the overall architecture and initialization flow, see Core Architecture.
Core API
register(name, module, dependencies?, source?)
Registers a module with the system.
- @param
name(string): Module name. - @param
module(object): Module object; must implement the initialization methods described below. - @param
dependencies(string[]): List of module names this module depends on. Default[]. - @param
source(string): Optional source identifier; used for extension modules. - @return
boolean:trueif registration succeeded.
Extension modules are mounted onto maplebirch and can be enabled/disabled via the GUI panel.
getModule(name)
Returns the registered module instance.
- @param
name(string): Module name. - @return Module object or
undefined.
dependencyGraph
Returns the module dependency graph. Each entry includes:
dependencies— Direct dependenciesdependents— Modules that depend on this onestate— Current state (e.g.'MOUNTED')allDependencies— All transitive dependenciessource— Source identifier (for extension modules)
Module States
Each module can be in one of these states:
Lifecycle Methods
A module can define these lifecycle methods:
preInit()
Runs during pre-initialization, after the :allModule event. Use for lightweight setup or resource loading.
Init()
Main initialization, called on :passagestart (first run only). Usually required for core module logic.
loadInit()
Called only when a save is loaded. Use to restore state from save data.
postInit()
Runs after Init or loadInit finishes. Use for cleanup or final setup.
Full Module Example
Dependency Management
Declaring Dependencies
Dependency Rules
- A module initializes only after all its dependencies have initialized.
- Transitive dependencies are supported (if A depends on B and B on C, A depends on C).
- Circular dependencies are detected and rejected.
Querying the Dependency Graph
Notes
- Naming — Avoid reserved names such as
core,modules. - Initialization order — Dependencies are resolved via topological sort; understand how this affects order.
- Error handling — A failed module does not block others.
- Disabling — Modules can be disabled via ModLoader config.
- Extension modules — Extension modules are mounted on
maplebirchfor global access.
