textmode.js 0.8.0-beta.2 → 0.8.0
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 +1134 -1128
- package/dist/textmode.umd.js +15 -15
- package/dist/types/textmode/Textmodifier.d.ts +8 -0
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +53 -5
- package/dist/types/textmode/layers/LayerManager.d.ts +2 -1
- package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +1 -1
- package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +1 -1
- package/dist/types/textmode/layers/types.d.ts +2 -2
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +2 -4
- package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +2 -4
- package/dist/types/textmode/loading/LoadingPhase.d.ts +2 -2
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +15 -13
- package/package.json +1 -1
|
@@ -62,6 +62,7 @@ export declare class Textmodifier extends Textmodifier_base implements ITextmodi
|
|
|
62
62
|
private _resizeObserver?;
|
|
63
63
|
private _isOverlay;
|
|
64
64
|
private _targetCanvasImage?;
|
|
65
|
+
private _inputGridOverride?;
|
|
65
66
|
/**
|
|
66
67
|
* Create a new Textmodifier instance.
|
|
67
68
|
* @param opts Configuration options for the Textmodifier instance.
|
|
@@ -82,6 +83,13 @@ export declare class Textmodifier extends Textmodifier_base implements ITextmodi
|
|
|
82
83
|
filter(name: FilterName, params?: unknown): void;
|
|
83
84
|
loadFont(fontSource: string): Promise<TextmodeFont>;
|
|
84
85
|
fontSize(size: number): void;
|
|
86
|
+
inputGrid(target?: 'topmost' | TextmodeGrid): 'topmost' | TextmodeGrid | void;
|
|
87
|
+
/**
|
|
88
|
+
* Get the grid used for input coordinate mapping.
|
|
89
|
+
* Returns the override grid/layer's grid if set, otherwise the topmost visible layer's grid.
|
|
90
|
+
* @ignore
|
|
91
|
+
*/
|
|
92
|
+
private _getInputGrid;
|
|
85
93
|
setup(callback: () => void | Promise<void>): Promise<void>;
|
|
86
94
|
draw(callback: () => void): void;
|
|
87
95
|
windowResized(callback: () => void): void;
|
|
@@ -71,6 +71,7 @@ export interface ITextmodifier extends IRenderingMixin, IAnimationMixin, IMouseM
|
|
|
71
71
|
* t.setup(async () => {
|
|
72
72
|
* // Load font for the base layer
|
|
73
73
|
* const font = await t.loadFont('./fonts/myfont.ttf');
|
|
74
|
+
* // const font = await t.layers.base.loadFont('./fonts/myfont.ttf'); // Equivalent
|
|
74
75
|
*
|
|
75
76
|
* // Use the same font on another layer
|
|
76
77
|
* const layer = t.layers.add();
|
|
@@ -104,6 +105,43 @@ export interface ITextmodifier extends IRenderingMixin, IAnimationMixin, IMouseM
|
|
|
104
105
|
* ```
|
|
105
106
|
*/
|
|
106
107
|
fontSize(size: number): void;
|
|
108
|
+
/**
|
|
109
|
+
* Get or set the grid used for mouse and touch input coordinate mapping.
|
|
110
|
+
*
|
|
111
|
+
* By default, input coordinates are mapped to the topmost visible layer's grid,
|
|
112
|
+
* which changes dynamically as layers are shown/hidden. Use this method to lock
|
|
113
|
+
* input mapping to a specific grid or layer, or to return to responsive mode.
|
|
114
|
+
*
|
|
115
|
+
* When called without arguments, returns the current input grid mode:<br/>
|
|
116
|
+
* - `'topmost'` if using responsive mode (default)<br/>
|
|
117
|
+
* - The specific `TextmodeGrid` if locked
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```javascript
|
|
121
|
+
* const t = textmode.create();
|
|
122
|
+
*
|
|
123
|
+
* // Add a UI layer on top
|
|
124
|
+
* const uiLayer = t.layers.add({ fontSize: 16 });
|
|
125
|
+
*
|
|
126
|
+
* t.setup(() => {
|
|
127
|
+
* // Lock input to the base layer's grid for game controls
|
|
128
|
+
* // even though the UI layer is rendered on top
|
|
129
|
+
* t.inputGrid(t.layers.base.grid);
|
|
130
|
+
* });
|
|
131
|
+
*
|
|
132
|
+
* t.draw(() => {
|
|
133
|
+
* // Mouse positions now always use base layer's grid
|
|
134
|
+
* t.text(`Mouse: ${t.mouseX}, ${t.mouseY}`, 0, 0);
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* // Switch back to responsive mode
|
|
138
|
+
* // t.inputGrid('topmost');
|
|
139
|
+
*
|
|
140
|
+
* // Or check current mode
|
|
141
|
+
* // const current = t.inputGrid(); // 'topmost' or the locked grid
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
inputGrid(target?: 'topmost' | TextmodeGrid): 'topmost' | TextmodeGrid | void;
|
|
107
145
|
/**
|
|
108
146
|
* Set a setup callback function that will be executed once when initialization is complete.
|
|
109
147
|
*
|
|
@@ -146,9 +184,15 @@ export interface ITextmodifier extends IRenderingMixin, IAnimationMixin, IMouseM
|
|
|
146
184
|
*
|
|
147
185
|
* This callback function is where all drawing commands should be placed for textmode rendering on the main layer.
|
|
148
186
|
*
|
|
149
|
-
* If multiple layers are added via {@link Textmodifier.layers}, each layer
|
|
187
|
+
* If multiple layers are added via {@link Textmodifier.layers}, each layer has its own draw callback set via {@link TextmodeLayer.draw}.
|
|
150
188
|
* This allows for complex multi-layered compositions with independent rendering logic per layer.
|
|
151
189
|
*
|
|
190
|
+
* Calling this method is equivalent to setting the draw callback on the base layer,
|
|
191
|
+
* while the direct layer callback has precedence if both are set.
|
|
192
|
+
* ```javascript
|
|
193
|
+
* textmodifier.layers.base.draw(callback);
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
152
196
|
* @param callback The function to call before each render
|
|
153
197
|
*
|
|
154
198
|
* @example
|
|
@@ -282,7 +326,12 @@ export interface ITextmodifier extends IRenderingMixin, IAnimationMixin, IMouseM
|
|
|
282
326
|
filter<T extends BuiltInFilterName>(name: T, params?: BuiltInFilterParams[T]): void;
|
|
283
327
|
filter(name: FilterName, params?: unknown): void;
|
|
284
328
|
filter(name: FilterName, params?: unknown): void;
|
|
285
|
-
/**
|
|
329
|
+
/**
|
|
330
|
+
* Get the grid whose layer is currently being drawn to.
|
|
331
|
+
* If called outside of a layers draw callback, returns the base layer's grid.
|
|
332
|
+
*
|
|
333
|
+
* If no grid is set (e.g., before user setup()), returns `undefined`.
|
|
334
|
+
*/
|
|
286
335
|
readonly grid: TextmodeGrid | undefined;
|
|
287
336
|
/** Get the current font object used for rendering the base layer. */
|
|
288
337
|
readonly font: TextmodeFont;
|
|
@@ -299,7 +348,6 @@ export interface ITextmodifier extends IRenderingMixin, IAnimationMixin, IMouseM
|
|
|
299
348
|
*
|
|
300
349
|
* Use this to register custom filters that can be applied both globally
|
|
301
350
|
* (via {@link filter}) and on individual layers (via {@link TextmodeLayer.filter}).
|
|
302
|
-
* Filters only need to be registered once and are available everywhere.
|
|
303
351
|
*
|
|
304
352
|
* @example
|
|
305
353
|
* ```typescript
|
|
@@ -326,7 +374,7 @@ export interface ITextmodifier extends IRenderingMixin, IAnimationMixin, IMouseM
|
|
|
326
374
|
* Access the layer manager for this Textmodifier instance.
|
|
327
375
|
*
|
|
328
376
|
* Use this to create and manage multiple layers within the textmode rendering context.
|
|
329
|
-
* Each layer
|
|
377
|
+
* Each layer has its own grid, font, draw callback, and filters.
|
|
330
378
|
*/
|
|
331
379
|
readonly layers: TextmodeLayerManager;
|
|
332
380
|
/**
|
|
@@ -379,7 +427,7 @@ export interface ITextmodifier extends IRenderingMixin, IAnimationMixin, IMouseM
|
|
|
379
427
|
* await phase1.track(async () => {
|
|
380
428
|
* for (let i = 0; i <= 5; i++) {
|
|
381
429
|
* phase1.report(i / 5);
|
|
382
|
-
* // Small delay
|
|
430
|
+
* // Small delay - increases visibility of the loading animation
|
|
383
431
|
* await new Promise((r) => setTimeout(r, 200));
|
|
384
432
|
* }
|
|
385
433
|
* });
|
|
@@ -73,8 +73,9 @@ export declare class LayerManager implements ILayerManager {
|
|
|
73
73
|
* Get the grid of the topmost visible layer.
|
|
74
74
|
* Returns the topmost user layer's grid if any are visible, otherwise returns the base layer's grid.
|
|
75
75
|
* This is useful for input managers that need to map coordinates to the layer the user sees on top.
|
|
76
|
+
* @ignore
|
|
76
77
|
*/
|
|
77
|
-
getTopmostGrid(): TextmodeGrid | undefined;
|
|
78
|
+
$getTopmostGrid(): TextmodeGrid | undefined;
|
|
78
79
|
/**
|
|
79
80
|
* Register a callback to be invoked whenever ANY layer's grid dimensions change.
|
|
80
81
|
* This includes the base layer and all user layers.
|
|
@@ -46,5 +46,5 @@ export interface ILayerManager {
|
|
|
46
46
|
* Returns the topmost user layer's grid if any are visible, otherwise returns the base layer's grid.
|
|
47
47
|
* This is useful for input managers that need to map coordinates to the layer the user sees on top.
|
|
48
48
|
*/
|
|
49
|
-
getTopmostGrid(): TextmodeGrid | undefined;
|
|
49
|
+
$getTopmostGrid(): TextmodeGrid | undefined;
|
|
50
50
|
}
|
|
@@ -334,7 +334,7 @@ export interface ITextmodeLayer {
|
|
|
334
334
|
* Filters are applied after ASCII conversion in the order they are called.
|
|
335
335
|
* Call this method within your layer's draw callback to apply effects.
|
|
336
336
|
*
|
|
337
|
-
* **Built-in
|
|
337
|
+
* **Built-in filters:**
|
|
338
338
|
* - `'invert'` - Inverts all colors
|
|
339
339
|
* - `'grayscale'` - Converts to grayscale (param: amount 0-1, default 1)
|
|
340
340
|
* - `'sepia'` - Applies sepia tone (param: amount 0-1, default 1)
|
|
@@ -47,9 +47,9 @@ export interface TextmodeLayerOptions {
|
|
|
47
47
|
*/
|
|
48
48
|
offsetY?: number;
|
|
49
49
|
/**
|
|
50
|
-
* The rotation of the layer in degrees around its center. Default is `0`.
|
|
50
|
+
* The z-rotation of the layer in degrees around its center. Default is `0`.
|
|
51
51
|
*/
|
|
52
|
-
|
|
52
|
+
rotationZ?: number;
|
|
53
53
|
/**
|
|
54
54
|
* The font size for the layer's text. Default is `16`.
|
|
55
55
|
*/
|
|
@@ -29,10 +29,8 @@ import type { TextmodeConversionManager } from '../conversion';
|
|
|
29
29
|
* t.draw(() => {
|
|
30
30
|
* t.background(0);
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* t.image(img);
|
|
35
|
-
* }
|
|
32
|
+
* // Draw the loaded image
|
|
33
|
+
* t.image(img);
|
|
36
34
|
* });
|
|
37
35
|
* ```
|
|
38
36
|
*/
|
|
@@ -33,10 +33,8 @@ import type { TextmodeConversionManager } from '../../conversion';
|
|
|
33
33
|
* t.draw(() => {
|
|
34
34
|
* t.background(0);
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* t.image(video);
|
|
39
|
-
* }
|
|
36
|
+
* // Draw the loaded video
|
|
37
|
+
* t.image(video);
|
|
40
38
|
* });
|
|
41
39
|
* ```
|
|
42
40
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { LoadingPhaseTracker } from
|
|
2
|
-
import type { ILoadingPhase } from
|
|
1
|
+
import type { LoadingPhaseTracker } from './LoadingPhaseTracker';
|
|
2
|
+
import type { ILoadingPhase } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Represents a loading phase tracked by a LoadingPhaseTracker.
|
|
5
5
|
*
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { GLFramebuffer, GLShader, TextmodeFramebufferOptions, UniformValue } from '../../../rendering/webgl';
|
|
2
|
-
import type { TextmodeSource } from '../../loadables/TextmodeSource';
|
|
3
2
|
import type { TextmodeImage } from '../../loadables/TextmodeImage';
|
|
4
3
|
import type { TextmodeColor } from '../../TextmodeColor';
|
|
5
4
|
import type { TextmodeVideo } from '../../loadables';
|
|
@@ -84,7 +83,7 @@ export interface IRenderingMixin {
|
|
|
84
83
|
*/
|
|
85
84
|
createFramebuffer(options: TextmodeFramebufferOptions): GLFramebuffer;
|
|
86
85
|
/**
|
|
87
|
-
* Draw a TextmodeFramebuffer or
|
|
86
|
+
* Draw a TextmodeFramebuffer, TextmodeImage, or TextmodeVideo to the current render target.
|
|
88
87
|
*
|
|
89
88
|
* @param source The TextmodeFramebuffer or TextmodeSource to render
|
|
90
89
|
* @param x X position on the grid where to place the content *(top-left corner)*
|
|
@@ -121,7 +120,7 @@ export interface IRenderingMixin {
|
|
|
121
120
|
* });
|
|
122
121
|
* ```
|
|
123
122
|
*/
|
|
124
|
-
image(source: GLFramebuffer |
|
|
123
|
+
image(source: GLFramebuffer | TextmodeImage | TextmodeVideo, width?: number, height?: number): void;
|
|
125
124
|
/**
|
|
126
125
|
* Load an image and return a TextmodeImage that can be drawn with image().
|
|
127
126
|
*
|
|
@@ -148,10 +147,8 @@ export interface IRenderingMixin {
|
|
|
148
147
|
* t.draw(() => {
|
|
149
148
|
* t.background(0);
|
|
150
149
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* t.image(img);
|
|
154
|
-
* }
|
|
150
|
+
* // Draw the loaded image
|
|
151
|
+
* t.image(img);
|
|
155
152
|
* });
|
|
156
153
|
* ```
|
|
157
154
|
*/
|
|
@@ -182,10 +179,8 @@ export interface IRenderingMixin {
|
|
|
182
179
|
* t.draw(() => {
|
|
183
180
|
* t.background(0);
|
|
184
181
|
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* t.image(video);
|
|
188
|
-
* }
|
|
182
|
+
* // Draw the loaded video
|
|
183
|
+
* t.image(video);
|
|
189
184
|
* });
|
|
190
185
|
* ```
|
|
191
186
|
*/
|
|
@@ -706,7 +701,10 @@ export interface IRenderingMixin {
|
|
|
706
701
|
*/
|
|
707
702
|
line(x1: number, y1: number, x2: number, y2: number): void;
|
|
708
703
|
/**
|
|
709
|
-
* Set the background color
|
|
704
|
+
* Set the background color of the layer currently drawing to.
|
|
705
|
+
*
|
|
706
|
+
* Used to clear the layer to a specific color at the start of its drawing cycle.
|
|
707
|
+
*
|
|
710
708
|
* @param value A {@link TextmodeColor}, hex string, grayscale value, or single RGB channel
|
|
711
709
|
* @param g Optional green component when providing RGB channels or alpha when used with grayscale
|
|
712
710
|
* @param b Optional blue component when providing RGB channels
|
|
@@ -739,7 +737,9 @@ export interface IRenderingMixin {
|
|
|
739
737
|
*/
|
|
740
738
|
background(value: number | string | TextmodeColor, g?: number, b?: number, a?: number): void;
|
|
741
739
|
/**
|
|
742
|
-
* Clear the
|
|
740
|
+
* Clear the layer currently drawing to.
|
|
741
|
+
*
|
|
742
|
+
* Used to clear the layer at the start of its drawing cycle.
|
|
743
743
|
*
|
|
744
744
|
* @example
|
|
745
745
|
* ```javascript
|
|
@@ -839,6 +839,8 @@ export interface IRenderingMixin {
|
|
|
839
839
|
* Set the character to be used for subsequent rendering operations.
|
|
840
840
|
* Accepts a single character string.
|
|
841
841
|
*
|
|
842
|
+
* @param character The character to set for rendering
|
|
843
|
+
*
|
|
842
844
|
* @example
|
|
843
845
|
* ```javascript
|
|
844
846
|
* const t = textmode.create({
|
package/package.json
CHANGED