textmode.js 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/textmode.esm.js +965 -965
- package/dist/textmode.umd.js +13 -13
- package/dist/types/Textmode.d.ts +133 -0
- package/dist/types/errors/Error.d.ts +24 -0
- package/dist/types/errors/ErrorHandler.d.ts +77 -0
- package/dist/types/errors/index.d.ts +2 -0
- package/dist/types/exports/conversion.d.ts +1 -0
- package/dist/types/exports/filters.d.ts +1 -0
- package/dist/types/exports/input.d.ts +1 -0
- package/dist/types/exports/layering.d.ts +1 -0
- package/dist/types/exports/loadables.d.ts +1 -0
- package/dist/types/exports/loading.d.ts +1 -0
- package/dist/types/exports/plugins.d.ts +1 -0
- package/dist/types/index.d.ts +85 -0
- package/dist/types/rendering/index.d.ts +4 -0
- package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +89 -0
- package/dist/types/rendering/webgl/batching/GeometryAttributeCache.d.ts +18 -0
- package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +83 -0
- package/dist/types/rendering/webgl/batching/InstanceBatch.d.ts +87 -0
- package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +68 -0
- package/dist/types/rendering/webgl/batching/InstanceData.d.ts +56 -0
- package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +78 -0
- package/dist/types/rendering/webgl/core/Framebuffer.d.ts +94 -0
- package/dist/types/rendering/webgl/core/Renderer.d.ts +78 -0
- package/dist/types/rendering/webgl/core/Shader.d.ts +62 -0
- package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +101 -0
- package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +214 -0
- package/dist/types/rendering/webgl/geometries/2d/Arc.d.ts +17 -0
- package/dist/types/rendering/webgl/geometries/2d/BezierCurve.d.ts +23 -0
- package/dist/types/rendering/webgl/geometries/2d/Ellipse.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Line.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Rectangle.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/2d/Triangle.d.ts +21 -0
- package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +57 -0
- package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +33 -0
- package/dist/types/rendering/webgl/geometries/index.d.ts +6 -0
- package/dist/types/rendering/webgl/geometries/utils/GeometryDescriptors.d.ts +31 -0
- package/dist/types/rendering/webgl/geometries/utils/GeometryGenerator.d.ts +16 -0
- package/dist/types/rendering/webgl/index.d.ts +19 -0
- package/dist/types/rendering/webgl/materials/Material.d.ts +23 -0
- package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +56 -0
- package/dist/types/rendering/webgl/materials/index.d.ts +2 -0
- package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +54 -0
- package/dist/types/rendering/webgl/pipeline/index.d.ts +7 -0
- package/dist/types/rendering/webgl/state/RenderState.d.ts +159 -0
- package/dist/types/rendering/webgl/types/DrawCommand.d.ts +29 -0
- package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +147 -0
- package/dist/types/rendering/webgl/types/RenderTypes.d.ts +18 -0
- package/dist/types/rendering/webgl/types/UniformTypes.d.ts +11 -0
- package/dist/types/rendering/webgl/utils/GLUtils.d.ts +68 -0
- package/dist/types/rendering/webgl/utils/ViewportCache.d.ts +3 -0
- package/dist/types/rendering/webgl/utils/hash.d.ts +102 -0
- package/dist/types/textmode/AnimationController.d.ts +110 -0
- package/dist/types/textmode/Canvas.d.ts +58 -0
- package/dist/types/textmode/Grid.d.ts +563 -0
- package/dist/types/textmode/TextmodeColor.d.ts +405 -0
- package/dist/types/textmode/Textmodifier.d.ts +113 -0
- package/dist/types/textmode/conversion/ConversionManager.d.ts +89 -0
- package/dist/types/textmode/conversion/ConversionRegistry.d.ts +78 -0
- package/dist/types/textmode/conversion/index.d.ts +2 -0
- package/dist/types/textmode/conversion/strategies/brightness.d.ts +2 -0
- package/dist/types/textmode/filters/FilterManager.d.ts +132 -0
- package/dist/types/textmode/filters/index.d.ts +2 -0
- package/dist/types/textmode/filters/types.d.ts +78 -0
- package/dist/types/textmode/interfaces/IDisposable.d.ts +14 -0
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +753 -0
- package/dist/types/textmode/interfaces/index.d.ts +2 -0
- package/dist/types/textmode/layers/Layer2DCompositor.d.ts +89 -0
- package/dist/types/textmode/layers/LayerManager.d.ts +115 -0
- package/dist/types/textmode/layers/TextmodeLayer.d.ts +105 -0
- package/dist/types/textmode/layers/index.d.ts +4 -0
- package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +158 -0
- package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +821 -0
- package/dist/types/textmode/layers/types.d.ts +78 -0
- package/dist/types/textmode/loadables/ITextmodeSource.d.ts +541 -0
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +45 -0
- package/dist/types/textmode/loadables/TextmodeSource.d.ts +65 -0
- package/dist/types/textmode/loadables/TextmodeTexture.d.ts +95 -0
- package/dist/types/textmode/loadables/font/CharacterColorMapper.d.ts +34 -0
- package/dist/types/textmode/loadables/font/CharacterExtractor.d.ts +22 -0
- package/dist/types/textmode/loadables/font/MetricsCalculator.d.ts +23 -0
- package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +176 -0
- package/dist/types/textmode/loadables/font/TextureAtlas.d.ts +66 -0
- package/dist/types/textmode/loadables/font/index.d.ts +8 -0
- package/dist/types/textmode/loadables/font/types.d.ts +28 -0
- package/dist/types/textmode/loadables/font/typr/Typr.d.ts +20 -0
- package/dist/types/textmode/loadables/font/typr/types.d.ts +241 -0
- package/dist/types/textmode/loadables/font/utils/CmapUtils.d.ts +11 -0
- package/dist/types/textmode/loadables/font/utils/FontTableReader.d.ts +40 -0
- package/dist/types/textmode/loadables/font/utils/index.d.ts +7 -0
- package/dist/types/textmode/loadables/index.d.ts +6 -0
- package/dist/types/textmode/loadables/video/ITextmodeVideo.d.ts +339 -0
- package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +81 -0
- package/dist/types/textmode/loading/LoadingPhase.d.ts +28 -0
- package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +20 -0
- package/dist/types/textmode/loading/LoadingScreenManager.d.ts +208 -0
- package/dist/types/textmode/loading/LoadingScreenState.d.ts +22 -0
- package/dist/types/textmode/loading/LoadingScreenTheme.d.ts +26 -0
- package/dist/types/textmode/loading/LoadingScreenTransition.d.ts +17 -0
- package/dist/types/textmode/loading/index.d.ts +7 -0
- package/dist/types/textmode/loading/templates/SpinnerTemplate.d.ts +2 -0
- package/dist/types/textmode/loading/templates/index.d.ts +1 -0
- package/dist/types/textmode/loading/types.d.ts +255 -0
- package/dist/types/textmode/managers/KeyboardManager.d.ts +128 -0
- package/dist/types/textmode/managers/MouseManager.d.ts +159 -0
- package/dist/types/textmode/managers/PluginManager.d.ts +220 -0
- package/dist/types/textmode/managers/TouchManager.d.ts +237 -0
- package/dist/types/textmode/managers/index.d.ts +12 -0
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +8 -0
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +13 -0
- package/dist/types/textmode/mixins/MouseMixin.d.ts +10 -0
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +8 -0
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +19 -0
- package/dist/types/textmode/mixins/TouchMixin.d.ts +6 -0
- package/dist/types/textmode/mixins/index.d.ts +9 -0
- package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +674 -0
- package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +234 -0
- package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +425 -0
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +2147 -0
- package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +509 -0
- package/dist/types/textmode/types.d.ts +52 -0
- package/dist/types/utils/Disposable.d.ts +18 -0
- package/dist/types/utils/TextmodeCollection.d.ts +172 -0
- package/dist/types/utils/array.d.ts +34 -0
- package/dist/types/utils/color.d.ts +61 -0
- package/dist/types/utils/input.d.ts +11 -0
- package/dist/types/utils/math.d.ts +118 -0
- package/dist/types/utils/shader.d.ts +12 -0
- package/package.json +2 -2
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { GLRenderer, GLFramebuffer } from '../../rendering';
|
|
2
|
+
import type { TextmodeLayer } from './TextmodeLayer';
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for the composite operation.
|
|
5
|
+
*/
|
|
6
|
+
export interface CompositeParams {
|
|
7
|
+
/** The base layer placement (texture + size + offset). */
|
|
8
|
+
base: CompositeLayerPlacement;
|
|
9
|
+
/** The array of user layer placements to composite on top of the base. */
|
|
10
|
+
layers: readonly CompositeLayerPlacement[];
|
|
11
|
+
/** The target framebuffer to render the final result into. */
|
|
12
|
+
targetFramebuffer: GLFramebuffer;
|
|
13
|
+
/** The background color as RGBA values (0-1 range). */
|
|
14
|
+
backgroundColor: [number, number, number, number];
|
|
15
|
+
/** Canvas width in pixels. */
|
|
16
|
+
canvasWidth: number;
|
|
17
|
+
/** Canvas height in pixels. */
|
|
18
|
+
canvasHeight: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Represents the placement and sizing of a single layer within the composite operation.
|
|
22
|
+
* Used to position layers relative to the base canvas during compositing.
|
|
23
|
+
*/
|
|
24
|
+
export interface CompositeLayerPlacement {
|
|
25
|
+
/** The {@link TextmodeLayer} instance being composited. */
|
|
26
|
+
layer: TextmodeLayer;
|
|
27
|
+
/** The WebGL texture containing the layer's rendered content. */
|
|
28
|
+
texture: WebGLTexture;
|
|
29
|
+
/** The width of the layer's texture in pixels. */
|
|
30
|
+
width: number;
|
|
31
|
+
/** The height of the layer's texture in pixels. */
|
|
32
|
+
height: number;
|
|
33
|
+
/** The horizontal offset from the canvas origin in pixels. */
|
|
34
|
+
offsetX: number;
|
|
35
|
+
/** The vertical offset from the canvas origin in pixels. */
|
|
36
|
+
offsetY: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Handles the compositing of multiple layers using shader-based blending.
|
|
40
|
+
*
|
|
41
|
+
* This class is responsible for:
|
|
42
|
+
* - Managing ping-pong framebuffers for layer compositing
|
|
43
|
+
* - Applying blend modes via the composite shader
|
|
44
|
+
* - Rendering the final composited result to a target framebuffer
|
|
45
|
+
*
|
|
46
|
+
* @ignore
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* The compositor uses a ping-pong buffer technique to avoid WebGL feedback loops
|
|
50
|
+
* when reading from and writing to textures during blend operations.
|
|
51
|
+
*/
|
|
52
|
+
export declare class Layer2DCompositor {
|
|
53
|
+
private readonly _renderer;
|
|
54
|
+
private readonly _blendShader;
|
|
55
|
+
private _pingPongBuffers;
|
|
56
|
+
private _currentPingPongIndex;
|
|
57
|
+
/**
|
|
58
|
+
* Create a new LayerCompositor.
|
|
59
|
+
* @param renderer The WebGL renderer instance.
|
|
60
|
+
* @param canvasWidth The canvas width in pixels.
|
|
61
|
+
* @param canvasHeight The canvas height in pixels.
|
|
62
|
+
*/
|
|
63
|
+
constructor(renderer: GLRenderer, canvasWidth: number, canvasHeight: number);
|
|
64
|
+
/**
|
|
65
|
+
* Composite all layers onto the target framebuffer.
|
|
66
|
+
* @param params The composite parameters.
|
|
67
|
+
*/
|
|
68
|
+
$composite(params: CompositeParams): void;
|
|
69
|
+
/**
|
|
70
|
+
* Blend a single layer onto the current composite.
|
|
71
|
+
*/
|
|
72
|
+
private _blendLayer;
|
|
73
|
+
/**
|
|
74
|
+
* Copy the final composite result to the target framebuffer.
|
|
75
|
+
*/
|
|
76
|
+
private _copyToTarget;
|
|
77
|
+
/**
|
|
78
|
+
* Resize the compositor's framebuffers.
|
|
79
|
+
* @param canvasWidth The canvas width in pixels.
|
|
80
|
+
* @param canvasHeight The canvas height in pixels.
|
|
81
|
+
* @ignore
|
|
82
|
+
*/
|
|
83
|
+
$resize(canvasWidth: number, canvasHeight: number): void;
|
|
84
|
+
/**
|
|
85
|
+
* Dispose of all compositor resources.
|
|
86
|
+
* @ignore
|
|
87
|
+
*/
|
|
88
|
+
$dispose(): void;
|
|
89
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import type { GLFramebuffer } from '../../rendering';
|
|
2
|
+
import type { Textmodifier } from '../Textmodifier';
|
|
3
|
+
import { TextmodeLayer } from './TextmodeLayer';
|
|
4
|
+
import type { TextmodeLayerOptions } from './types';
|
|
5
|
+
import type { ILayerManager } from './interfaces/ILayerManager';
|
|
6
|
+
import type { TextmodeOptions } from '../types';
|
|
7
|
+
import type { TextmodeGrid } from '../Grid';
|
|
8
|
+
import { type FilterName, type BuiltInFilterName, type BuiltInFilterParams, TextmodeFilterManager } from '../filters';
|
|
9
|
+
/**
|
|
10
|
+
* Manages the stack of layers within a {@link Textmodifier} instance.
|
|
11
|
+
*
|
|
12
|
+
* This interface provides methods to create, manage, and organize multiple textmode layers.
|
|
13
|
+
* Layers allow for complex compositing, independent rendering passes, and post-processing effects.
|
|
14
|
+
*
|
|
15
|
+
* The `base` layer is always present at the bottom of the stack. User-created layers are added
|
|
16
|
+
* on top of the base layer.
|
|
17
|
+
*
|
|
18
|
+
* Access this manager via `textmodifier.layers`.
|
|
19
|
+
*/
|
|
20
|
+
export declare class LayerManager implements ILayerManager {
|
|
21
|
+
private readonly _textmodifier;
|
|
22
|
+
private readonly _renderer;
|
|
23
|
+
private readonly _compositor2D;
|
|
24
|
+
private readonly _filterManager;
|
|
25
|
+
private readonly _layers;
|
|
26
|
+
private readonly _baseLayer;
|
|
27
|
+
private _isReady;
|
|
28
|
+
private readonly _gridDimensionChangeCallbacks;
|
|
29
|
+
private _globalFilterQueue;
|
|
30
|
+
private _preFilterFramebuffer;
|
|
31
|
+
private _postFilterFramebuffer;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new LayerManager.
|
|
34
|
+
* @param textmodifier The Textmodifier instance this manager belongs to.
|
|
35
|
+
* @ignore
|
|
36
|
+
*/
|
|
37
|
+
constructor(textmodifier: Textmodifier, opts: TextmodeOptions);
|
|
38
|
+
/**
|
|
39
|
+
* Initialize all pending layers, compositor, and global post-processing resources.
|
|
40
|
+
* @ignore
|
|
41
|
+
*/
|
|
42
|
+
$initialize(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Queue a global filter to be applied after all layers are composited.
|
|
45
|
+
* Intended to be called by Textmodifier.filter().
|
|
46
|
+
* @ignore
|
|
47
|
+
*/
|
|
48
|
+
$queueGlobalFilter<T extends BuiltInFilterName>(name: T, params?: BuiltInFilterParams[T]): void;
|
|
49
|
+
$queueGlobalFilter<TParams = unknown>(name: FilterName, params?: TParams): void;
|
|
50
|
+
/**
|
|
51
|
+
* Clear any queued global filters for the current frame.
|
|
52
|
+
* @ignore
|
|
53
|
+
*/
|
|
54
|
+
$clearGlobalFilterQueue(): void;
|
|
55
|
+
add(options?: TextmodeLayerOptions): TextmodeLayer;
|
|
56
|
+
remove(layer: TextmodeLayer): void;
|
|
57
|
+
move(layer: TextmodeLayer, newIndex: number): void;
|
|
58
|
+
swap(layerA: TextmodeLayer, layerB: TextmodeLayer): void;
|
|
59
|
+
clear(): void;
|
|
60
|
+
/**
|
|
61
|
+
* Render all layers (base and user) and composite them to the provided target framebuffer.
|
|
62
|
+
* This performs ONLY layer rendering + compositing (no global filters, no present).
|
|
63
|
+
*
|
|
64
|
+
* @param targetFramebuffer The framebuffer to render the final composited result to.
|
|
65
|
+
* @ignore
|
|
66
|
+
*/
|
|
67
|
+
$renderAndComposite(targetFramebuffer: GLFramebuffer): void;
|
|
68
|
+
/**
|
|
69
|
+
* Render, composite, apply global filters, present to screen, run post-draw hooks.
|
|
70
|
+
* This replaces the removed "Pass 3/4 + post hooks" section from Textmodifier.$render().
|
|
71
|
+
*
|
|
72
|
+
* @ignore
|
|
73
|
+
*/
|
|
74
|
+
$renderAndPresent(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Composite base + user layers onto the target framebuffer.
|
|
77
|
+
*/
|
|
78
|
+
private _compositeLayers;
|
|
79
|
+
/**
|
|
80
|
+
* Resize all layers, compositor, and global post-processing buffers.
|
|
81
|
+
* @ignore
|
|
82
|
+
*/
|
|
83
|
+
$resize(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Dispose of the layer manager, all layers, compositor, and global post-processing resources.
|
|
86
|
+
* @ignore
|
|
87
|
+
*/
|
|
88
|
+
$dispose(): void;
|
|
89
|
+
get all(): readonly TextmodeLayer[];
|
|
90
|
+
get base(): TextmodeLayer;
|
|
91
|
+
get filters(): TextmodeFilterManager;
|
|
92
|
+
get resultFramebuffer(): GLFramebuffer;
|
|
93
|
+
/**
|
|
94
|
+
* Get the grid of the topmost visible layer.
|
|
95
|
+
* Returns the topmost user layer's grid if any are visible, otherwise returns the base layer's grid.
|
|
96
|
+
* This is useful for input managers that need to map coordinates to the layer the user sees on top.
|
|
97
|
+
* @ignore
|
|
98
|
+
*/
|
|
99
|
+
$getTopmostGrid(): TextmodeGrid | undefined;
|
|
100
|
+
/**
|
|
101
|
+
* Register a callback to be invoked whenever ANY layer's grid dimensions change.
|
|
102
|
+
* This includes the base layer and all user layers.
|
|
103
|
+
* @param callback The callback to invoke on dimension changes.
|
|
104
|
+
* @ignore
|
|
105
|
+
*/
|
|
106
|
+
$onAnyGridDimensionChange(callback: () => void): void;
|
|
107
|
+
/**
|
|
108
|
+
* Notify all registered callbacks that a grid's dimensions have changed.
|
|
109
|
+
*/
|
|
110
|
+
private _notifyGridDimensionChange;
|
|
111
|
+
/**
|
|
112
|
+
* Initialize a single layer with required dependencies.
|
|
113
|
+
*/
|
|
114
|
+
private _initializeLayer;
|
|
115
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { GLFramebuffer, GLRenderer, GLShader } from '../../rendering';
|
|
2
|
+
import { TextmodeGrid } from '../Grid';
|
|
3
|
+
import { TextmodeFont } from '../loadables/font';
|
|
4
|
+
import type { Textmodifier } from '../Textmodifier';
|
|
5
|
+
import type { TextmodeLayerBlendMode, TextmodeLayerOptions, LayerDependencies } from './types';
|
|
6
|
+
import type { FilterName, BuiltInFilterName, BuiltInFilterParams } from '../filters';
|
|
7
|
+
import type { ITextmodeLayer } from './interfaces/ITextmodeLayer';
|
|
8
|
+
/**
|
|
9
|
+
* A single layer within a multi-layered textmode rendering context.
|
|
10
|
+
*
|
|
11
|
+
* Layers are composited together using various blend modes
|
|
12
|
+
* to create complex visual effects. Each layer can be independently
|
|
13
|
+
* manipulated in terms of visibility, {@link opacity}, {@link blendMode}, {@link offset}, rotation, {@link TextmodeGrid}, and {@link TextmodeFont}.
|
|
14
|
+
*
|
|
15
|
+
* You can draw on each layer by providing a draw callback function,
|
|
16
|
+
* like you would with the base layer's {@link Textmodifier.draw} method.
|
|
17
|
+
*
|
|
18
|
+
* Plugins can extend TextmodeLayer with additional methods using the plugin API's
|
|
19
|
+
* `extendLayer` function. For example, the `textmode-synth` plugin adds a `.synth()`
|
|
20
|
+
* method for hydra-like procedural generation.
|
|
21
|
+
*/
|
|
22
|
+
export declare class TextmodeLayer implements ITextmodeLayer {
|
|
23
|
+
/** @ignore */
|
|
24
|
+
$visible: boolean;
|
|
25
|
+
/** @ignore */
|
|
26
|
+
$opacity: number;
|
|
27
|
+
/** @ignore */
|
|
28
|
+
$blendMode: TextmodeLayerBlendMode;
|
|
29
|
+
/** @ignore */
|
|
30
|
+
$offsetX: number;
|
|
31
|
+
/** @ignore */
|
|
32
|
+
$offsetY: number;
|
|
33
|
+
/** @ignore */
|
|
34
|
+
$rotation: number;
|
|
35
|
+
/** @ignore */
|
|
36
|
+
$fontSize: number | undefined;
|
|
37
|
+
/** @ignore */
|
|
38
|
+
$fontSource: string | TextmodeFont | URL | undefined;
|
|
39
|
+
private _deps?;
|
|
40
|
+
private _grid?;
|
|
41
|
+
private _font;
|
|
42
|
+
private _drawFramebuffer;
|
|
43
|
+
private _asciiFramebuffer;
|
|
44
|
+
private _rawAsciiFramebuffer?;
|
|
45
|
+
private _pingPongBuffers?;
|
|
46
|
+
private _drawCallback;
|
|
47
|
+
private _filterQueue;
|
|
48
|
+
private _pluginState;
|
|
49
|
+
/**
|
|
50
|
+
* Create a new TextmodeLayer with the given options.
|
|
51
|
+
* @param renderer The TextmodeRenderer instance.
|
|
52
|
+
* @param options Layer configuration options.
|
|
53
|
+
* @ignore
|
|
54
|
+
*/
|
|
55
|
+
constructor(renderer: GLRenderer, options?: TextmodeLayerOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Attach necessary dependencies for this layer to function.
|
|
58
|
+
* @param deps Dependencies required by the layer.
|
|
59
|
+
* @ignore
|
|
60
|
+
*/
|
|
61
|
+
$attachDependencies(deps: LayerDependencies): Promise<void>;
|
|
62
|
+
draw(callback: () => void): void;
|
|
63
|
+
show(): void;
|
|
64
|
+
hide(): void;
|
|
65
|
+
opacity(opacity?: number): number | void;
|
|
66
|
+
blendMode(mode?: TextmodeLayerBlendMode): TextmodeLayerBlendMode | void;
|
|
67
|
+
offset(x?: number, y?: number): {
|
|
68
|
+
x: number;
|
|
69
|
+
y: number;
|
|
70
|
+
} | void;
|
|
71
|
+
rotateZ(z?: number): number | void;
|
|
72
|
+
filter<T extends BuiltInFilterName>(name: T, params?: BuiltInFilterParams[T]): void;
|
|
73
|
+
filter<TParams = unknown>(name: FilterName, params?: TParams): void;
|
|
74
|
+
setPluginState<T>(pluginName: string, state: T): void;
|
|
75
|
+
getPluginState<T>(pluginName: string): T | undefined;
|
|
76
|
+
hasPluginState(pluginName: string): boolean;
|
|
77
|
+
deletePluginState(pluginName: string): boolean;
|
|
78
|
+
fontSize(size?: number): number | void;
|
|
79
|
+
loadFont(fontSource: string | TextmodeFont): Promise<TextmodeFont>;
|
|
80
|
+
/**
|
|
81
|
+
* Render the layer's content into its ASCII framebuffer.
|
|
82
|
+
* @param textmodifier The Textmodifier instance.
|
|
83
|
+
* @param conversionShader The shader used for conversion.
|
|
84
|
+
* @ignore
|
|
85
|
+
*/
|
|
86
|
+
$render(textmodifier: Textmodifier, conversionShader: GLShader): void;
|
|
87
|
+
/**
|
|
88
|
+
* Resize the layer's framebuffers to match the given grid dimensions.
|
|
89
|
+
* @ignore
|
|
90
|
+
*/
|
|
91
|
+
$resize(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Dispose of the layer's resources.
|
|
94
|
+
* @ignore
|
|
95
|
+
*/
|
|
96
|
+
$dispose(): void;
|
|
97
|
+
get texture(): WebGLTexture | undefined;
|
|
98
|
+
get grid(): TextmodeGrid | undefined;
|
|
99
|
+
get font(): TextmodeFont;
|
|
100
|
+
get width(): number;
|
|
101
|
+
get height(): number;
|
|
102
|
+
get drawFramebuffer(): GLFramebuffer | undefined;
|
|
103
|
+
get asciiFramebuffer(): GLFramebuffer | undefined;
|
|
104
|
+
private _syncGridToFont;
|
|
105
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { TextmodeLayer } from './TextmodeLayer';
|
|
2
|
+
export { LayerManager as TextmodeLayerManager } from './LayerManager';
|
|
3
|
+
export { Layer2DCompositor as LayerCompositor } from './Layer2DCompositor';
|
|
4
|
+
export type { TextmodeLayerOptions, TextmodeLayerBlendMode } from './types';
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type { TextmodeLayer } from '../TextmodeLayer';
|
|
2
|
+
import type { TextmodeLayerOptions } from '../types';
|
|
3
|
+
import type { TextmodeGrid } from '../../Grid';
|
|
4
|
+
import type { GLFramebuffer } from '../../../rendering/webgl/core/Framebuffer';
|
|
5
|
+
export interface ILayerManager {
|
|
6
|
+
/**
|
|
7
|
+
* Get all user layers as a readonly array.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```js
|
|
11
|
+
* const t = textmode.create();
|
|
12
|
+
* t.layers.add();
|
|
13
|
+
* t.layers.add();
|
|
14
|
+
*
|
|
15
|
+
* console.log(t.layers.all.length); // 2
|
|
16
|
+
*
|
|
17
|
+
* // Iterate over all user layers
|
|
18
|
+
* t.layers.all.forEach(layer => {
|
|
19
|
+
* layer.opacity(0.5);
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
readonly all: readonly TextmodeLayer[];
|
|
24
|
+
/**
|
|
25
|
+
* The base layer that is always rendered at the bottom of the layer stack.
|
|
26
|
+
* This layer represents the main drawing content before any user layers are composited.
|
|
27
|
+
*
|
|
28
|
+
* The base layer cannot be removed or moved.
|
|
29
|
+
*/
|
|
30
|
+
readonly base: TextmodeLayer;
|
|
31
|
+
/**
|
|
32
|
+
* The framebuffer containing the final composited result after all layers and filters have been applied.
|
|
33
|
+
*/
|
|
34
|
+
readonly resultFramebuffer: GLFramebuffer;
|
|
35
|
+
/**
|
|
36
|
+
* Create and add a new layer to the top of the layer stack.
|
|
37
|
+
*
|
|
38
|
+
* New layers are initialized with their own grid and font settings.
|
|
39
|
+
* Layers can be offset, rotated, and blended with layers below them.
|
|
40
|
+
*
|
|
41
|
+
* @param options Optional configuration for the new layer (visibility, opacity, blendMode, etc.)
|
|
42
|
+
* @returns The newly created TextmodeLayer instance.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```javascript
|
|
46
|
+
* const t = textmode.create();
|
|
47
|
+
*
|
|
48
|
+
* // Add a new layer on top of the base layer
|
|
49
|
+
* const uiLayer = t.layers.add({
|
|
50
|
+
* blendMode: 'normal',
|
|
51
|
+
* opacity: 1.0,
|
|
52
|
+
* fontSize: 16
|
|
53
|
+
* });
|
|
54
|
+
*
|
|
55
|
+
* // Draw to the new layer
|
|
56
|
+
* uiLayer.draw(() => {
|
|
57
|
+
* t.clear(); // Clear THIS layer's background (transparent)
|
|
58
|
+
*
|
|
59
|
+
* t.charColor(255, 0, 0); // Red text
|
|
60
|
+
* t.cellColor(0, 0, 0, 0); // Transparent cell background
|
|
61
|
+
* t.char('!');
|
|
62
|
+
* t.rect(5, 5);
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* // Base layer content
|
|
66
|
+
* t.draw(() => {
|
|
67
|
+
* t.background(0, 0, 50); // Dark blue background
|
|
68
|
+
*
|
|
69
|
+
* t.charColor(0, 0, 255); // Blue text
|
|
70
|
+
* t.cellColor(0, 0, 0, 0); // Transparent cell background
|
|
71
|
+
* t.char('?');
|
|
72
|
+
* t.rect(5, 5);
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
add(options?: TextmodeLayerOptions): TextmodeLayer;
|
|
77
|
+
/**
|
|
78
|
+
* Remove a layer from the manager.
|
|
79
|
+
* @param layer The layer to remove.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```js
|
|
83
|
+
* const t = textmode.create();
|
|
84
|
+
*
|
|
85
|
+
* const tempLayer = t.layers.add();
|
|
86
|
+
*
|
|
87
|
+
* // Remove the layer after 100 frames
|
|
88
|
+
* t.draw(() => {
|
|
89
|
+
* if (t.frameCount > 100) {
|
|
90
|
+
* t.layers.remove(tempLayer);
|
|
91
|
+
* }
|
|
92
|
+
* });
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
remove(layer: TextmodeLayer): void;
|
|
96
|
+
/**
|
|
97
|
+
* Move a layer to a new index in the layer stack.
|
|
98
|
+
* @param layer The layer to move.
|
|
99
|
+
* @param newIndex The new index for the layer.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```js
|
|
103
|
+
* const t = textmode.create();
|
|
104
|
+
*
|
|
105
|
+
* const bgLayer = t.layers.add(); // Index 0
|
|
106
|
+
* const fgLayer = t.layers.add(); // Index 1
|
|
107
|
+
*
|
|
108
|
+
* // Swap z-order by moving fgLayer to bottom (index 0)
|
|
109
|
+
* // This pushes bgLayer to index 1
|
|
110
|
+
* t.layers.move(fgLayer, 0);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
move(layer: TextmodeLayer, newIndex: number): void;
|
|
114
|
+
/**
|
|
115
|
+
* Swap the order of two layers if they exist in the same collection.
|
|
116
|
+
* @param layerA The first layer to swap.
|
|
117
|
+
* @param layerB The second layer to swap.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```js
|
|
121
|
+
* const t = textmode.create();
|
|
122
|
+
*
|
|
123
|
+
* const layer1 = t.layers.add();
|
|
124
|
+
* const layer2 = t.layers.add();
|
|
125
|
+
*
|
|
126
|
+
* // Swap the layers' positions in the stack
|
|
127
|
+
* t.layers.swap(layer1, layer2);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
swap(layerA: TextmodeLayer, layerB: TextmodeLayer): void;
|
|
131
|
+
/**
|
|
132
|
+
* Remove all user-created layers from the manager.
|
|
133
|
+
* The base layer is not affected by this operation.
|
|
134
|
+
* This is useful for integration into live-coding environments where code is re-evaluated
|
|
135
|
+
* and layers need to be recreated from scratch.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```js
|
|
139
|
+
* const t = textmode.create();
|
|
140
|
+
*
|
|
141
|
+
* t.setup(() => {
|
|
142
|
+
* // Ensure clean slate when re-running setup
|
|
143
|
+
* t.layers.clear();
|
|
144
|
+
*
|
|
145
|
+
* // Re-create layers
|
|
146
|
+
* t.layers.add({ blendMode: 'additive' });
|
|
147
|
+
* t.layers.add({ blendMode: 'multiply' });
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
clear(): void;
|
|
152
|
+
/**
|
|
153
|
+
* Get the grid of the topmost visible layer.
|
|
154
|
+
* Returns the topmost user layer's grid if any are visible, otherwise returns the base layer's grid.
|
|
155
|
+
* This is useful for input managers that need to map coordinates to the layer the user sees on top.
|
|
156
|
+
*/
|
|
157
|
+
$getTopmostGrid(): TextmodeGrid | undefined;
|
|
158
|
+
}
|