textmode.js / plugins / TextmodePluginAPI
Interface: TextmodePluginAPI
An extended API provided to plugins when they are installed on a Textmodifier instance.
Properties
| Property | Type | Description |
|---|---|---|
asciiFramebuffer | TextmodeFramebuffer | The framebuffer containing the ASCII representation (from base layer). This framebuffer only has a single render target. |
canvas | TextmodeCanvas | The canvas used by the Textmodifier instance. |
drawFramebuffer | TextmodeFramebuffer | The framebuffer the user draws to with 3 render targets (from base layer). |
font | TextmodeFont | The font used by the Textmodifier instance (from base layer). |
grid | TextmodeGrid | The grid used by the Textmodifier instance (from base layer). |
layerManager | TextmodeLayerManager | The layer manager for accessing and managing all layers. |
renderer | GLRenderer | The WebGL renderer used by the Textmodifier instance. |
Methods
extendLayer()
extendLayer<TArgs, TReturn>(methodName, implementation): void;Extend TextmodeLayer instances with a new method. The method will be available on all existing and future layer instances.
Type Parameters
| Type Parameter |
|---|
TArgs extends unknown[] |
TReturn |
Parameters
| Parameter | Type | Description |
|---|---|---|
methodName | string | The name of the method to add. |
implementation | (this, ...args) => TReturn | The implementation function. this will be bound to the TextmodeLayer instance. |
Returns
void
Example
api.extendLayer('synth', function(source: SynthSource) {
// `this` is the TextmodeLayer instance
this.setPluginState('synth', { source, compiled: compile(source) });
});registerLayerDisposedHook()
registerLayerDisposedHook(callback): () => void;Register a callback to be invoked when a layer is about to be disposed.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | LayerLifecycleHook | The callback to invoke with the layer being disposed. |
Returns
A function to unregister the hook.
(): void;Returns
void
registerLayerPostRenderHook()
registerLayerPostRenderHook(callback): () => void;Register a callback to be invoked after each layer's render cycle. This happens after the user draw callback but before ASCII conversion.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | LayerRenderHook | The callback to invoke with the layer and render context. |
Returns
A function to unregister the hook.
(): void;Returns
void
registerLayerPreRenderHook()
registerLayerPreRenderHook(callback): () => void;Register a callback to be invoked before each layer's render cycle. This happens after the layer's visibility check but before any drawing operations. Useful for rendering content to the layer's framebuffer before user draw callbacks.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | LayerRenderHook | The callback to invoke with the layer and render context. |
Returns
A function to unregister the hook.
(): void;Returns
void
registerPostDrawHook()
registerPostDrawHook(callback): () => void;Register a callback to be invoked after each draw cycle. Happens outside of the draw framebuffer being bound after the final result is drawn to the screen.
Parameters
| Parameter | Type |
|---|---|
callback | () => void |
Returns
A function to unregister the hook.
(): void;Returns
void
registerPostSetupHook()
registerPostSetupHook(callback): () => void;Register a callback to be invoked after the user's setup callback completes. This happens after user code in setup() has finished executing, but before the loading screen finishes and the main render loop begins. Useful for plugins that need to finalize initialization after user setup.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | () => void | Promise<void> | The callback to invoke after setup. |
Returns
A function to unregister the hook.
(): void;Returns
void
registerPreDrawHook()
registerPreDrawHook(callback): () => void;Register a callback to be invoked before each draw cycle. Happens just before any framebuffer
Parameters
| Parameter | Type |
|---|---|
callback | () => void |
Returns
A function to unregister the hook.
(): void;Returns
void
registerPreSetupHook()
registerPreSetupHook(callback): () => void;Register a callback to be invoked before the user's setup callback runs. This happens after the Textmodifier and all layers are fully initialized, but before user code in setup() executes. Useful for plugins that need to prepare resources or state before user setup.
Parameters
| Parameter | Type | Description |
|---|---|---|
callback | () => void | Promise<void> | The callback to invoke before setup. |
Returns
A function to unregister the hook.
(): void;Returns
void
removeLayerExtension()
removeLayerExtension(methodName): void;Remove a method extension from TextmodeLayer.
Parameters
| Parameter | Type | Description |
|---|---|---|
methodName | string | The name of the method to remove. |
Returns
void