textmode.js 0.7.1 → 0.8.0-beta.2
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 +2042 -2108
- package/dist/textmode.umd.js +16 -16
- package/dist/types/Textmode.d.ts +11 -11
- package/dist/types/errors/index.d.ts +1 -1
- package/dist/types/index.d.ts +11 -3
- package/dist/types/rendering/webgl/core/Framebuffer.d.ts +0 -6
- package/dist/types/rendering/webgl/core/Renderer.d.ts +7 -6
- package/dist/types/rendering/webgl/core/interfaces/IFramebuffer.d.ts +6 -6
- package/dist/types/rendering/webgl/core/interfaces/IRenderer.d.ts +3 -3
- package/dist/types/rendering/webgl/index.d.ts +2 -2
- package/dist/types/rendering/webgl/pipeline/MaterialBatchPipeline.d.ts +1 -1
- package/dist/types/textmode/Canvas.d.ts +2 -2
- package/dist/types/textmode/Grid.d.ts +32 -3
- package/dist/types/textmode/Textmodifier.d.ts +14 -72
- package/dist/types/textmode/conversion/ConversionManager.d.ts +73 -0
- package/dist/types/textmode/conversion/ConversionRegistry.d.ts +61 -18
- package/dist/types/textmode/conversion/index.d.ts +3 -1
- package/dist/types/textmode/filters/FilterManager.d.ts +0 -4
- package/dist/types/textmode/filters/index.d.ts +1 -1
- package/dist/types/textmode/interfaces/ITextmodifier.d.ts +165 -50
- package/dist/types/textmode/layers/Layer2DCompositor.d.ts +13 -20
- package/dist/types/textmode/layers/LayerManager.d.ts +31 -20
- package/dist/types/textmode/layers/TextmodeLayer.d.ts +58 -20
- package/dist/types/textmode/layers/interfaces/ILayerManager.d.ts +7 -0
- package/dist/types/textmode/layers/interfaces/ITextmodeLayer.d.ts +49 -28
- package/dist/types/textmode/layers/types.d.ts +16 -21
- package/dist/types/textmode/loadables/ITextmodeSource.d.ts +123 -0
- package/dist/types/textmode/loadables/TextmodeImage.d.ts +2 -2
- package/dist/types/textmode/loadables/TextmodeSource.d.ts +10 -118
- package/dist/types/textmode/loadables/font/CharacterExtractor.d.ts +1 -1
- package/dist/types/textmode/loadables/font/TextmodeFont.d.ts +3 -0
- package/dist/types/textmode/loadables/font/index.d.ts +2 -2
- package/dist/types/textmode/loadables/index.d.ts +0 -2
- package/dist/types/textmode/loadables/video/ITextmodeVideo.d.ts +75 -0
- package/dist/types/textmode/loadables/video/TextmodeVideo.d.ts +23 -126
- package/dist/types/textmode/loading/LoadingPhase.d.ts +26 -0
- package/dist/types/textmode/loading/LoadingScreenManager.d.ts +91 -93
- package/dist/types/textmode/loading/index.d.ts +3 -2
- package/dist/types/textmode/loading/types.d.ts +57 -57
- package/dist/types/textmode/managers/MouseManager.d.ts +24 -14
- package/dist/types/textmode/managers/TouchManager.d.ts +25 -13
- package/dist/types/textmode/mixins/index.d.ts +1 -2
- package/dist/types/textmode/mixins/interfaces/IAnimationMixin.d.ts +87 -87
- package/dist/types/textmode/mixins/interfaces/IKeyboardMixin.d.ts +128 -128
- package/dist/types/textmode/mixins/interfaces/IMouseMixin.d.ts +96 -105
- package/dist/types/textmode/mixins/interfaces/IRenderingMixin.d.ts +271 -370
- package/dist/types/textmode/mixins/interfaces/ITouchMixin.d.ts +1 -1
- package/dist/types/textmode/types.d.ts +2 -6
- package/package.json +5 -2
- package/dist/types/textmode/layers/filters/index.d.ts +0 -6
- package/dist/types/textmode/loadables/video/TextmodeVideoPreloader.d.ts +0 -29
- package/dist/types/textmode/loadables/video/types.d.ts +0 -43
- package/dist/types/textmode/mixins/FontMixin.d.ts +0 -8
- package/dist/types/textmode/mixins/interfaces/IFontMixin.d.ts +0 -46
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { MouseEventHandler, MousePosition } from
|
|
1
|
+
import type { MouseEventHandler, MousePosition } from '../../managers/MouseManager';
|
|
2
2
|
/**
|
|
3
3
|
* Capabilities provided by the MouseMixin
|
|
4
4
|
*/
|
|
@@ -19,11 +19,11 @@ export interface IMouseMixin {
|
|
|
19
19
|
*
|
|
20
20
|
* // Create a ripple at the clicked grid cell
|
|
21
21
|
* t.mouseClicked((data) => {
|
|
22
|
-
* //
|
|
23
|
-
*
|
|
24
|
-
* const centerY = Math.round(data.position.y - (t.grid.rows - 1) / 2);
|
|
22
|
+
* // Skip if mouse is outside the grid
|
|
23
|
+
* if (data.position.x === Number.NEGATIVE_INFINITY) return;
|
|
25
24
|
*
|
|
26
|
-
*
|
|
25
|
+
* // Coordinates are already center-based, matching the drawing coordinate system
|
|
26
|
+
* ripples.push({ x: data.position.x, y: data.position.y, age: 0, maxAge: 20 });
|
|
27
27
|
* });
|
|
28
28
|
*
|
|
29
29
|
* t.draw(() => {
|
|
@@ -64,14 +64,12 @@ export interface IMouseMixin {
|
|
|
64
64
|
* }
|
|
65
65
|
* }
|
|
66
66
|
*
|
|
67
|
-
* // Show crosshair for the current mouse cell
|
|
68
|
-
* //
|
|
69
|
-
* if (t.mouse.x !==
|
|
70
|
-
* const cx = Math.round(t.mouse.x - (t.grid.cols - 1) / 2);
|
|
71
|
-
* const cy = Math.round(t.mouse.y - (t.grid.rows - 1) / 2);
|
|
67
|
+
* // Show crosshair for the current mouse cell
|
|
68
|
+
* // Mouse coordinates are center-based, matching the drawing coordinate system
|
|
69
|
+
* if (t.mouse.x !== Number.NEGATIVE_INFINITY) {
|
|
72
70
|
* t.push();
|
|
73
71
|
* t.charColor(180);
|
|
74
|
-
* t.translate(
|
|
72
|
+
* t.translate(t.mouse.x, t.mouse.y);
|
|
75
73
|
* t.char('+');
|
|
76
74
|
* t.point();
|
|
77
75
|
* t.pop();
|
|
@@ -95,7 +93,7 @@ export interface IMouseMixin {
|
|
|
95
93
|
* let pressing = false;
|
|
96
94
|
*
|
|
97
95
|
* t.mousePressed((data) => {
|
|
98
|
-
* if (data.position.x ===
|
|
96
|
+
* if (data.position.x === Number.NEGATIVE_INFINITY) return;
|
|
99
97
|
* pressing = true;
|
|
100
98
|
* });
|
|
101
99
|
*
|
|
@@ -106,10 +104,10 @@ export interface IMouseMixin {
|
|
|
106
104
|
* t.draw(() => {
|
|
107
105
|
* t.background(0);
|
|
108
106
|
*
|
|
109
|
-
* // Spawn particles while pressing
|
|
110
|
-
* if (pressing && t.mouse.x !==
|
|
111
|
-
* const cx =
|
|
112
|
-
* const cy =
|
|
107
|
+
* // Spawn particles while pressing (mouse coords are center-based)
|
|
108
|
+
* if (pressing && t.mouse.x !== Number.NEGATIVE_INFINITY) {
|
|
109
|
+
* const cx = t.mouse.x;
|
|
110
|
+
* const cy = t.mouse.y;
|
|
113
111
|
*
|
|
114
112
|
* for (let i = 0; i < 3; i++) {
|
|
115
113
|
* particles.push({
|
|
@@ -165,16 +163,15 @@ export interface IMouseMixin {
|
|
|
165
163
|
* let dragStart = null;
|
|
166
164
|
*
|
|
167
165
|
* t.mousePressed((data) => {
|
|
168
|
-
* if (data.position.x ===
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* dragStart = { x: cx, y: cy };
|
|
166
|
+
* if (data.position.x === Number.NEGATIVE_INFINITY) return;
|
|
167
|
+
* // Coordinates are already center-based
|
|
168
|
+
* dragStart = { x: data.position.x, y: data.position.y };
|
|
172
169
|
* });
|
|
173
170
|
*
|
|
174
171
|
* t.mouseReleased((data) => {
|
|
175
|
-
* if (!dragStart || data.position.x ===
|
|
176
|
-
* const cx =
|
|
177
|
-
* const cy =
|
|
172
|
+
* if (!dragStart || data.position.x === Number.NEGATIVE_INFINITY) return;
|
|
173
|
+
* const cx = data.position.x;
|
|
174
|
+
* const cy = data.position.y;
|
|
178
175
|
*
|
|
179
176
|
* // Calculate line center and local endpoints
|
|
180
177
|
* const centerX = (dragStart.x + cx) / 2;
|
|
@@ -215,10 +212,10 @@ export interface IMouseMixin {
|
|
|
215
212
|
* t.pop();
|
|
216
213
|
* }
|
|
217
214
|
*
|
|
218
|
-
* // Draw current drag line
|
|
219
|
-
* if (dragStart && t.mouse.x !==
|
|
220
|
-
* const cx =
|
|
221
|
-
* const cy =
|
|
215
|
+
* // Draw current drag line (mouse coords are center-based)
|
|
216
|
+
* if (dragStart && t.mouse.x !== Number.NEGATIVE_INFINITY) {
|
|
217
|
+
* const cx = t.mouse.x;
|
|
218
|
+
* const cy = t.mouse.y;
|
|
222
219
|
* const centerX = (dragStart.x + cx) / 2;
|
|
223
220
|
* const centerY = (dragStart.y + cy) / 2;
|
|
224
221
|
* const dx = cx - dragStart.x;
|
|
@@ -252,11 +249,11 @@ export interface IMouseMixin {
|
|
|
252
249
|
* let lastMouse = null;
|
|
253
250
|
*
|
|
254
251
|
* t.mouseMoved((data) => {
|
|
255
|
-
* if (data.position.x ===
|
|
252
|
+
* if (data.position.x === Number.NEGATIVE_INFINITY) return;
|
|
256
253
|
*
|
|
257
|
-
* //
|
|
258
|
-
* const cx =
|
|
259
|
-
* const cy =
|
|
254
|
+
* // Coordinates are already center-based, matching the drawing system
|
|
255
|
+
* const cx = data.position.x;
|
|
256
|
+
* const cy = data.position.y;
|
|
260
257
|
*
|
|
261
258
|
* // Spawn multiple particles based on movement speed
|
|
262
259
|
* const dx = lastMouse ? cx - lastMouse.x : 0;
|
|
@@ -313,39 +310,40 @@ export interface IMouseMixin {
|
|
|
313
310
|
*
|
|
314
311
|
* @example
|
|
315
312
|
* ```javascript
|
|
316
|
-
|
|
313
|
+
* // Scroll to create expanding rings.
|
|
317
314
|
*
|
|
318
315
|
* const t = textmode.create({ width: 800, height: 600 });
|
|
319
316
|
*
|
|
320
317
|
* const rings = [];
|
|
321
318
|
*
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
319
|
+
* t.mouseScrolled((data) => {
|
|
320
|
+
* if (data.position.x === Number.NEGATIVE_INFINITY) return;
|
|
321
|
+
*
|
|
322
|
+
* // Coordinates are already center-based
|
|
323
|
+
* const cx = data.position.x;
|
|
324
|
+
* const cy = data.position.y;
|
|
325
|
+
*
|
|
326
|
+
* // Use scroll delta to determine ring intensity and direction
|
|
327
|
+
* const scrollSpeed = 2;
|
|
328
|
+
* const intensity = Math.min(scrollSpeed * 30, 255);
|
|
329
|
+
* const scrollDown = (data.delta?.y || 0) > 0;
|
|
330
|
+
*
|
|
331
|
+
* rings.push({
|
|
332
|
+
* x: cx,
|
|
333
|
+
* y: cy,
|
|
334
|
+
* radius: 1,
|
|
335
|
+
* maxRadius: 5 + scrollSpeed * 0.5,
|
|
336
|
+
* color: intensity,
|
|
337
|
+
* scrollDown: scrollDown,
|
|
338
|
+
* age: 0,
|
|
339
|
+
* maxAge: 20
|
|
340
|
+
* });
|
|
341
|
+
* });
|
|
344
342
|
*
|
|
345
343
|
* t.draw(() => {
|
|
346
344
|
* t.background(0);
|
|
347
345
|
*
|
|
348
|
-
|
|
346
|
+
* // Update and draw rings
|
|
349
347
|
* for (let i = rings.length - 1; i >= 0; i--) {
|
|
350
348
|
* const r = rings[i];
|
|
351
349
|
* r.age++;
|
|
@@ -359,13 +357,13 @@ export interface IMouseMixin {
|
|
|
359
357
|
* const life = 1 - (r.age / r.maxAge);
|
|
360
358
|
* const brightness = Math.round(r.color * life);
|
|
361
359
|
*
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
360
|
+
* t.push();
|
|
361
|
+
* // Blue for scroll down, orange for scroll up
|
|
362
|
+
* if (r.scrollDown) {
|
|
363
|
+
* t.charColor(brightness * 0.5, brightness * 0.8, 255);
|
|
364
|
+
* } else {
|
|
365
|
+
* t.charColor(255, brightness * 0.6, brightness * 0.3);
|
|
366
|
+
* }
|
|
369
367
|
* t.translate(r.x, r.y);
|
|
370
368
|
*
|
|
371
369
|
* // Draw ring
|
|
@@ -385,12 +383,13 @@ export interface IMouseMixin {
|
|
|
385
383
|
*/
|
|
386
384
|
mouseScrolled(callback: MouseEventHandler): void;
|
|
387
385
|
/**
|
|
388
|
-
* Get the current mouse position in grid coordinates.
|
|
386
|
+
* Get the current mouse position in center-based grid coordinates.
|
|
389
387
|
*
|
|
390
|
-
* Returns the mouse position as grid cell coordinates
|
|
388
|
+
* Returns the mouse position as grid cell coordinates where `(0, 0)` is the center cell.
|
|
389
|
+
* This matches the drawing coordinate system, so coordinates can be used directly with `translate()`.
|
|
391
390
|
*
|
|
392
391
|
* If the mouse is outside the grid or the instance is not ready,
|
|
393
|
-
* it returns `{ x:
|
|
392
|
+
* it returns `{ x: Number.NEGATIVE_INFINITY, y: Number.NEGATIVE_INFINITY }`.
|
|
394
393
|
*
|
|
395
394
|
* @example
|
|
396
395
|
* ```javascript
|
|
@@ -399,15 +398,14 @@ export interface IMouseMixin {
|
|
|
399
398
|
* t.draw(() => {
|
|
400
399
|
* t.background(0);
|
|
401
400
|
*
|
|
402
|
-
* //
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
* t.point();
|
|
401
|
+
* // Mouse coordinates are center-based, matching the drawing system
|
|
402
|
+
* if (t.mouse.x !== Number.NEGATIVE_INFINITY) {
|
|
403
|
+
* t.translate(t.mouse.x, t.mouse.y);
|
|
404
|
+
* t.char('*');
|
|
405
|
+
* t.charColor(255, 0, 0);
|
|
406
|
+
* t.cellColor(100);
|
|
407
|
+
* t.point();
|
|
408
|
+
* }
|
|
411
409
|
* });
|
|
412
410
|
* ```
|
|
413
411
|
*/
|
|
@@ -421,37 +419,30 @@ export interface IMouseMixin {
|
|
|
421
419
|
*
|
|
422
420
|
* See MDN for all options: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor
|
|
423
421
|
*
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
* const hovering =
|
|
449
|
-
* t.mouse.x >= rectLeft && t.mouse.x < rectRight &&
|
|
450
|
-
* t.mouse.y >= rectTop && t.mouse.y < rectBottom;
|
|
451
|
-
*
|
|
452
|
-
* t.cursor(hovering ? 'pointer' : 'default');
|
|
453
|
-
* });
|
|
454
|
-
* ```
|
|
422
|
+
* @example
|
|
423
|
+
* ```javascript
|
|
424
|
+
* const t = textmode.create({ width: 800, height: 600 });
|
|
425
|
+
* const target = { width: 30, height: 15 };
|
|
426
|
+
*
|
|
427
|
+
* t.draw(() => {
|
|
428
|
+
* t.background(0);
|
|
429
|
+
* t.charColor(255); // keep char visible
|
|
430
|
+
* t.char('*');
|
|
431
|
+
* t.rect(target.width, target.height);
|
|
432
|
+
*
|
|
433
|
+
* // Rectangle is centered at (0, 0) which is grid center
|
|
434
|
+
* // Mouse coordinates are also center-based, so we can compare directly
|
|
435
|
+
* const halfRectWidth = target.width / 2;
|
|
436
|
+
* const halfRectHeight = target.height / 2;
|
|
437
|
+
*
|
|
438
|
+
* const hovering =
|
|
439
|
+
* t.mouse.x !== Number.NEGATIVE_INFINITY &&
|
|
440
|
+
* t.mouse.x >= -halfRectWidth && t.mouse.x < halfRectWidth &&
|
|
441
|
+
* t.mouse.y >= -halfRectHeight && t.mouse.y < halfRectHeight;
|
|
442
|
+
*
|
|
443
|
+
* t.cursor(hovering ? 'pointer' : 'default');
|
|
444
|
+
* });
|
|
445
|
+
* ```
|
|
455
446
|
*/
|
|
456
447
|
cursor(cursor?: string): void;
|
|
457
448
|
}
|