Core Services
Estimated reading time: 5 minutesThis document introduces the core services of maplebirchFramework: EventEmitter event bus, Logger logging service, LanguageManager internationalization service, and CloudSaveService cloud save service.
EventEmitter Event Bus
EventEmitter (accessible via maplebirch.tracer) provides a publish/subscribe event mechanism and is the foundation for inter-module communication within the framework. For full API reference, see EventEmitter.
API
Convenience Methods
MaplebirchCore proxies the event bus methods, which can be called directly on maplebirch:
Built-in Events
on vs once vs after
on— Executes every time the event firesonce— Executes once then auto-removesafter— Executes after alloncallbacks complete, then removes
Custom Events
Besides built-in events, you can register arbitrary custom events:
Logger Logging Service
Logger (accessible via maplebirch.logger) provides a tiered logging system.
Log Levels
Default level is INFO. Set to DEBUG to see all debug logs.
Usage
Creating Module Logs
Use createlog() to create log functions with a prefix:
IDB Configuration
Log level is read from the IndexedDB settings.DEBUG key. If DEBUG is true, log level is automatically set to DEBUG.
LanguageManager Internationalization
LanguageManager (accessible via maplebirch.lang) provides multi-language translation support. For full API reference and configuration options, see LanguageManager.
Supported Languages
EN— EnglishCN— Chinese
Translation API
t() Method
key— Translation keyspace— Iftrueand current language is EN, append space to result
Lookup order: Memory cache → Current language → EN fallback → First available translation → [key]
auto() Method
Reverse translation: Finds translation key by text content, then returns translation for current language.
Lookup order: Cache → Full search in memory translation table → IndexedDB async lookup
Translation File Format
Supports JSON and YAML formats:
Switching Language
Switching language will:
- Update
LanguageManager.language - Clear translation cache
- Trigger
:languageevent
Data Persistence
Translation data is stored in IndexedDB:
language-translations— Translation key-value pairs (indexed by mod and language)language-metadata— File hash (for incremental update detection)language-text_index— Text reverse index (forauto()lookup)
Translation files compute SHA-256 hash on import; import is skipped if file unchanged.
CloudSaveService Cloud Save
CloudSaveService (accessible via maplebirch.cloudSave) provides cloud save management with two backend modes: self-hosted server (Go+SQLite) and WebDAV (e.g. Cloudflare R2). Save data is encrypted with AES-256-GCM, with keys derived via PBKDF2.
Backend Modes
Auto-detection on connect: sends a request to /health; if JSON is returned, uses server mode, otherwise falls back to webdav.
Configuration
Account Management (server mode)
Save Slot Operations
Save Code Operations
Panel Integration
Supported panel actions (PanelAction):
Encryption
- Algorithm: AES-256-GCM
- Key derivation: PBKDF2 (150,000 iterations, SHA-256)
- Compression: gzip (only when compressed size is smaller)
- Random salt and IV per encryption
