3.8 KiB
3.8 KiB
ADR 0046: The module framework
- Status: accepted
- Date: 2026-10-09
Context
The client's features number in the dozens, many written in parallel by agents. Each needs an on/off switch, keybinds, settings with a screen, a HUD place, game events, and saved state. This builds that once: done when a sample module's settings screen and keybind come from its schema alone.
The look will be redone, so nothing may tie features to the game's widgets. And on a Chromebook, a feature that's off must cost nothing, and one that's on must not allocate on hot paths.
Decision
:framework, a strict module with no game types:Module,ModuleSystem, the event bus, settings, HUD elements, profiles. Only the JDK, JSpecify and Gson's tree API (BoundaryTest).- Features are
features/<name>projects depending on:frameworkonly.:clientlists them inincari.client.modules.Features: no reflection or service loading (the browser's closed world can't see them). Toggle Sprint is the first. - Adapters in
incari.client.modulesare the only code seeing both sides: hooks fire events,ModuleHuddraws,GameKeysreads binds. - A module declares; the framework runs it: settings as fields, HUD elements and listeners in the constructor. Listeners are subscribed only while enabled.
- Events are channels with their own listener interface (
TICK,MOVEMENT,JOIN,LEAVE; later ADRs add more). Listeners are an array replaced on (un)subscribe: firing allocates nothing, and an unheard channel costs a length check. A listener that throws is logged and its module turned off. - Settings are a typed schema: boolean, integer, decimal, choice, colour, keybind; each with an
id (config key), name, tooltip, default, optional
visibleWhenandhidden().SettingVisitormakes a new kind fail to compile wherever it isn't handled. Reads are primitive. - Keybinds use the game's key handling: each
KeySettinggets its ownKeyMapping, outside Controls andoptions.txt. Every module has a toggle key (unbound by default). The module menu is Right Shift. - HUD elements draw on a
HudCanvasin GUI units. Placement (anchor of nine, offsets, scale) is settings saved with the profile; offsets are hidden, for the editor (ADR 0049). In the browser they're drawn into the HUD's cached texture (ADR 0030). - Colours are tones (
Tone: text, muted, accent, positive, warning, negative, background) that the theme resolves. Player-pickedColorSettings are drawn as given. - Profiles: named JSON sets of module states and settings in
incari/modules/profiles/. A new one copies the active one. Saved a second after the last change, or at once on closing a module screen or leaving a world. Reading is forgiving: bad values keep defaults, broken files aren't overwritten until something changes, unknown modules keep their entries. - The UI is generated through one seam:
incari.client.ui(Theme,Ui,ControlList,ListScreen,SettingControls) builds the module menu, settings screens and profiles screen. The restyle replacesThemeandUi, and every screen follows. - Two patches:
KeyboardInput.tick(keys toModuleInput) andHud.extractRenderState(ModuleHudbefore chat). Ticks, the menu key and the pause button use existing hooks.
Not yet (at the time)
- World-render and packet events come with their first users, in the framework's own terms (done in ADRs 0050–0053).
- Server feature control:
Module.setEnabledis the one way on, so a server veto goes there. - Language files: names are English for now.
Consequences
- A feature is one class plus tests, a dependency line and a line in
Features.TestGamefakes the game for tests. smokeModules(desktop) andmodules.steps(page) check it end to end.