textmode.js 0.2.1-beta.1 → 0.2.1-beta.3
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 +1470 -1442
- package/dist/textmode.esm.min.js +1356 -1328
- package/dist/textmode.umd.js +10 -26
- package/dist/textmode.umd.min.js +9 -25
- package/dist/types/assets/shaders-minified/frag/ascii.d.ts +14 -0
- package/dist/types/assets/shaders-minified/frag/copy-mrt.d.ts +14 -0
- package/dist/types/assets/shaders-minified/frag/instanced-ascii-mrt.d.ts +14 -0
- package/dist/types/assets/shaders-minified/index.d.ts +5 -0
- package/dist/types/assets/shaders-minified/vert/instanced-ascii-mrt.d.ts +14 -0
- package/dist/types/assets/shaders-minified/vert/shader.d.ts +14 -0
- package/dist/types/export/svg/SVGContentGenerator.d.ts +0 -6
- package/dist/types/index.d.ts +2 -0
- package/dist/types/rendering/index.d.ts +2 -0
- package/dist/types/rendering/webgl/Framebuffer.d.ts +31 -20
- package/dist/types/rendering/webgl/InstanceData.d.ts +1 -1
- package/dist/types/rendering/webgl/RenderPipeline.d.ts +10 -3
- package/dist/types/rendering/webgl/RenderState.d.ts +11 -11
- package/dist/types/rendering/webgl/Renderer.d.ts +26 -2
- package/dist/types/rendering/webgl/Shader.d.ts +7 -8
- package/dist/types/rendering/webgl/ShaderManager.d.ts +65 -1
- package/dist/types/rendering/webgl/index.d.ts +1 -0
- package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +7 -7
- package/dist/types/rendering/webgl/types/ShaderTypes.d.ts +35 -0
- package/dist/types/textmode/Textmodifier.d.ts +2 -2
- package/dist/types/textmode/managers/index.d.ts +4 -0
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +0 -4
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +75 -19
- package/dist/types/textmode/mixins/MouseMixin.d.ts +101 -8
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +92 -0
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +2 -2
- package/dist/types/textmode/mixins/index.d.ts +2 -2
- package/package.json +4 -3
- package/dist/types/textmode/keyboard/index.d.ts +0 -2
- package/dist/types/textmode/mouse/index.d.ts +0 -2
- /package/dist/types/textmode/{keyboard → managers}/KeyboardManager.d.ts +0 -0
- /package/dist/types/textmode/{mouse → managers}/MouseManager.d.ts +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { GLRenderer } from './Renderer';
|
|
1
2
|
export type FramebufferOptions = {
|
|
2
3
|
/** Texture filtering mode */
|
|
3
4
|
filter?: 'nearest' | 'linear';
|
|
@@ -9,10 +10,7 @@ export type FramebufferOptions = {
|
|
|
9
10
|
type?: 'unsigned_byte' | 'float';
|
|
10
11
|
};
|
|
11
12
|
/**
|
|
12
|
-
*
|
|
13
|
-
* Provides GPU-accelerated render targets with automatic texture creation.
|
|
14
|
-
* Supports both single-texture and Multiple Render Targets (MRT) functionality.
|
|
15
|
-
* Can also be used as a standalone texture (without render target functionality).
|
|
13
|
+
* Framebuffer class for managing offscreen rendering targets.
|
|
16
14
|
*/
|
|
17
15
|
export declare class GLFramebuffer {
|
|
18
16
|
protected _width: number;
|
|
@@ -25,46 +23,59 @@ export declare class GLFramebuffer {
|
|
|
25
23
|
private _attachmentCount;
|
|
26
24
|
private _previousState;
|
|
27
25
|
private _attachmentPixels;
|
|
28
|
-
|
|
26
|
+
private _renderer;
|
|
27
|
+
private _isolatedState;
|
|
28
|
+
private _stateForFBO;
|
|
29
|
+
/**
|
|
30
|
+
* Create a new GLFramebuffer instance.
|
|
31
|
+
* @param gl WebGL2 rendering context
|
|
32
|
+
* @param width Framebuffer width
|
|
33
|
+
* @param height Framebuffer height
|
|
34
|
+
* @param attachmentCount Number of color attachments
|
|
35
|
+
* @param options Framebuffer options
|
|
36
|
+
* @param renderer Optional GLRenderer instance for state management
|
|
37
|
+
* @param isolatedState Optional flag to isolate framebuffer state from renderer
|
|
38
|
+
* @ignore
|
|
39
|
+
*/
|
|
40
|
+
constructor(gl: WebGL2RenderingContext, width: number, height?: number, attachmentCount?: number, options?: FramebufferOptions, renderer?: GLRenderer | null, isolatedState?: boolean);
|
|
29
41
|
private _createTextures;
|
|
30
42
|
private _attachTextures;
|
|
31
43
|
/**
|
|
32
44
|
* Update the framebuffer texture with canvas or video content
|
|
33
45
|
* Note: Only updates the first attachment in multi-attachment mode
|
|
46
|
+
* @ignore
|
|
34
47
|
*/
|
|
35
48
|
$update(source: HTMLCanvasElement | HTMLVideoElement): void;
|
|
36
49
|
/**
|
|
37
|
-
* Resize the framebuffer
|
|
50
|
+
* Resize the framebuffer.
|
|
51
|
+
* @param width New width
|
|
52
|
+
* @param height New height
|
|
38
53
|
*/
|
|
39
|
-
|
|
54
|
+
resize(width: number, height: number): void;
|
|
40
55
|
/**
|
|
41
56
|
* Read pixels from a specific color attachment into an RGBA Uint8Array.
|
|
42
57
|
* Rows are flipped to top-left origin to match row-major iteration in exporters.
|
|
58
|
+
* @ignore
|
|
43
59
|
*/
|
|
44
60
|
$readAttachment(attachmentIndex: number): Uint8Array;
|
|
45
|
-
/** Read and cache all attachments. */
|
|
46
|
-
$readAll(): void;
|
|
47
61
|
/**
|
|
48
|
-
* Begin rendering to this framebuffer
|
|
62
|
+
* Begin rendering to this framebuffer.
|
|
49
63
|
*/
|
|
50
|
-
|
|
64
|
+
begin(): void;
|
|
51
65
|
/**
|
|
52
|
-
* End rendering to this framebuffer and restore previous state
|
|
66
|
+
* End rendering to this framebuffer and restore previous state.
|
|
53
67
|
*/
|
|
54
|
-
|
|
68
|
+
end(): void;
|
|
55
69
|
/**
|
|
56
70
|
* Dispose of WebGL resources used by this framebuffer.
|
|
57
71
|
* This method is idempotent and safe to call multiple times.
|
|
72
|
+
* @ignore
|
|
58
73
|
*/
|
|
59
74
|
$dispose(): void;
|
|
75
|
+
/** Get the current framebuffer width. */
|
|
60
76
|
get width(): number;
|
|
77
|
+
/** Get the current framebuffer height. */
|
|
61
78
|
get height(): number;
|
|
62
|
-
|
|
63
|
-
get options(): FramebufferOptions;
|
|
64
|
-
get framebuffer(): WebGLFramebuffer | null;
|
|
65
|
-
get texture(): WebGLTexture;
|
|
79
|
+
/** Get all textures associated with this framebuffer. */
|
|
66
80
|
get textures(): WebGLTexture[];
|
|
67
|
-
get attachmentCount(): number;
|
|
68
|
-
/** Return a cached copy of pixels for an attachment if previously read, else null. */
|
|
69
|
-
getAttachmentPixels(attachmentIndex: number): Uint8Array | null;
|
|
70
81
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
export interface InstanceData {
|
|
6
6
|
position: [number, number];
|
|
7
7
|
size: [number, number];
|
|
8
|
-
|
|
8
|
+
_character: [number, number, number];
|
|
9
9
|
primaryColor: [number, number, number, number];
|
|
10
10
|
secondaryColor: [number, number, number, number];
|
|
11
11
|
rotation: [number, number];
|
|
@@ -2,6 +2,10 @@ import type { IGeometry } from './types/GeometryTypes';
|
|
|
2
2
|
import { GeometryType } from './types/GeometryTypes';
|
|
3
3
|
import type { RenderContext } from './types/RenderTypes';
|
|
4
4
|
import type { DrawCommand } from './types/DrawCommand';
|
|
5
|
+
import { GLShader } from './Shader';
|
|
6
|
+
interface IShaderProvider {
|
|
7
|
+
$getCopyShader(): GLShader;
|
|
8
|
+
}
|
|
5
9
|
/**
|
|
6
10
|
* Execute draw commands exactly in the order they were enqueued while
|
|
7
11
|
* still batching consecutive commands of the same geometry type to minimize
|
|
@@ -10,13 +14,16 @@ import type { DrawCommand } from './types/DrawCommand';
|
|
|
10
14
|
export declare class RenderPipeline {
|
|
11
15
|
private readonly _vaoMgr;
|
|
12
16
|
private readonly _gl;
|
|
13
|
-
private
|
|
17
|
+
private readonly _renderer;
|
|
14
18
|
private _tempRectFBO;
|
|
15
19
|
private _tempRectFBOSize;
|
|
16
|
-
constructor(gl: WebGL2RenderingContext);
|
|
20
|
+
constructor(gl: WebGL2RenderingContext, renderer: IShaderProvider);
|
|
17
21
|
$execute(context: RenderContext, commands: Iterable<DrawCommand>, geometries: Map<GeometryType, IGeometry>): void;
|
|
18
|
-
/**
|
|
22
|
+
/** Execute a custom-shaded rectangle using provided shader/uniforms */
|
|
19
23
|
private _drawCustomRect;
|
|
24
|
+
/** Draw a rectangle with the specified shader, uniforms, and viewport handling */
|
|
25
|
+
private _drawRectangleWithShader;
|
|
20
26
|
private _getCopyShader;
|
|
21
27
|
private _getTempRectFBO;
|
|
22
28
|
}
|
|
29
|
+
export {};
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
* Represents a snapshot of the current rendering state
|
|
3
3
|
*/
|
|
4
4
|
export interface IRenderState {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
_lineWeight: number;
|
|
6
|
+
_rotationX: number;
|
|
7
|
+
_rotationY: number;
|
|
8
|
+
_rotationZ: number;
|
|
9
|
+
_character: [number, number, number];
|
|
10
|
+
_charColor: [number, number, number, number];
|
|
11
|
+
_cellColor: [number, number, number, number];
|
|
12
|
+
_flipHorizontally: boolean;
|
|
13
|
+
_flipVertically: boolean;
|
|
14
|
+
_invert: boolean;
|
|
15
|
+
_charRotation: [number, number];
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Manages rendering state and provides push/pop functionality for state management
|
|
@@ -2,12 +2,14 @@ import { GLFramebuffer } from "./Framebuffer";
|
|
|
2
2
|
import type { FramebufferOptions } from '../webgl/Framebuffer';
|
|
3
3
|
import { GLShader } from "./Shader";
|
|
4
4
|
import { RenderState } from "./RenderState";
|
|
5
|
+
import type { ShaderSource } from './types/ShaderTypes';
|
|
5
6
|
/**
|
|
6
7
|
* Core WebGL renderer that manages the WebGL context and provides high-level rendering operations
|
|
7
8
|
*/
|
|
8
9
|
export declare class GLRenderer {
|
|
9
10
|
private _gl;
|
|
10
11
|
private _currentShader;
|
|
12
|
+
private _shaderManager;
|
|
11
13
|
private _userShader;
|
|
12
14
|
private _userUniforms;
|
|
13
15
|
private _ndcQuadBuffer;
|
|
@@ -15,6 +17,7 @@ export declare class GLRenderer {
|
|
|
15
17
|
private readonly _renderPipeline;
|
|
16
18
|
private readonly _drawQueue;
|
|
17
19
|
private _renderState;
|
|
20
|
+
private _stateStack;
|
|
18
21
|
constructor(gl: WebGL2RenderingContext);
|
|
19
22
|
/** Get or create a geometry instance */
|
|
20
23
|
private _getGeometry;
|
|
@@ -22,7 +25,19 @@ export declare class GLRenderer {
|
|
|
22
25
|
* Set the current shader
|
|
23
26
|
*/
|
|
24
27
|
$shader(shader: GLShader): void;
|
|
25
|
-
$createShader(vertexSource:
|
|
28
|
+
$createShader(vertexSource: ShaderSource, fragmentSource: ShaderSource): GLShader;
|
|
29
|
+
/**
|
|
30
|
+
* Get the shared MRT copy shader
|
|
31
|
+
*/
|
|
32
|
+
$getCopyShader(): GLShader;
|
|
33
|
+
/**
|
|
34
|
+
* Get the main MRT draw shader
|
|
35
|
+
*/
|
|
36
|
+
$getMainDrawShader(): GLShader;
|
|
37
|
+
/**
|
|
38
|
+
* Get the ASCII conversion shader
|
|
39
|
+
*/
|
|
40
|
+
$getConversionShader(): GLShader;
|
|
26
41
|
/**
|
|
27
42
|
* Set a custom user shader for subsequent rendering operations
|
|
28
43
|
*/
|
|
@@ -30,7 +45,7 @@ export declare class GLRenderer {
|
|
|
30
45
|
/**
|
|
31
46
|
* Set a uniform value for the current user shader
|
|
32
47
|
*/
|
|
33
|
-
$
|
|
48
|
+
$setUniform(name: string, value: any): void;
|
|
34
49
|
/**
|
|
35
50
|
* Set multiple uniform values for the current user shader
|
|
36
51
|
*/
|
|
@@ -39,6 +54,11 @@ export declare class GLRenderer {
|
|
|
39
54
|
* Create a filter shader using the standard instanced vertex shader
|
|
40
55
|
*/
|
|
41
56
|
$createFilterShader(fragmentSource: string): GLShader;
|
|
57
|
+
/**
|
|
58
|
+
* Enqueue an image blit from a source MRT framebuffer to the current render target.
|
|
59
|
+
* This uses the internal copy shader and preserves draw ordering within the pipeline.
|
|
60
|
+
*/
|
|
61
|
+
$imageRect(src: GLFramebuffer, x: number, y: number, width: number, height: number): void;
|
|
42
62
|
/**
|
|
43
63
|
* Draw a quad covering the pixel rectangle (x, y, width, height) on the canvas.
|
|
44
64
|
* The quad is converted to NDC and rendered with the current shader using only a_position.
|
|
@@ -109,6 +129,10 @@ export declare class GLRenderer {
|
|
|
109
129
|
*/
|
|
110
130
|
get context(): WebGLRenderingContext;
|
|
111
131
|
get state(): RenderState;
|
|
132
|
+
/** Internal: push a specific render state as current (used by user FBO begin) */
|
|
133
|
+
$pushState(state: RenderState): void;
|
|
134
|
+
/** Internal: pop the render state after user FBO end */
|
|
135
|
+
$popState(): void;
|
|
112
136
|
/**
|
|
113
137
|
* Flush all batched instances for instanced rendering.
|
|
114
138
|
* This must be called at the end of each frame to actually render the batched geometry.
|
|
@@ -1,27 +1,26 @@
|
|
|
1
1
|
import { GLFramebuffer } from './Framebuffer';
|
|
2
|
+
import type { ShaderSource } from './types/ShaderTypes';
|
|
2
3
|
/**
|
|
3
4
|
* Supported uniform value types
|
|
4
5
|
*/
|
|
5
|
-
type UniformValue = number | boolean | number[] | Float32Array | Int32Array | GLFramebuffer | WebGLTexture;
|
|
6
|
+
type UniformValue = number | boolean | number[] | number[][] | Float32Array | Int32Array | GLFramebuffer | WebGLTexture;
|
|
6
7
|
/**
|
|
7
8
|
* WebGL implementation of the shader abstraction.
|
|
8
|
-
* Provides GPU shader program management with automatic uniform handling.
|
|
9
|
+
* Provides GPU shader program management with automatic uniform handling and minification support.
|
|
9
10
|
*/
|
|
10
11
|
export declare class GLShader {
|
|
11
12
|
private _gl;
|
|
12
13
|
private _program;
|
|
13
14
|
private _uniformLocations;
|
|
14
|
-
private _uniformTypes;
|
|
15
15
|
private _textureUnitCounter;
|
|
16
|
-
private _maxTextureUnits;
|
|
17
16
|
/**
|
|
18
17
|
* Creates a new GLShader instance.
|
|
19
18
|
* @param gl The WebGL rendering context.
|
|
20
|
-
* @param vertexSource The source code for the vertex shader.
|
|
21
|
-
* @param fragmentSource The source code for the fragment shader.
|
|
19
|
+
* @param vertexSource The source code for the vertex shader (or ShaderData object).
|
|
20
|
+
* @param fragmentSource The source code for the fragment shader (or ShaderData object).
|
|
22
21
|
* @ignore
|
|
23
22
|
*/
|
|
24
|
-
constructor(gl: WebGLRenderingContext, vertexSource:
|
|
23
|
+
constructor(gl: WebGLRenderingContext, vertexSource: ShaderSource, fragmentSource: ShaderSource);
|
|
25
24
|
private _cacheLocations;
|
|
26
25
|
private _createProgram;
|
|
27
26
|
private _createShader;
|
|
@@ -39,7 +38,7 @@ export declare class GLShader {
|
|
|
39
38
|
*/
|
|
40
39
|
$hasUniform(name: string): boolean;
|
|
41
40
|
/**
|
|
42
|
-
* Set a single uniform value with automatic texture unit management
|
|
41
|
+
* Set a single uniform value with automatic texture unit management and minification support
|
|
43
42
|
*/
|
|
44
43
|
$setUniform(name: string, value: UniformValue): void;
|
|
45
44
|
private _getNextTextureUnit;
|
|
@@ -1 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
import { GLShader } from './Shader';
|
|
2
|
+
import type { ShaderSource } from './types/ShaderTypes';
|
|
3
|
+
/**
|
|
4
|
+
* Registry keys for built-in shaders
|
|
5
|
+
*/
|
|
6
|
+
export declare enum BuiltInShader {
|
|
7
|
+
MRT_DRAW = "mrt-draw",
|
|
8
|
+
MRT_COPY = "mrt-copy",
|
|
9
|
+
ASCII_CONVERSION = "ascii-conversion"
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Centralized shader management system for textmode.js
|
|
13
|
+
*
|
|
14
|
+
* Provides a registry pattern for managing shared shaders, eliminating
|
|
15
|
+
* duplication and providing a single source of truth for shader lifecycle.
|
|
16
|
+
*
|
|
17
|
+
* Key benefits:
|
|
18
|
+
* - Eliminates shader duplication (especially copy shader)
|
|
19
|
+
* - Centralizes vertex shader imports
|
|
20
|
+
* - Provides lazy initialization
|
|
21
|
+
* - Supports future extensibility (shader variants, hot-reloading)
|
|
22
|
+
* - Consistent resource management
|
|
23
|
+
*/
|
|
24
|
+
export declare class ShaderManager {
|
|
25
|
+
private _shaders;
|
|
26
|
+
private _gl;
|
|
27
|
+
constructor(gl: WebGL2RenderingContext);
|
|
28
|
+
/**
|
|
29
|
+
* Get or create a shader with lazy initialization
|
|
30
|
+
* @param key Unique identifier for the shader
|
|
31
|
+
* @param factory Function that creates the shader if it doesn't exist
|
|
32
|
+
* @returns The shader instance
|
|
33
|
+
*/
|
|
34
|
+
$getOrCreateShader(key: string, factory: () => GLShader): GLShader;
|
|
35
|
+
/**
|
|
36
|
+
* Get the shared MRT copy shader used for framebuffer compositing
|
|
37
|
+
* This shader handles copying 5-attachment MRT data with proper transparency
|
|
38
|
+
*/
|
|
39
|
+
$getCopyShader(): GLShader;
|
|
40
|
+
/**
|
|
41
|
+
* Get the main MRT draw shader used for standard geometry rendering
|
|
42
|
+
* This shader outputs to all 5 MRT attachments for textmode rendering
|
|
43
|
+
*/
|
|
44
|
+
$getMainDrawShader(): GLShader;
|
|
45
|
+
/**
|
|
46
|
+
* Get the ASCII conversion shader used for final display output
|
|
47
|
+
* This shader converts MRT data to final ASCII characters
|
|
48
|
+
*/
|
|
49
|
+
$getConversionShader(): GLShader;
|
|
50
|
+
/**
|
|
51
|
+
* Create a custom filter shader using the standard instanced vertex shader
|
|
52
|
+
* These shaders are not cached as they are user-specific
|
|
53
|
+
*/
|
|
54
|
+
$createFilterShader(fragmentSource: string): GLShader;
|
|
55
|
+
/**
|
|
56
|
+
* Create a custom shader with arbitrary vertex and fragment sources
|
|
57
|
+
* These shaders are not cached as they are user-specific
|
|
58
|
+
*/
|
|
59
|
+
$createCustomShader(vertexSource: ShaderSource, fragmentSource: ShaderSource): GLShader;
|
|
60
|
+
/**
|
|
61
|
+
* Dispose of all managed shaders and clear the registry
|
|
62
|
+
* This method is idempotent and safe to call multiple times
|
|
63
|
+
*/
|
|
64
|
+
$dispose(): void;
|
|
65
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './Framebuffer';
|
|
2
2
|
export * from './Renderer';
|
|
3
3
|
export * from './Shader';
|
|
4
|
+
export * from './ShaderManager';
|
|
4
5
|
export * from './StateCache';
|
|
5
6
|
export { GeometryType } from './types/GeometryTypes';
|
|
6
7
|
export type { IGeometry as IInstancedGeometry, UnitGeometryData, RectangleParams, LineParams, EllipseParams, ArcParams, TriangleParams, BezierCurveParams, GeometryParams } from './types/GeometryTypes';
|
|
@@ -19,20 +19,20 @@ export declare enum GeometryType {
|
|
|
19
19
|
*/
|
|
20
20
|
export interface UnitGeometryData {
|
|
21
21
|
/** Vertex data as Float32Array (position + texCoord interleaved) */
|
|
22
|
-
|
|
22
|
+
_vertices: Float32Array;
|
|
23
23
|
/** Number of vertices in the geometry */
|
|
24
|
-
|
|
24
|
+
_vertexCount: number;
|
|
25
25
|
/** WebGL primitive type (gl.TRIANGLES, gl.LINES, etc.) */
|
|
26
|
-
|
|
26
|
+
_primitiveType: number;
|
|
27
27
|
/** Stride in bytes between vertices */
|
|
28
|
-
|
|
28
|
+
_stride: number;
|
|
29
29
|
/** Attribute configuration for position and texCoord */
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
_attributes: {
|
|
31
|
+
_position: {
|
|
32
32
|
size: number;
|
|
33
33
|
offset: number;
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
_texCoord: {
|
|
36
36
|
size: number;
|
|
37
37
|
offset: number;
|
|
38
38
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for shader data with minification support
|
|
3
|
+
*/
|
|
4
|
+
export interface ShaderData {
|
|
5
|
+
/** The shader source code (minified in production, original in development) */
|
|
6
|
+
sourceCode: string;
|
|
7
|
+
/** Original unminified source code (available in development builds) */
|
|
8
|
+
originalCode?: string;
|
|
9
|
+
/** Mapping of original uniform names to minified names and types */
|
|
10
|
+
uniforms: Record<string, {
|
|
11
|
+
/** Minified uniform name used in the shader */
|
|
12
|
+
variableName: string;
|
|
13
|
+
/** GLSL type of the uniform (vec2, sampler2D, etc.) */
|
|
14
|
+
variableType: string;
|
|
15
|
+
}>;
|
|
16
|
+
/** Mapping of const variables (if any) */
|
|
17
|
+
consts: Record<string, {
|
|
18
|
+
/** Substitution value for the const */
|
|
19
|
+
variableName: string;
|
|
20
|
+
/** GLSL type of the const */
|
|
21
|
+
variableType: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Union type for shader imports - either ShaderData or plain string (for backward compatibility)
|
|
26
|
+
*/
|
|
27
|
+
export type ShaderSource = ShaderData | string;
|
|
28
|
+
/**
|
|
29
|
+
* Helper to normalize shader source to ShaderData format
|
|
30
|
+
*/
|
|
31
|
+
export declare function normalizeShaderData(source: ShaderSource): ShaderData;
|
|
32
|
+
/**
|
|
33
|
+
* Extract just the source code from ShaderSource
|
|
34
|
+
*/
|
|
35
|
+
export declare function getShaderCode(source: ShaderSource): string;
|
|
@@ -3,8 +3,8 @@ import { TextmodeFont } from './font';
|
|
|
3
3
|
import { TextmodeGrid } from './Grid';
|
|
4
4
|
import { TextmodeCanvas } from './Canvas';
|
|
5
5
|
import { AnimationController } from './AnimationController';
|
|
6
|
-
import { MouseManager } from './
|
|
7
|
-
import { KeyboardManager } from './
|
|
6
|
+
import { MouseManager } from './managers';
|
|
7
|
+
import { KeyboardManager } from './managers';
|
|
8
8
|
import { type TextmodifierContext } from './mixins';
|
|
9
9
|
import type { RenderingCapabilities } from './mixins/RenderingMixin';
|
|
10
10
|
import type { ExportCapabilities } from './mixins/ExportMixin';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { KeyboardManager } from '../managers/KeyboardManager';
|
|
2
|
+
export type { KeyboardEventData, KeyboardEventHandler, KeyState } from '../managers/KeyboardManager';
|
|
3
|
+
export { MouseManager } from '../managers/MouseManager';
|
|
4
|
+
export type { MousePosition, MouseEventData, MouseEventHandler } from '../managers/MouseManager';
|
|
@@ -3,10 +3,6 @@ import type { Mixin } from './TextmodifierMixin';
|
|
|
3
3
|
* Interface for animation capabilities that will be mixed into Textmodifier
|
|
4
4
|
*/
|
|
5
5
|
export interface AnimationCapabilities {
|
|
6
|
-
/**
|
|
7
|
-
* Get or set the current frame count.
|
|
8
|
-
*/
|
|
9
|
-
frameCount: number;
|
|
10
6
|
/**
|
|
11
7
|
* Set the maximum frame rate. If called without arguments, returns the current measured frame rate.
|
|
12
8
|
* @param fps The maximum frames per second for rendering.
|
|
@@ -1,30 +1,86 @@
|
|
|
1
1
|
import type { Mixin } from './TextmodifierMixin';
|
|
2
|
-
import type { KeyboardEventHandler } from '../
|
|
2
|
+
import type { KeyboardEventHandler } from '../managers';
|
|
3
3
|
/**
|
|
4
4
|
* Capabilities provided by the KeyboardMixin
|
|
5
5
|
*/
|
|
6
6
|
export interface KeyboardCapabilities {
|
|
7
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* Check if a specific key is currently being pressed.
|
|
9
|
+
*
|
|
10
|
+
* @param key The key to check (e.g., 'a', 'Enter', 'ArrowLeft')
|
|
11
|
+
* @returns true if the key is currently pressed, false otherwise
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```javascript
|
|
15
|
+
* const t = textmode.create({ width: 800, height: 600 });
|
|
16
|
+
*
|
|
17
|
+
* let playerX = 0;
|
|
18
|
+
* let playerY = 0;
|
|
19
|
+
*
|
|
20
|
+
* t.draw(() => {
|
|
21
|
+
* t.background(0);
|
|
22
|
+
*
|
|
23
|
+
* // Check for arrow keys to move a character
|
|
24
|
+
* if (t.isKeyPressed('ArrowUp')) {
|
|
25
|
+
* playerY -= 1;
|
|
26
|
+
* }
|
|
27
|
+
* if (t.isKeyPressed('ArrowDown')) {
|
|
28
|
+
* playerY += 1;
|
|
29
|
+
* }
|
|
30
|
+
* if (t.isKeyPressed('ArrowLeft')) {
|
|
31
|
+
* playerX -= 1;
|
|
32
|
+
* }
|
|
33
|
+
* if (t.isKeyPressed('ArrowRight')) {
|
|
34
|
+
* playerX += 1;
|
|
35
|
+
* }
|
|
36
|
+
*
|
|
37
|
+
* // Draw player character
|
|
38
|
+
* t.char('@');
|
|
39
|
+
* t.charColor(255, 255, 0);
|
|
40
|
+
* t.point(playerX, playerY);
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
8
44
|
isKeyPressed(key: string): boolean;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Set a callback function that will be called when a key is pressed down.
|
|
47
|
+
*
|
|
48
|
+
* @param callback The function to call when a key is pressed
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```javascript
|
|
52
|
+
* const t = textmode.create({ width: 800, height: 600 });
|
|
53
|
+
*
|
|
54
|
+
* t.keyPressed((data) => {
|
|
55
|
+
* console.log(`Key pressed: ${data.key}`);
|
|
56
|
+
* if (data.key === 'Enter') {
|
|
57
|
+
* console.log('Enter key was pressed!');
|
|
58
|
+
* }
|
|
59
|
+
* if (data.ctrlKey && data.key === 's') {
|
|
60
|
+
* console.log('Ctrl+S was pressed!');
|
|
61
|
+
* }
|
|
62
|
+
* });
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
23
65
|
keyPressed(callback: KeyboardEventHandler): void;
|
|
24
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Set a callback function that will be called when a key is released.
|
|
68
|
+
*
|
|
69
|
+
* @param callback The function to call when a key is released
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```javascript
|
|
73
|
+
* const t = textmode.create({ width: 800, height: 600 });
|
|
74
|
+
*
|
|
75
|
+
* t.keyReleased((data) => {
|
|
76
|
+
* console.log(`Key released: ${data.key}`);
|
|
77
|
+
* if (data.key === ' ') {
|
|
78
|
+
* console.log('Spacebar was released!');
|
|
79
|
+
* }
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
25
83
|
keyReleased(callback: KeyboardEventHandler): void;
|
|
26
|
-
/** Clear all key states */
|
|
27
|
-
clearKeyStates(): void;
|
|
28
84
|
}
|
|
29
85
|
/**
|
|
30
86
|
* Mixin that adds keyboard interaction capabilities to Textmodifier.
|