textmode.js 0.4.0 → 0.6.0-beta.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 +2868 -2164
- package/dist/textmode.esm.min.js +2863 -2159
- package/dist/textmode.umd.js +11 -8
- package/dist/textmode.umd.min.js +11 -8
- package/dist/types/Textmode.d.ts +13 -22
- package/dist/types/index.d.ts +8 -6
- package/dist/types/rendering/index.d.ts +3 -3
- package/dist/types/rendering/webgl/batching/DrawQueue.d.ts +89 -0
- package/dist/types/rendering/webgl/{VAOManager.d.ts → batching/GeometryAttributeCache.d.ts} +4 -4
- package/dist/types/rendering/webgl/batching/InstanceAttributeBinder.d.ts +87 -0
- package/dist/types/rendering/webgl/{InstanceBatch.d.ts → batching/InstanceBatch.d.ts} +25 -34
- package/dist/types/rendering/webgl/batching/InstanceBuffer.d.ts +78 -0
- package/dist/types/rendering/webgl/{InstanceData.d.ts → batching/InstanceData.d.ts} +11 -18
- package/dist/types/rendering/webgl/batching/InstanceWriter.d.ts +70 -0
- package/dist/types/rendering/webgl/{Framebuffer.d.ts → core/Framebuffer.d.ts} +37 -39
- package/dist/types/rendering/webgl/core/Renderer.d.ts +64 -0
- package/dist/types/rendering/webgl/{Shader.d.ts → core/Shader.d.ts} +2 -23
- package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +103 -0
- package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +210 -0
- package/dist/types/rendering/webgl/geometries/{Arc.d.ts → 2d/Arc.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/{BezierCurve.d.ts → 2d/BezierCurve.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/{Ellipse.d.ts → 2d/Ellipse.d.ts} +6 -5
- package/dist/types/rendering/webgl/geometries/{Line.d.ts → 2d/Line.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/{Rectangle.d.ts → 2d/Rectangle.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/{Triangle.d.ts → 2d/Triangle.d.ts} +5 -4
- package/dist/types/rendering/webgl/geometries/BaseGeometry.d.ts +30 -26
- package/dist/types/rendering/webgl/geometries/immediate/ImmediateQuad.d.ts +33 -0
- package/dist/types/rendering/webgl/geometries/index.d.ts +6 -6
- 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 +15 -14
- package/dist/types/rendering/webgl/materials/Material.d.ts +26 -0
- package/dist/types/rendering/webgl/materials/MaterialManager.d.ts +63 -0
- package/dist/types/rendering/webgl/materials/index.d.ts +2 -0
- package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +63 -0
- package/dist/types/rendering/webgl/pipeline/index.d.ts +7 -0
- package/dist/types/rendering/webgl/state/RenderState.d.ts +143 -0
- package/dist/types/rendering/webgl/types/DrawCommand.d.ts +5 -3
- package/dist/types/rendering/webgl/types/GeometryTypes.d.ts +10 -10
- package/dist/types/rendering/webgl/types/RenderTypes.d.ts +1 -1
- package/dist/types/rendering/webgl/utils/GLUtils.d.ts +45 -0
- package/dist/types/rendering/webgl/utils/hash.d.ts +118 -0
- package/dist/types/textmode/AnimationController.d.ts +11 -21
- package/dist/types/textmode/Canvas.d.ts +10 -2
- package/dist/types/textmode/Grid.d.ts +2 -0
- package/dist/types/textmode/TextmodeColor.d.ts +57 -0
- package/dist/types/textmode/Textmodifier.d.ts +40 -212
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +272 -0
- package/dist/types/textmode/interfaces/index.d.ts +1 -0
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +21 -0
- package/dist/types/textmode/loadables/TextmodeSource.d.ts +130 -0
- package/dist/types/textmode/loadables/TextmodeVideo.d.ts +237 -0
- package/dist/types/textmode/{font → loadables/font}/CharacterColorMapper.d.ts +1 -1
- package/dist/types/textmode/{font → loadables/font}/CharacterExtractor.d.ts +0 -10
- package/dist/types/textmode/{font → loadables/font}/TextmodeFont.d.ts +6 -3
- package/dist/types/textmode/{font → loadables/font}/TextureAtlas.d.ts +4 -11
- package/dist/types/textmode/{font → loadables/font}/typr/types.d.ts +0 -6
- package/dist/types/textmode/loadables/index.d.ts +5 -0
- package/dist/types/textmode/loading/LoadingPhaseTracker.d.ts +20 -0
- package/dist/types/textmode/loading/LoadingScreenManager.d.ts +170 -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 +6 -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 +251 -0
- package/dist/types/textmode/managers/KeyboardManager.d.ts +2 -3
- package/dist/types/textmode/managers/MouseManager.d.ts +1 -1
- package/dist/types/textmode/{plugins → managers}/PluginManager.d.ts +12 -15
- package/dist/types/textmode/managers/TouchManager.d.ts +0 -2
- package/dist/types/textmode/mixins/AnimationMixin.d.ts +2 -122
- package/dist/types/textmode/mixins/FontMixin.d.ts +2 -77
- package/dist/types/textmode/mixins/KeyboardMixin.d.ts +3 -85
- package/dist/types/textmode/mixins/MouseMixin.d.ts +3 -130
- package/dist/types/textmode/mixins/RenderingMixin.d.ts +2 -749
- package/dist/types/textmode/mixins/TextmodifierMixin.d.ts +2 -44
- package/dist/types/textmode/mixins/TouchMixin.d.ts +2 -187
- package/dist/types/textmode/mixins/index.d.ts +8 -8
- package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +167 -0
- package/dist/types/textmode/mixins/interfaces/IFontMixin.d.ts +46 -0
- package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +235 -0
- package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +457 -0
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +1085 -0
- package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +186 -0
- package/dist/types/textmode/types.d.ts +49 -0
- package/dist/types/textmode/utils/cssColor.d.ts +8 -0
- package/dist/types/utils/array.d.ts +34 -0
- package/dist/types/utils/math.d.ts +69 -0
- package/package.json +1 -1
- package/dist/types/rendering/webgl/DrawQueue.d.ts +0 -30
- package/dist/types/rendering/webgl/RenderPipeline.d.ts +0 -30
- package/dist/types/rendering/webgl/RenderState.d.ts +0 -73
- package/dist/types/rendering/webgl/Renderer.d.ts +0 -158
- package/dist/types/rendering/webgl/ShaderManager.d.ts +0 -66
- package/dist/types/rendering/webgl/geometries/NoiseGrid.d.ts +0 -1
- package/dist/types/textmode/TextmodeImage.d.ts +0 -161
- package/dist/types/textmode/mixins/ShaderMixin.d.ts +0 -1
- /package/dist/types/rendering/webgl/{StateCache.d.ts → utils/ViewportCache.d.ts} +0 -0
- /package/dist/types/textmode/{font → loadables/font}/MetricsCalculator.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/index.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/types.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/typr/Typr.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/utils/FontTableReader.d.ts +0 -0
- /package/dist/types/textmode/{font → loadables/font}/utils/index.d.ts +0 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { Textmodifier } from '../Textmodifier';
|
|
2
|
+
import type { RGBA } from '../utils/cssColor';
|
|
3
|
+
import type { LoadingPhaseHandle, LoadingScreenOptions } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Manages the loading screen display and state. Can be accessed via {@link Textmodifier.loading}.
|
|
6
|
+
*/
|
|
7
|
+
export declare class LoadingScreenManager {
|
|
8
|
+
private readonly _textmodifier;
|
|
9
|
+
private readonly _options;
|
|
10
|
+
private readonly _stateMachine;
|
|
11
|
+
private readonly _phaseTracker;
|
|
12
|
+
private readonly _transition;
|
|
13
|
+
private _renderer;
|
|
14
|
+
private _palette;
|
|
15
|
+
private _theme;
|
|
16
|
+
private _startTime;
|
|
17
|
+
/**
|
|
18
|
+
* Initializes a new LoadingScreenManager.
|
|
19
|
+
* @param textmodifier Textmodifier instance to render on.
|
|
20
|
+
* @param opts Loading screen options.
|
|
21
|
+
* @param canvasBackground Background color of the canvas.
|
|
22
|
+
* @ignore
|
|
23
|
+
*/
|
|
24
|
+
constructor(textmodifier: Textmodifier, opts: LoadingScreenOptions | undefined, canvasBackground: RGBA | null);
|
|
25
|
+
/**
|
|
26
|
+
* Indicates whether the loading screen should render this frame.
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
get shouldRender(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Get the current overall loading progress (0-1).
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* const t = textmode.create({
|
|
36
|
+
* width: 800,
|
|
37
|
+
* height: 600,
|
|
38
|
+
* loadingScreen: { message: 'starting...' }
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // In setup we can start a phase and read the overall progress
|
|
42
|
+
* t.setup(async () => {
|
|
43
|
+
* const phase = t.loading.beginPhase('assets', 1);
|
|
44
|
+
* phase.report(0.5); // half complete for the phase
|
|
45
|
+
*
|
|
46
|
+
* // The `progress` accessor reports the global progress across all phases
|
|
47
|
+
* console.log(`Loading: ${Math.round(t.loading.progress * 100)}%`);
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
get progress(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Get or set the loading screen message.
|
|
54
|
+
* @param next Optional new message to set.
|
|
55
|
+
* @returns The current loading screen message.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const t = textmode.create({
|
|
60
|
+
* width: 800,
|
|
61
|
+
* height: 600,
|
|
62
|
+
* loadingScreen: { message: 'loading...' }
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* t.setup(() => {
|
|
66
|
+
* // Update the message visible on the loading screen
|
|
67
|
+
* t.loading.message('preloading video...');
|
|
68
|
+
*
|
|
69
|
+
* // Read the current message (useful in custom renderers)
|
|
70
|
+
* const msg = t.loading.message();
|
|
71
|
+
* console.log(msg);
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
message(next?: string): string | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Begin a new loading phase.
|
|
78
|
+
*
|
|
79
|
+
* With the returned {@link LoadingPhaseHandle} you can report progress,
|
|
80
|
+
* track asynchronous work, and manage the phase lifecycle.
|
|
81
|
+
*
|
|
82
|
+
* @param label Label for the loading phase.
|
|
83
|
+
* @param weight Weight of the loading phase (default is 1).
|
|
84
|
+
* @returns A handle to the created loading phase.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const t = textmode.create({
|
|
89
|
+
* width: 800,
|
|
90
|
+
* height: 600,
|
|
91
|
+
* loadingScreen: { message: 'preparing...' }
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* // In setup we start a phase and then track work in that phase
|
|
95
|
+
* t.setup(async () => {
|
|
96
|
+
* const phase = t.loading.beginPhase('video preload', 2);
|
|
97
|
+
*
|
|
98
|
+
* // Example: report progress from a loader callback
|
|
99
|
+
* await phase.track(async () => {
|
|
100
|
+
* // Simulated work
|
|
101
|
+
* for (let i = 0; i <= 10; i++) {
|
|
102
|
+
* phase.report(i / 10);
|
|
103
|
+
* await new Promise((r) => setTimeout(r, 30));
|
|
104
|
+
* }
|
|
105
|
+
* });
|
|
106
|
+
* });
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
addPhase(label: string, weight?: number): LoadingPhaseHandle;
|
|
110
|
+
/**
|
|
111
|
+
* Finish the loading process.
|
|
112
|
+
* @ignore
|
|
113
|
+
*/
|
|
114
|
+
finish(): void;
|
|
115
|
+
private _notifyComplete;
|
|
116
|
+
private _onCompleteCallback?;
|
|
117
|
+
/**
|
|
118
|
+
* Set a callback to be invoked when loading is complete.
|
|
119
|
+
* @param callback The callback function to invoke.
|
|
120
|
+
* @ignore
|
|
121
|
+
*/
|
|
122
|
+
setOnComplete(callback: () => void): void;
|
|
123
|
+
/**
|
|
124
|
+
* Report an error that occurred during loading.
|
|
125
|
+
* @param error The error message or `Error` object.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* const t = textmode.create({
|
|
130
|
+
* width: 800,
|
|
131
|
+
* height: 600,
|
|
132
|
+
* loadingScreen: { message: 'starting...' }
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* t.setup(async () => {
|
|
136
|
+
* const phase = t.loading.beginPhase('remote fetch', 1);
|
|
137
|
+
* try {
|
|
138
|
+
* await phase.track(async () => {
|
|
139
|
+
* // Failing call
|
|
140
|
+
* throw new Error('server down');
|
|
141
|
+
* });
|
|
142
|
+
* } catch (err) {
|
|
143
|
+
* // This will put the loading manager into an error state
|
|
144
|
+
* t.loading.error(err instanceof Error ? err : String(err));
|
|
145
|
+
* }
|
|
146
|
+
* });
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
error(error: Error | string): void;
|
|
150
|
+
/**
|
|
151
|
+
* Render a frame of the loading screen.
|
|
152
|
+
* @param frameCount Current frame count.
|
|
153
|
+
* @returns void
|
|
154
|
+
* @ignore
|
|
155
|
+
*/
|
|
156
|
+
renderFrame(frameCount: number): void;
|
|
157
|
+
/**
|
|
158
|
+
* Update the background color used in the loading screen theme.
|
|
159
|
+
* @param color The new background color.
|
|
160
|
+
* @ignore
|
|
161
|
+
*/
|
|
162
|
+
updateBackgroundColor(color: RGBA | null): void;
|
|
163
|
+
private _resolveRenderer;
|
|
164
|
+
/**
|
|
165
|
+
* Renders the library branding tag at the bottom left of the loading screen.
|
|
166
|
+
* Uses obfuscation techniques to make removal more difficult.
|
|
167
|
+
* @ignore
|
|
168
|
+
*/
|
|
169
|
+
private _renderBrandingTag;
|
|
170
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { LoadingScreenState } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Manages the state of the loading screen.
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export declare class LoadingScreenStateMachine {
|
|
7
|
+
private _state;
|
|
8
|
+
private _errorMessage;
|
|
9
|
+
private _errorDetails;
|
|
10
|
+
constructor(initialState?: LoadingScreenState);
|
|
11
|
+
get state(): LoadingScreenState;
|
|
12
|
+
get isEnabled(): boolean;
|
|
13
|
+
get shouldRender(): boolean;
|
|
14
|
+
get errorMessage(): string;
|
|
15
|
+
get errorDetails(): string;
|
|
16
|
+
activate(): void;
|
|
17
|
+
finish(): void;
|
|
18
|
+
startTransition(): void;
|
|
19
|
+
completeTransition(): void;
|
|
20
|
+
setError(error: Error | string): void;
|
|
21
|
+
disable(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LoadingScreenTheme, LoadingScreenOptions } from './types';
|
|
2
|
+
import type { Textmodifier } from '../Textmodifier';
|
|
3
|
+
import type { TextmodeColor } from '../TextmodeColor';
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the loading screen theme based on options and background color.
|
|
6
|
+
* @param options Loading screen options.
|
|
7
|
+
* @param background Background color as RGBA or null.
|
|
8
|
+
* @returns The resolved loading screen theme.
|
|
9
|
+
* @ignore
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveTheme(options: LoadingScreenOptions, background: [number, number, number, number] | null): LoadingScreenTheme;
|
|
12
|
+
/**
|
|
13
|
+
* Resolves the default color palette based on the theme mode.
|
|
14
|
+
* @param theme The loading screen theme.
|
|
15
|
+
* @returns An array of color strings representing the default palette.
|
|
16
|
+
* @ignore
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveDefaultPalette(theme: LoadingScreenTheme): string[];
|
|
19
|
+
/**
|
|
20
|
+
* Resolves an array of color inputs into TextmodeColor instances.
|
|
21
|
+
* @param inputs Input colors as numbers, strings, or TextmodeColor instances.
|
|
22
|
+
* @param textmodifier The Textmodifier instance used to create TextmodeColor objects.
|
|
23
|
+
* @returns An array of TextmodeColor instances.
|
|
24
|
+
* @ignore
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveColorInputs(inputs: (number | string | TextmodeColor)[], textmodifier: Textmodifier): TextmodeColor[];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type TransitionType = 'none' | 'fade';
|
|
2
|
+
/**
|
|
3
|
+
* Handles loading screen transitions.
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export declare class LoadingScreenTransition {
|
|
7
|
+
private _transitionStartTime;
|
|
8
|
+
private _transitionOpacity;
|
|
9
|
+
private _transitionType;
|
|
10
|
+
private _transitionDuration;
|
|
11
|
+
constructor(transitionType: TransitionType, transitionDuration: number);
|
|
12
|
+
get opacity(): number;
|
|
13
|
+
get isTransitioning(): boolean;
|
|
14
|
+
start(): void;
|
|
15
|
+
update(): boolean;
|
|
16
|
+
reset(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { LoadingScreenManager } from './LoadingScreenManager';
|
|
2
|
+
export { LoadingPhaseTracker } from './LoadingPhaseTracker';
|
|
3
|
+
export { LoadingScreenStateMachine } from './LoadingScreenState';
|
|
4
|
+
export { LoadingScreenTransition } from './LoadingScreenTransition';
|
|
5
|
+
export { resolveTheme, resolveDefaultPalette, resolveColorInputs } from './LoadingScreenTheme';
|
|
6
|
+
export type { LoadingPhaseSnapshot, LoadingScreenOptions, LoadingScreenRendererContext, LoadingPhaseHandle, LoadingScreenTheme, LoadingScreenState } from './types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { spinnerTemplate } from './SpinnerTemplate';
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import type { TextmodeGrid } from '../Grid';
|
|
2
|
+
import type { Textmodifier } from '../Textmodifier';
|
|
3
|
+
import type { TextmodeColor } from '../TextmodeColor';
|
|
4
|
+
/**
|
|
5
|
+
* Snapshot of a loading phase's state.
|
|
6
|
+
*/
|
|
7
|
+
export interface LoadingPhaseSnapshot {
|
|
8
|
+
/** The unique identifier of the loading phase. */
|
|
9
|
+
id: string;
|
|
10
|
+
/** The label or name of the loading phase. */
|
|
11
|
+
label: string;
|
|
12
|
+
/**
|
|
13
|
+
* The weight of this phase for calculating overall progress.
|
|
14
|
+
*/
|
|
15
|
+
weight: number;
|
|
16
|
+
/** The progress of the loading phase, represented as a number between 0 and 1. */
|
|
17
|
+
progress: number;
|
|
18
|
+
/** The current status of the loading phase. */
|
|
19
|
+
status: 'pending' | 'running' | 'complete' | 'failed';
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Options for configuring the loading screen.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```js
|
|
26
|
+
* const tm = textmode.create({
|
|
27
|
+
* width: 800,
|
|
28
|
+
* height: 600,
|
|
29
|
+
* loadingScreen: {
|
|
30
|
+
* message: 'booting...',
|
|
31
|
+
* }
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export interface LoadingScreenOptions {
|
|
36
|
+
/**
|
|
37
|
+
* Message to display on the loading screen. Default is `'loading...'`.
|
|
38
|
+
*/
|
|
39
|
+
message?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Color tone of the loading screen. Can be 'auto', 'light', or 'dark'. Default is 'auto'.
|
|
42
|
+
* <br/><br/>
|
|
43
|
+
* Based on the background color the `textmode.js` canvas is rendered on, the loading screen
|
|
44
|
+
* will automatically choose a light or dark theme when set to `'auto'`.
|
|
45
|
+
*/
|
|
46
|
+
tone?: 'auto' | 'light' | 'dark';
|
|
47
|
+
/**
|
|
48
|
+
* Provides a custom renderer function for the loading screen,
|
|
49
|
+
* overriding the default loading screen. The `context` parameter is a {@link LoadingScreenRendererContext} object.
|
|
50
|
+
*/
|
|
51
|
+
renderer?: (context: LoadingScreenRendererContext) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Type of transition effect. Default is `'fade'`.
|
|
54
|
+
*/
|
|
55
|
+
transition?: 'none' | 'fade';
|
|
56
|
+
/**
|
|
57
|
+
* Duration of the transition effect in milliseconds. Default is `500`ms.
|
|
58
|
+
*/
|
|
59
|
+
transitionDuration?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Context object passed to a loading screen renderer function.
|
|
63
|
+
*
|
|
64
|
+
* Can be used to create a custom loading screen to fit your needs.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* const t = textmode.create({
|
|
69
|
+
* width: 800,
|
|
70
|
+
* height: 600,
|
|
71
|
+
* loadingScreen: {
|
|
72
|
+
* message: 'loading...',
|
|
73
|
+
* renderer: (ctx) => {
|
|
74
|
+
* const { textmodifier: tm, grid, progress, message, transitionOpacity } = ctx;
|
|
75
|
+
*
|
|
76
|
+
* // Clear the screen
|
|
77
|
+
* tm.background(0, 0, 0, Math.floor(transitionOpacity * 255));
|
|
78
|
+
*
|
|
79
|
+
* // Position at top-left corner
|
|
80
|
+
* const x = -Math.floor(grid.cols / 2) + 2;
|
|
81
|
+
* const y = -Math.floor(grid.rows / 2) + 2;
|
|
82
|
+
*
|
|
83
|
+
* tm.push();
|
|
84
|
+
* tm.translate(x, y, 0);
|
|
85
|
+
* tm.charColor(255, 255, 255, transitionOpacity * 255);
|
|
86
|
+
*
|
|
87
|
+
* // Display message
|
|
88
|
+
* if (message) {
|
|
89
|
+
* for (let i = 0; i < message.length; i++) {
|
|
90
|
+
* tm.char(message[i]);
|
|
91
|
+
* tm.rect(1, 1);
|
|
92
|
+
* tm.translateX(1);
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
*
|
|
96
|
+
* // Display progress bar
|
|
97
|
+
* tm.translate(-message.length, 2, 0);
|
|
98
|
+
* const barWidth = 20;
|
|
99
|
+
* const filled = Math.floor(progress * barWidth);
|
|
100
|
+
*
|
|
101
|
+
* for (let i = 0; i < barWidth; i++) {
|
|
102
|
+
* tm.char(i < filled ? '=' : '-');
|
|
103
|
+
* tm.rect(1, 1);
|
|
104
|
+
* tm.translateX(1);
|
|
105
|
+
* }
|
|
106
|
+
*
|
|
107
|
+
* tm.pop();
|
|
108
|
+
* }
|
|
109
|
+
* }
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export interface LoadingScreenRendererContext {
|
|
114
|
+
/** The Textmodifier instance for rendering text and graphics. */
|
|
115
|
+
textmodifier: Textmodifier;
|
|
116
|
+
/** The TextmodeGrid representing the screen grid. */
|
|
117
|
+
grid: TextmodeGrid;
|
|
118
|
+
/** The current loading progress (0-1). */
|
|
119
|
+
progress: number;
|
|
120
|
+
/** The elapsed time since the loading started, in milliseconds. */
|
|
121
|
+
elapsedMs: number;
|
|
122
|
+
/** The number of frames rendered since the loading started. */
|
|
123
|
+
frameCount: number;
|
|
124
|
+
/** The current loading message, if any. */
|
|
125
|
+
message?: string;
|
|
126
|
+
/** The palette of colors available for rendering based on the `theme`. */
|
|
127
|
+
palette: TextmodeColor[];
|
|
128
|
+
/** The current theme of the loading screen. */
|
|
129
|
+
theme: LoadingScreenTheme;
|
|
130
|
+
/** The phases of the loading process. */
|
|
131
|
+
phases: LoadingPhaseSnapshot[];
|
|
132
|
+
/** The opacity level for transition effects. */
|
|
133
|
+
transitionOpacity: number;
|
|
134
|
+
/** Indicates if the loading screen is in an error state. */
|
|
135
|
+
isError: boolean;
|
|
136
|
+
/** The error message to display, if any. */
|
|
137
|
+
errorMessage?: string;
|
|
138
|
+
/** Detailed error information, if any. */
|
|
139
|
+
errorDetails?: string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* A function that renders the loading screen.
|
|
143
|
+
*/
|
|
144
|
+
export type LoadingScreenRenderer = (context: LoadingScreenRendererContext) => void;
|
|
145
|
+
/**
|
|
146
|
+
* Handle for managing a loading phase.
|
|
147
|
+
*/
|
|
148
|
+
export interface LoadingPhaseHandle {
|
|
149
|
+
/**
|
|
150
|
+
* The unique identifier of the loading phase.
|
|
151
|
+
*/
|
|
152
|
+
id: string;
|
|
153
|
+
/**
|
|
154
|
+
* The label or name of the loading phase.
|
|
155
|
+
*/
|
|
156
|
+
label: string;
|
|
157
|
+
/**
|
|
158
|
+
* Update the progress of the loading phase.
|
|
159
|
+
* @param progress A number between 0 and 1 representing the phase's progress.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* const t = textmode.create({ width: 800, height: 600, loadingScreen: { message: 'prepping...' } });
|
|
164
|
+
*
|
|
165
|
+
* // Create a phase and report progress as work proceeds
|
|
166
|
+
* t.setup(async () => {
|
|
167
|
+
* const phase = t.loading.beginPhase('assets', 1);
|
|
168
|
+
* phase.report(0.25);
|
|
169
|
+
* // ...load assets...
|
|
170
|
+
* phase.report(0.75);
|
|
171
|
+
* phase.complete();
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
report(progress: number): void;
|
|
176
|
+
/**
|
|
177
|
+
* Mark the loading phase as complete.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const t = textmode.create({ width: 800, height: 600, loadingScreen: { message: 'prepping...' } });
|
|
182
|
+
*
|
|
183
|
+
* t.setup(() => {
|
|
184
|
+
* const phase = t.loading.beginPhase('init', 1);
|
|
185
|
+
* // Finish phase when work is done
|
|
186
|
+
* phase.complete();
|
|
187
|
+
* });
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
complete(): void;
|
|
191
|
+
/**
|
|
192
|
+
* Mark the loading phase as failed.
|
|
193
|
+
* @param error An optional error object describing the failure.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```ts
|
|
197
|
+
* const t = textmode.create({ width: 800, height: 600 });
|
|
198
|
+
*
|
|
199
|
+
* t.setup(async () => {
|
|
200
|
+
* const phase = t.loading.beginPhase('fetch', 1);
|
|
201
|
+
* try {
|
|
202
|
+
* // simulate failure
|
|
203
|
+
* throw new Error('network error');
|
|
204
|
+
* } catch (err) {
|
|
205
|
+
* phase.fail(err instanceof Error ? err : String(err));
|
|
206
|
+
* }
|
|
207
|
+
* });
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
fail(error?: Error): void;
|
|
211
|
+
/**
|
|
212
|
+
* Track a task within this loading phase.
|
|
213
|
+
* @param task A promise or function representing the task to track.
|
|
214
|
+
* @returns A promise that resolves with the task's result.
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```ts
|
|
218
|
+
* const t = textmode.create({ width: 800, height: 600, loadingScreen: { message: 'loading...' } });
|
|
219
|
+
*
|
|
220
|
+
* t.setup(async () => {
|
|
221
|
+
* const phase = t.loading.beginPhase('video', 2);
|
|
222
|
+
* await phase.track(async () => {
|
|
223
|
+
* // do async work and report updates
|
|
224
|
+
* for (let i = 0; i <= 10; i++) {
|
|
225
|
+
* phase.report(i / 10);
|
|
226
|
+
* await new Promise((r) => setTimeout(r, 30));
|
|
227
|
+
* }
|
|
228
|
+
* });
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
track<T>(task: Promise<T> | (() => Promise<T> | T)): Promise<T>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Theme settings for the loading screen.
|
|
236
|
+
*/
|
|
237
|
+
export interface LoadingScreenTheme {
|
|
238
|
+
/** The color mode of the loading screen, either 'light' or 'dark'. */
|
|
239
|
+
mode: 'light' | 'dark';
|
|
240
|
+
/** The background color of the loading screen, or null for transparent. */
|
|
241
|
+
background: [number, number, number, number] | null;
|
|
242
|
+
/** The primary text color used on the loading screen. */
|
|
243
|
+
textColor: number | string | TextmodeColor;
|
|
244
|
+
/** The subtle text color used on the loading screen. */
|
|
245
|
+
subtleColor: number | string | TextmodeColor;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The state of the loading screen.
|
|
249
|
+
* @ignore
|
|
250
|
+
*/
|
|
251
|
+
export type LoadingScreenState = 'disabled' | 'active' | 'done' | 'transitioning' | 'error';
|
|
@@ -39,7 +39,7 @@ export interface KeyState {
|
|
|
39
39
|
* Manages all keyboard interaction for a Textmodifier instance.
|
|
40
40
|
* Handles event listeners, key state tracking, and event dispatching.
|
|
41
41
|
*
|
|
42
|
-
* Provides
|
|
42
|
+
* Provides keyboard functionality including:
|
|
43
43
|
* - keyPressed() and keyReleased() callbacks
|
|
44
44
|
* - Current key state tracking
|
|
45
45
|
* - Special key handling (arrows, function keys, etc.)
|
|
@@ -56,7 +56,6 @@ export declare class KeyboardManager {
|
|
|
56
56
|
private _keyPressedCallback?;
|
|
57
57
|
private _keyReleasedCallback?;
|
|
58
58
|
private readonly _specialKeyMap;
|
|
59
|
-
constructor();
|
|
60
59
|
/**
|
|
61
60
|
* Setup keyboard event listeners.
|
|
62
61
|
*/
|
|
@@ -119,7 +118,7 @@ export declare class KeyboardManager {
|
|
|
119
118
|
*/
|
|
120
119
|
private _handleKeyUp;
|
|
121
120
|
/**
|
|
122
|
-
* Normalize key names for consistency
|
|
121
|
+
* Normalize key names for consistency
|
|
123
122
|
*/
|
|
124
123
|
private _normalizeKey;
|
|
125
124
|
}
|
|
@@ -89,7 +89,7 @@ export declare class MouseManager {
|
|
|
89
89
|
* This is useful when grid dimensions change (font size, window resize, etc.)
|
|
90
90
|
* and we need to recalculate the mouse coordinates without waiting for a mouse event.
|
|
91
91
|
*/
|
|
92
|
-
$
|
|
92
|
+
$updatePositions(): void;
|
|
93
93
|
/**
|
|
94
94
|
* Set a callback function that will be called when the mouse is clicked.
|
|
95
95
|
* @param callback The function to call when the mouse is clicked
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import type { Textmodifier } from '../Textmodifier';
|
|
2
|
-
import type { GLRenderer } from '../../rendering/webgl/Renderer';
|
|
2
|
+
import type { GLRenderer } from '../../rendering/webgl/core/Renderer';
|
|
3
3
|
import type { GLFramebuffer } from '../../rendering';
|
|
4
|
-
import type { TextmodeFont } from '../font';
|
|
4
|
+
import type { TextmodeFont } from '../loadables/font';
|
|
5
5
|
import type { TextmodeGrid } from '../Grid';
|
|
6
6
|
import type { TextmodeCanvas } from '../Canvas';
|
|
7
7
|
export type TextmodePluginHook = () => void;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* An extended API provided to plugins when they are installed on a {@link Textmodifier} instance.
|
|
10
|
+
*/
|
|
11
|
+
export interface TextmodePluginAPI {
|
|
9
12
|
/** The WebGL renderer used by the Textmodifier instance. */
|
|
10
13
|
renderer: GLRenderer;
|
|
11
14
|
/** The font used by the Textmodifier instance. */
|
|
@@ -16,21 +19,15 @@ export interface TextmodePluginContext {
|
|
|
16
19
|
canvas: TextmodeCanvas;
|
|
17
20
|
/** The framebuffer the user draws to. */
|
|
18
21
|
drawFramebuffer: GLFramebuffer;
|
|
19
|
-
/** The framebuffer containing the ASCII representation
|
|
22
|
+
/** The framebuffer containing the ASCII representation.<br/>
|
|
23
|
+
* This framebuffer only has a single render target. */
|
|
20
24
|
asciiFramebuffer: GLFramebuffer;
|
|
21
|
-
/** Immediately execute any pending draw commands. */
|
|
22
|
-
flushDrawCommands(): void;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* An extended API provided to plugins when they are installed on a {@link Textmodifier} instance.
|
|
26
|
-
*/
|
|
27
|
-
export interface TextmodePluginAPI extends TextmodePluginContext {
|
|
28
25
|
/**
|
|
29
|
-
* Register a callback to be invoked before each draw cycle. Happens
|
|
26
|
+
* Register a callback to be invoked before each draw cycle. Happens just before the draw framebuffer is being bound.
|
|
30
27
|
*/
|
|
31
28
|
registerPreDrawHook(callback: () => void): () => void;
|
|
32
29
|
/**
|
|
33
|
-
* Register a callback to be invoked after each draw cycle. Happens outside of the draw framebuffer being bound.
|
|
30
|
+
* 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.
|
|
34
31
|
*/
|
|
35
32
|
registerPostDrawHook(callback: () => void): () => void;
|
|
36
33
|
}
|
|
@@ -66,8 +63,8 @@ export declare class TextmodePluginManager {
|
|
|
66
63
|
constructor(textmodifier: Textmodifier);
|
|
67
64
|
$installMany(plugins: TextmodePlugin[]): Promise<void>;
|
|
68
65
|
$unuse(pluginName: string): Promise<void>;
|
|
69
|
-
runPreDrawHooks(): void;
|
|
70
|
-
runPostDrawHooks(): void;
|
|
66
|
+
$runPreDrawHooks(): void;
|
|
67
|
+
$runPostDrawHooks(): void;
|
|
71
68
|
$disposeAll(): Promise<void>;
|
|
72
69
|
private _createAPI;
|
|
73
70
|
private _registerHook;
|