AddonPlugin System
Estimated reading time: 4 minutesAddonPlugin is the core module that integrates maplebirchFramework with the ModLoader lifecycle. It is responsible for receiving registration requests from other mods, handling script loading, language file import, audio import, NPC configuration, and framework configuration.
Registration Mechanism
The framework registers itself with ModLoader during the inject_early phase:
Other mods register with the framework via the addonPlugin field in boot.json:
Lifecycle Hooks
AddonPlugin implements ModLoader's LifeTimeCircleHook interface and executes in the following order:
params Configuration Reference
script
List of JavaScript script files, executed during the afterRegisterMod2Addon phase. This is the most commonly used configuration item.
Scripts can be disabled via the GUI panel. The script key format is [ModName]:filePath.
module
Script files executed during the afterInjectEarlyLoad phase, earlier than script. Suitable for scenarios requiring custom module registration.
module scripts run very early when the framework may not yet be fully initialized. Not recommended unless necessary.
language
Language file configuration, supporting three formats:
Auto-import all languages:
Automatically searches and imports JSON/YAML translation files from the translations/ directory.
Specify language list:
Imports translations/cn.json and translations/en.json.
Custom path:
Translation file format is simple key-value pairs:
audio
Audio file configuration.
Default path import:
Import all audio files (mp3, wav, ogg, m4a, flac, webm) from the audio/ directory.
Custom path:
npc
NPC configuration object with the following sub-items:
Each NamedNPC entry is a triple [NPCData, NPCConfig, Translations]. See Named NPC System for details.
framework
Framework-level configuration, supporting trait registration and region widget addition.
Register traits:
Add region widget:
Conditional widget configuration is also supported:
Data Replacement
During the beforePatchModToGame phase, AddonPlugin performs the following game data modifications:
- Modify date format options (Options Overlay)
- Modify weather JavaScript (WeatherManager)
- Modify PC model (Character)
- Modify face styles (Character)
- Modify transformation effects (Transformation)
These modifications use the replace() utility function to replace Passage and script content via regular expressions.
