@datamoc/mw_games 0.4.1 → 0.4.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/README.md +1 -1
- package/dist/assets/binary.d.ts +52 -0
- package/dist/assets/binary.d.ts.map +1 -0
- package/dist/assets/binary.js +57 -0
- package/dist/assets/binary.js.map +1 -0
- package/dist/assets/index.d.ts +10 -5
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js +9 -5
- package/dist/assets/index.js.map +1 -1
- package/dist/board/Army.d.ts +75 -0
- package/dist/board/Army.d.ts.map +1 -1
- package/dist/board/Army.js +75 -0
- package/dist/board/Army.js.map +1 -1
- package/dist/board/Classics.d.ts +297 -1
- package/dist/board/Classics.d.ts.map +1 -1
- package/dist/board/Classics.js +297 -1
- package/dist/board/Classics.js.map +1 -1
- package/dist/board/Engine.d.ts +23 -0
- package/dist/board/Engine.d.ts.map +1 -1
- package/dist/board/Engine.js +23 -0
- package/dist/board/Engine.js.map +1 -1
- package/dist/board/FogOfWar.d.ts +20 -0
- package/dist/board/FogOfWar.d.ts.map +1 -1
- package/dist/board/FogOfWar.js +20 -0
- package/dist/board/FogOfWar.js.map +1 -1
- package/dist/board/Tactics.d.ts +158 -1
- package/dist/board/Tactics.d.ts.map +1 -1
- package/dist/board/Tactics.js +125 -1
- package/dist/board/Tactics.js.map +1 -1
- package/dist/board/chess.d.ts +87 -3
- package/dist/board/chess.d.ts.map +1 -1
- package/dist/board/chess.js +96 -4
- package/dist/board/chess.js.map +1 -1
- package/dist/i18n/Content.d.ts +151 -0
- package/dist/i18n/Content.d.ts.map +1 -0
- package/dist/i18n/Content.js +219 -0
- package/dist/i18n/Content.js.map +1 -0
- package/dist/i18n/index.d.ts +35 -3
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +88 -6
- package/dist/i18n/index.js.map +1 -1
- package/dist/mw_games.global.js +89 -89
- package/dist/roguelike/Placement.d.ts +62 -0
- package/dist/roguelike/Placement.d.ts.map +1 -0
- package/dist/roguelike/Placement.js +79 -0
- package/dist/roguelike/Placement.js.map +1 -0
- package/dist/roguelike/index.d.ts +2 -0
- package/dist/roguelike/index.d.ts.map +1 -1
- package/dist/roguelike/index.js +1 -0
- package/dist/roguelike/index.js.map +1 -1
- package/dist/three-d/Models.d.ts +38 -1
- package/dist/three-d/Models.d.ts.map +1 -1
- package/dist/three-d/Models.js +66 -3
- package/dist/three-d/Models.js.map +1 -1
- package/dist/two-d/render/ActorAnimator.d.ts +32 -0
- package/dist/two-d/render/ActorAnimator.d.ts.map +1 -1
- package/dist/two-d/render/ActorAnimator.js +21 -0
- package/dist/two-d/render/ActorAnimator.js.map +1 -1
- package/dist/two-d/render/AnimatedSprite.d.ts +24 -4
- package/dist/two-d/render/AnimatedSprite.d.ts.map +1 -1
- package/dist/two-d/render/AnimatedSprite.js +24 -4
- package/dist/two-d/render/AnimatedSprite.js.map +1 -1
- package/dist/two-d/render/Autotile.d.ts +33 -1
- package/dist/two-d/render/Autotile.d.ts.map +1 -1
- package/dist/two-d/render/Autotile.js +33 -1
- package/dist/two-d/render/Autotile.js.map +1 -1
- package/dist/two-d/render/Camera.d.ts +53 -1
- package/dist/two-d/render/Camera.d.ts.map +1 -1
- package/dist/two-d/render/Camera.js +36 -1
- package/dist/two-d/render/Camera.js.map +1 -1
- package/dist/two-d/render/Capabilities.d.ts +33 -0
- package/dist/two-d/render/Capabilities.d.ts.map +1 -1
- package/dist/two-d/render/Capabilities.js +33 -0
- package/dist/two-d/render/Capabilities.js.map +1 -1
- package/dist/two-d/render/ColorBlindness.d.ts +23 -0
- package/dist/two-d/render/ColorBlindness.d.ts.map +1 -1
- package/dist/two-d/render/ColorBlindness.js +23 -4
- package/dist/two-d/render/ColorBlindness.js.map +1 -1
- package/dist/two-d/render/ColorTransformBatcher.d.ts +67 -1
- package/dist/two-d/render/ColorTransformBatcher.d.ts.map +1 -1
- package/dist/two-d/render/ColorTransformBatcher.js +57 -1
- package/dist/two-d/render/ColorTransformBatcher.js.map +1 -1
- package/dist/two-d/render/LayeredSprite.d.ts +19 -0
- package/dist/two-d/render/LayeredSprite.d.ts.map +1 -1
- package/dist/two-d/render/LayeredSprite.js +19 -0
- package/dist/two-d/render/LayeredSprite.js.map +1 -1
- package/dist/two-d/render/Minimap.d.ts +25 -1
- package/dist/two-d/render/Minimap.d.ts.map +1 -1
- package/dist/two-d/render/Minimap.js +25 -1
- package/dist/two-d/render/Minimap.js.map +1 -1
- package/dist/two-d/render/Particles.d.ts +26 -2
- package/dist/two-d/render/Particles.d.ts.map +1 -1
- package/dist/two-d/render/Particles.js +23 -0
- package/dist/two-d/render/Particles.js.map +1 -1
- package/dist/two-d/render/Projectile.d.ts +14 -0
- package/dist/two-d/render/Projectile.d.ts.map +1 -1
- package/dist/two-d/render/Projectile.js +14 -0
- package/dist/two-d/render/Projectile.js.map +1 -1
- package/dist/two-d/render/ScreenEffects.d.ts +15 -0
- package/dist/two-d/render/ScreenEffects.d.ts.map +1 -1
- package/dist/two-d/render/ScreenEffects.js +15 -0
- package/dist/two-d/render/ScreenEffects.js.map +1 -1
- package/dist/two-d/render/Shape2D.d.ts +58 -1
- package/dist/two-d/render/Shape2D.d.ts.map +1 -1
- package/dist/two-d/render/Shape2D.js +58 -1
- package/dist/two-d/render/Shape2D.js.map +1 -1
- package/dist/two-d/render/StatusVisuals.d.ts +22 -0
- package/dist/two-d/render/StatusVisuals.d.ts.map +1 -1
- package/dist/two-d/render/StatusVisuals.js +22 -0
- package/dist/two-d/render/StatusVisuals.js.map +1 -1
- package/dist/two-d/render/TileMap.d.ts +65 -3
- package/dist/two-d/render/TileMap.d.ts.map +1 -1
- package/dist/two-d/render/TileMap.js +65 -3
- package/dist/two-d/render/TileMap.js.map +1 -1
- package/dist/two-d/render/TiledMap.d.ts +9 -3
- package/dist/two-d/render/TiledMap.d.ts.map +1 -1
- package/dist/two-d/render/TiledMap.js +9 -3
- package/dist/two-d/render/TiledMap.js.map +1 -1
- package/dist/two-d/render/TintedSprite.d.ts +9 -2
- package/dist/two-d/render/TintedSprite.d.ts.map +1 -1
- package/dist/two-d/render/TintedSprite.js +9 -2
- package/dist/two-d/render/TintedSprite.js.map +1 -1
- package/dist/two-d/render/Types2D.d.ts +14 -2
- package/dist/two-d/render/Types2D.d.ts.map +1 -1
- package/dist/two-d/render/Types2D.js +14 -2
- package/dist/two-d/render/Types2D.js.map +1 -1
- package/dist/two-d/render/Viewport.d.ts +22 -0
- package/dist/two-d/render/Viewport.d.ts.map +1 -1
- package/dist/two-d/render/Viewport.js +22 -0
- package/dist/two-d/render/Viewport.js.map +1 -1
- package/dist/two-d/ui/Bar.d.ts +16 -3
- package/dist/two-d/ui/Bar.d.ts.map +1 -1
- package/dist/two-d/ui/Bar.js +16 -1
- package/dist/two-d/ui/Bar.js.map +1 -1
- package/dist/two-d/ui/BitmapLabel.d.ts +23 -1
- package/dist/two-d/ui/BitmapLabel.d.ts.map +1 -1
- package/dist/two-d/ui/BitmapLabel.js +23 -1
- package/dist/two-d/ui/BitmapLabel.js.map +1 -1
- package/dist/two-d/ui/Button.d.ts +15 -0
- package/dist/two-d/ui/Button.d.ts.map +1 -1
- package/dist/two-d/ui/Button.js +15 -0
- package/dist/two-d/ui/Button.js.map +1 -1
- package/dist/two-d/ui/FloatingText.d.ts +15 -0
- package/dist/two-d/ui/FloatingText.d.ts.map +1 -1
- package/dist/two-d/ui/FloatingText.js +15 -0
- package/dist/two-d/ui/FloatingText.js.map +1 -1
- package/dist/two-d/ui/HelpScreen.d.ts +16 -0
- package/dist/two-d/ui/HelpScreen.d.ts.map +1 -1
- package/dist/two-d/ui/HelpScreen.js +23 -3
- package/dist/two-d/ui/HelpScreen.js.map +1 -1
- package/dist/two-d/ui/IconGrid.d.ts +25 -0
- package/dist/two-d/ui/IconGrid.d.ts.map +1 -1
- package/dist/two-d/ui/IconGrid.js +37 -5
- package/dist/two-d/ui/IconGrid.js.map +1 -1
- package/dist/two-d/ui/Label.d.ts +10 -0
- package/dist/two-d/ui/Label.d.ts.map +1 -1
- package/dist/two-d/ui/Label.js +10 -0
- package/dist/two-d/ui/Label.js.map +1 -1
- package/dist/two-d/ui/ListView.d.ts +19 -0
- package/dist/two-d/ui/ListView.d.ts.map +1 -1
- package/dist/two-d/ui/ListView.js +19 -0
- package/dist/two-d/ui/ListView.js.map +1 -1
- package/dist/two-d/ui/LoadingScreen.d.ts +24 -1
- package/dist/two-d/ui/LoadingScreen.d.ts.map +1 -1
- package/dist/two-d/ui/LoadingScreen.js +24 -1
- package/dist/two-d/ui/LoadingScreen.js.map +1 -1
- package/dist/two-d/ui/MessageBox.d.ts +21 -2
- package/dist/two-d/ui/MessageBox.d.ts.map +1 -1
- package/dist/two-d/ui/MessageBox.js +19 -0
- package/dist/two-d/ui/MessageBox.js.map +1 -1
- package/dist/two-d/ui/NinePatch.d.ts +12 -0
- package/dist/two-d/ui/NinePatch.d.ts.map +1 -1
- package/dist/two-d/ui/NinePatch.js +12 -0
- package/dist/two-d/ui/NinePatch.js.map +1 -1
- package/dist/two-d/ui/RebindScreen.d.ts +15 -0
- package/dist/two-d/ui/RebindScreen.d.ts.map +1 -1
- package/dist/two-d/ui/RebindScreen.js +15 -0
- package/dist/two-d/ui/RebindScreen.js.map +1 -1
- package/dist/two-d/ui/StatsScreen.d.ts +15 -0
- package/dist/two-d/ui/StatsScreen.d.ts.map +1 -1
- package/dist/two-d/ui/StatsScreen.js +15 -0
- package/dist/two-d/ui/StatsScreen.js.map +1 -1
- package/dist/two-d/ui/Toast.d.ts +12 -0
- package/dist/two-d/ui/Toast.d.ts.map +1 -1
- package/dist/two-d/ui/Toast.js +12 -0
- package/dist/two-d/ui/Toast.js.map +1 -1
- package/dist/two-d/ui/Tooltip.d.ts +14 -0
- package/dist/two-d/ui/Tooltip.d.ts.map +1 -1
- package/dist/two-d/ui/Tooltip.js +14 -0
- package/dist/two-d/ui/Tooltip.js.map +1 -1
- package/dist/two-d/ui/VerticalLabel.d.ts +18 -0
- package/dist/two-d/ui/VerticalLabel.d.ts.map +1 -1
- package/dist/two-d/ui/VerticalLabel.js +18 -0
- package/dist/two-d/ui/VerticalLabel.js.map +1 -1
- package/dist/two-d/ui/Window.d.ts +12 -0
- package/dist/two-d/ui/Window.d.ts.map +1 -1
- package/dist/two-d/ui/Window.js +12 -0
- package/dist/two-d/ui/Window.js.map +1 -1
- package/dist/two-d/ui/theme.d.ts +45 -1
- package/dist/two-d/ui/theme.d.ts.map +1 -1
- package/dist/two-d/ui/theme.js +45 -1
- package/dist/two-d/ui/theme.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +8 -2
|
@@ -14,6 +14,14 @@ import { EMPTY } from './TileMap.js';
|
|
|
14
14
|
* different engine's autotile layout will need its frames reordered into this one. What is
|
|
15
15
|
* guaranteed: `BLOB_SHAPES` lists all 47 shapes in the exact order `blobIndex` returns them
|
|
16
16
|
* in, so a tool (or a person, reading it once) can draw or arrange frames against it directly.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { BLOB_SHAPES } from '@datamoc/mw_games/two-d/render';
|
|
21
|
+
*
|
|
22
|
+
* console.log(BLOB_SHAPES.length); // 47
|
|
23
|
+
* console.log(BLOB_SHAPES[0]); // { n: false, e: false, s: false, w: false, ne: false, se: false, sw: false, nw: false }
|
|
24
|
+
* ```
|
|
17
25
|
*/
|
|
18
26
|
export const BLOB_SHAPES = buildBlobShapes();
|
|
19
27
|
const blobIndexByMask = new Map(BLOB_SHAPES.map((shape, index) => [maskOf(shape), index]));
|
|
@@ -73,7 +81,20 @@ function buildBlobShapes() {
|
|
|
73
81
|
shapes.sort((a, b) => a.mask - b.mask);
|
|
74
82
|
return shapes.map((entry) => entry.shape);
|
|
75
83
|
}
|
|
76
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* the blob index (0 to 46) for one cell's 8-neighbour membership test
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { blobIndex } from '@datamoc/mw_games/two-d/render';
|
|
90
|
+
*
|
|
91
|
+
* const surroundedOnAllSides = blobIndex({
|
|
92
|
+
* n: true, e: true, s: true, w: true,
|
|
93
|
+
* ne: true, se: true, sw: true, nw: true,
|
|
94
|
+
* });
|
|
95
|
+
* console.log(surroundedOnAllSides); // 46 - the fully-interior shape
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
77
98
|
export function blobIndex(neighbors) {
|
|
78
99
|
return blobIndexByMask.get(maskOf(neighbors));
|
|
79
100
|
}
|
|
@@ -86,6 +107,17 @@ export function blobIndex(neighbors) {
|
|
|
86
107
|
* @param frames the 47 frames a `blobIndex` of 0 to 46 selects between, drawn (or arranged)
|
|
87
108
|
* against `BLOB_SHAPES`
|
|
88
109
|
* @returns one frame index per cell, row-major, `EMPTY` wherever `sameTerrain` is false
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* import { autotileFrames, BLOB_SHAPES } from '@datamoc/mw_games/two-d/render';
|
|
114
|
+
*
|
|
115
|
+
* const water = new Set([0, 1, 10, 11]); // a 2x2 pond in a wider grid
|
|
116
|
+
* const frames = Array.from({ length: BLOB_SHAPES.length }, (_, index) => index); // frame N = shape N
|
|
117
|
+
*
|
|
118
|
+
* const cellFrames = autotileFrames(10, 10, (x, y) => water.has(y * 10 + x), frames);
|
|
119
|
+
* console.log(cellFrames[0]); // the blob frame for the pond's top-left corner
|
|
120
|
+
* ```
|
|
89
121
|
*/
|
|
90
122
|
export function autotileFrames(width, height, sameTerrain, frames) {
|
|
91
123
|
if (frames.length !== BLOB_SHAPES.length) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autotile.js","sourceRoot":"","sources":["../../../src/two-d/render/Autotile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAcrC
|
|
1
|
+
{"version":3,"file":"Autotile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7,23 @@ import { Container } from 'pixi.js';
|
|
|
7
7
|
* anything that should stay put on screen (the HUD, a dialogue box) goes outside it.
|
|
8
8
|
*
|
|
9
9
|
* Positions are in world units. At `zoom = 3` a 16px tile is 48 screen pixels.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { Camera, createCamera } from '@datamoc/mw_games/two-d/render';
|
|
14
|
+
* import type { Container2D } from '@datamoc/mw_games/two-d/render';
|
|
15
|
+
*
|
|
16
|
+
* declare const stage: Container2D;
|
|
17
|
+
* declare const hero: { x: number; y: number };
|
|
18
|
+
*
|
|
19
|
+
* const camera = createCamera({ zoom: 3, deadzone: 0.3, pixelPerfectTileSize: 16 });
|
|
20
|
+
* stage.addChild(camera.world);
|
|
21
|
+
* camera.follow(hero);
|
|
22
|
+
*
|
|
23
|
+
* function onFrame(dt: number): void {
|
|
24
|
+
* camera.update(dt);
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
10
27
|
*/
|
|
11
28
|
export interface CameraOptions {
|
|
12
29
|
/** screen pixels per world unit */
|
|
@@ -33,6 +50,25 @@ export interface CameraOptions {
|
|
|
33
50
|
*/
|
|
34
51
|
pixelPerfectTileSize?: number;
|
|
35
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { Camera } from '@datamoc/mw_games/two-d/render';
|
|
57
|
+
* import type { Container2D } from '@datamoc/mw_games/two-d/render';
|
|
58
|
+
*
|
|
59
|
+
* declare const stage: Container2D;
|
|
60
|
+
*
|
|
61
|
+
* const camera = new Camera({ zoom: 2 });
|
|
62
|
+
* camera.setViewport(960, 540);
|
|
63
|
+
* stage.addChild(camera.world);
|
|
64
|
+
*
|
|
65
|
+
* camera.snapTo(160, 160); // jump to the start room, no easing
|
|
66
|
+
* camera.follow({ x: 176, y: 160 }); // then ease towards wherever the hero is
|
|
67
|
+
* camera.update(1 / 60);
|
|
68
|
+
*
|
|
69
|
+
* const screenPoint = camera.toScreen(160, 160);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
36
72
|
export declare class Camera {
|
|
37
73
|
/** put the map and everything in it here */
|
|
38
74
|
readonly world: Container<import("pixi.js").ContainerChild>;
|
|
@@ -109,8 +145,24 @@ export declare class Camera {
|
|
|
109
145
|
* The nearest zoom to `zoom` at which `tileSize * zoom` is a whole number of screen pixels -
|
|
110
146
|
* the pure math behind `CameraOptions.pixelPerfectTileSize`, exported so a game can snap a
|
|
111
147
|
* zoom value (from a slider, say) before ever handing it to a `Camera`.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* import { snapZoom } from '@datamoc/mw_games/two-d/render';
|
|
152
|
+
*
|
|
153
|
+
* console.log(snapZoom(2.4, 16)); // 2.375 - 16 * 2.375 = 38, a whole number of pixels
|
|
154
|
+
* ```
|
|
112
155
|
*/
|
|
113
156
|
export declare function snapZoom(zoom: number, tileSize: number): number;
|
|
114
|
-
/**
|
|
157
|
+
/**
|
|
158
|
+
* a camera sized to the running game's viewport, updated on every frame
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* import { createCamera } from '@datamoc/mw_games/two-d/render';
|
|
163
|
+
*
|
|
164
|
+
* const camera = createCamera({ zoom: 2 }); // sized to Game.current automatically
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
115
167
|
export declare function createCamera(options?: CameraOptions): Camera;
|
|
116
168
|
//# sourceMappingURL=Camera.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAIpC
|
|
1
|
+
{"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA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AQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,aAAkB,GAAG,MAAM,CAMhE"}
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { Container } from 'pixi.js';
|
|
2
2
|
import { Game } from '../Game.js';
|
|
3
3
|
import * as Random from '../../core/Random.js';
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { Camera } from '@datamoc/mw_games/two-d/render';
|
|
8
|
+
* import type { Container2D } from '@datamoc/mw_games/two-d/render';
|
|
9
|
+
*
|
|
10
|
+
* declare const stage: Container2D;
|
|
11
|
+
*
|
|
12
|
+
* const camera = new Camera({ zoom: 2 });
|
|
13
|
+
* camera.setViewport(960, 540);
|
|
14
|
+
* stage.addChild(camera.world);
|
|
15
|
+
*
|
|
16
|
+
* camera.snapTo(160, 160); // jump to the start room, no easing
|
|
17
|
+
* camera.follow({ x: 176, y: 160 }); // then ease towards wherever the hero is
|
|
18
|
+
* camera.update(1 / 60);
|
|
19
|
+
*
|
|
20
|
+
* const screenPoint = camera.toScreen(160, 160);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
4
23
|
export class Camera {
|
|
5
24
|
constructor(options = {}) {
|
|
6
25
|
/** put the map and everything in it here */
|
|
@@ -166,12 +185,28 @@ function clamp(value, min, max) {
|
|
|
166
185
|
* The nearest zoom to `zoom` at which `tileSize * zoom` is a whole number of screen pixels -
|
|
167
186
|
* the pure math behind `CameraOptions.pixelPerfectTileSize`, exported so a game can snap a
|
|
168
187
|
* zoom value (from a slider, say) before ever handing it to a `Camera`.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { snapZoom } from '@datamoc/mw_games/two-d/render';
|
|
192
|
+
*
|
|
193
|
+
* console.log(snapZoom(2.4, 16)); // 2.375 - 16 * 2.375 = 38, a whole number of pixels
|
|
194
|
+
* ```
|
|
169
195
|
*/
|
|
170
196
|
export function snapZoom(zoom, tileSize) {
|
|
171
197
|
const pixels = Math.max(1, Math.round(zoom * tileSize));
|
|
172
198
|
return pixels / tileSize;
|
|
173
199
|
}
|
|
174
|
-
/**
|
|
200
|
+
/**
|
|
201
|
+
* a camera sized to the running game's viewport, updated on every frame
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* import { createCamera } from '@datamoc/mw_games/two-d/render';
|
|
206
|
+
*
|
|
207
|
+
* const camera = createCamera({ zoom: 2 }); // sized to Game.current automatically
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
175
210
|
export function createCamera(options = {}) {
|
|
176
211
|
const camera = new Camera(options);
|
|
177
212
|
const game = Game.current;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Camera.js","sourceRoot":"","sources":["../../../src/two-d/render/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Camera.js","sourceRoot":"","sources":["../../../src/two-d/render/Camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,sBAAsB,CAAC;AAwD/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,MAAM;IAiClB,YAAY,OAAO,GAAkB,EAAE;QAhCvC,4CAA4C;QACnC,UAAK,GAAG,IAAI,SAAS,EAAE,CAAC;QAEjC,yCAAyC;QACzC,MAAC,GAAG,CAAC,CAAC;QACN,MAAC,GAAG,CAAC,CAAC;QAME,cAAS,GAAG,CAA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,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY,EAAE,QAAgB;IACtD,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC;IACxD,OAAO,MAAM,GAAG,QAAQ,CAAC;AAC1B,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,OAAO,GAAkB,EAAE;IACvD,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;IAC1B,iFAAiF;IACjF,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -24,6 +24,14 @@ export interface RenderingDecision {
|
|
|
24
24
|
* The framework's rendering choices by workload. This is data, not a global renderer switch:
|
|
25
25
|
* each game imports only the module it uses and keeps 2D Pixi and optional 3D Babylon paths
|
|
26
26
|
* independent.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { RENDERING_DECISIONS } from '@datamoc/mw_games/two-d/render';
|
|
31
|
+
*
|
|
32
|
+
* const particles = RENDERING_DECISIONS.find((d) => d.workload === 'particles');
|
|
33
|
+
* console.log(particles?.preferred); // 'PixiJS for 2D, Babylon.js for 3D'
|
|
34
|
+
* ```
|
|
27
35
|
*/
|
|
28
36
|
export declare const RENDERING_DECISIONS: readonly RenderingDecision[];
|
|
29
37
|
/**
|
|
@@ -35,6 +43,22 @@ export declare const RENDERING_DECISIONS: readonly RenderingDecision[];
|
|
|
35
43
|
* of that is asynchronous. Rather than assume WGSL works just because `navigator.gpu`
|
|
36
44
|
* exists (a browser can expose WebGPU behind a still-broken or disabled implementation),
|
|
37
45
|
* this stays `false` unless a caller supplies a real result through `probe.wgsl`.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { inspectGraphicsCapabilities } from '@datamoc/mw_games/two-d/render';
|
|
50
|
+
*
|
|
51
|
+
* // reads the real browser when no probe is given
|
|
52
|
+
* const here = inspectGraphicsCapabilities();
|
|
53
|
+
*
|
|
54
|
+
* // a fake probe, for a test or a host integration with no DOM
|
|
55
|
+
* const capabilities = inspectGraphicsCapabilities({
|
|
56
|
+
* createCanvas: () => ({ getContext: (kind) => (kind === 'webgl2' ? {} : null) }),
|
|
57
|
+
* webgpu: false,
|
|
58
|
+
* });
|
|
59
|
+
* console.log(capabilities.webgl2); // true
|
|
60
|
+
* console.log(capabilities.webgpu); // false
|
|
61
|
+
* ```
|
|
38
62
|
*/
|
|
39
63
|
export declare function inspectGraphicsCapabilities(probe?: GraphicsProbe): GraphicsCapabilities;
|
|
40
64
|
export interface WebGpuDetection {
|
|
@@ -46,6 +70,15 @@ export interface WebGpuDetection {
|
|
|
46
70
|
* synchronously: requests an actual adapter and device, then compiles an actual shader
|
|
47
71
|
* module and reads back its compilation diagnostics. Feed the result to
|
|
48
72
|
* `inspectGraphicsCapabilities` via `probe.webgpu`/`probe.wgsl` once resolved.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { detectWebGpu, inspectGraphicsCapabilities } from '@datamoc/mw_games/two-d/render';
|
|
77
|
+
*
|
|
78
|
+
* const detected = await detectWebGpu();
|
|
79
|
+
* const capabilities = inspectGraphicsCapabilities({ webgpu: detected.webgpu, wgsl: detected.wgsl });
|
|
80
|
+
* console.log(capabilities.wgsl); // true only if a real WGSL shader actually compiled
|
|
81
|
+
* ```
|
|
49
82
|
*/
|
|
50
83
|
export declare function detectWebGpu(): Promise<WebGpuDetection>;
|
|
51
84
|
//# sourceMappingURL=Capabilities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Capabilities.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACzB,SAAS,GACT,IAAI,GACJ,gBAAgB,GAChB,WAAW,GACX,mBAAmB,GACnB,QAAQ,GACR,iBAAiB,GACjB,iBAAiB,CAAC;AAErB,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,oEAAoE;IACpE,IAAI,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC7B,YAAY,CAAC,IAAI;QAAE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0FAA0F;IAC1F,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CACf;AAED
|
|
1
|
+
{"version":3,"file":"Capabilities.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/Capabilities.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GACzB,SAAS,GACT,IAAI,GACJ,gBAAgB,GAChB,WAAW,GACX,mBAAmB,GACnB,QAAQ,GACR,iBAAiB,GACjB,iBAAiB,CAAC;AAErB,MAAM,WAAW,oBAAoB;IACpC,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,oEAAoE;IACpE,IAAI,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,aAAa;IAC7B,YAAY,CAAC,IAAI;QAAE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9D,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,0FAA0F;IAC1F,IAAI,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IACjC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,mBAAmB,EAAE,SAAS,iBAAiB,EAS3D,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,GAAE,aAAkB,GAAG,oBAAoB,CAM3F;AAED,MAAM,WAAW,eAAe;IAC/B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACd;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,CAe7D"}
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
* The framework's rendering choices by workload. This is data, not a global renderer switch:
|
|
3
3
|
* each game imports only the module it uses and keeps 2D Pixi and optional 3D Babylon paths
|
|
4
4
|
* independent.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { RENDERING_DECISIONS } from '@datamoc/mw_games/two-d/render';
|
|
9
|
+
*
|
|
10
|
+
* const particles = RENDERING_DECISIONS.find((d) => d.workload === 'particles');
|
|
11
|
+
* console.log(particles?.preferred); // 'PixiJS for 2D, Babylon.js for 3D'
|
|
12
|
+
* ```
|
|
5
13
|
*/
|
|
6
14
|
export const RENDERING_DECISIONS = [
|
|
7
15
|
{ workload: 'sprites', preferred: 'PixiJS WebGL/WebGPU batcher', fallback: 'PixiJS WebGL', reason: 'high-volume textured 2D batches' },
|
|
@@ -22,6 +30,22 @@ export const RENDERING_DECISIONS = [
|
|
|
22
30
|
* of that is asynchronous. Rather than assume WGSL works just because `navigator.gpu`
|
|
23
31
|
* exists (a browser can expose WebGPU behind a still-broken or disabled implementation),
|
|
24
32
|
* this stays `false` unless a caller supplies a real result through `probe.wgsl`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { inspectGraphicsCapabilities } from '@datamoc/mw_games/two-d/render';
|
|
37
|
+
*
|
|
38
|
+
* // reads the real browser when no probe is given
|
|
39
|
+
* const here = inspectGraphicsCapabilities();
|
|
40
|
+
*
|
|
41
|
+
* // a fake probe, for a test or a host integration with no DOM
|
|
42
|
+
* const capabilities = inspectGraphicsCapabilities({
|
|
43
|
+
* createCanvas: () => ({ getContext: (kind) => (kind === 'webgl2' ? {} : null) }),
|
|
44
|
+
* webgpu: false,
|
|
45
|
+
* });
|
|
46
|
+
* console.log(capabilities.webgl2); // true
|
|
47
|
+
* console.log(capabilities.webgpu); // false
|
|
48
|
+
* ```
|
|
25
49
|
*/
|
|
26
50
|
export function inspectGraphicsCapabilities(probe = {}) {
|
|
27
51
|
const canvas = probe.createCanvas?.() ?? (typeof document === 'undefined' ? null : document.createElement('canvas'));
|
|
@@ -35,6 +59,15 @@ export function inspectGraphicsCapabilities(probe = {}) {
|
|
|
35
59
|
* synchronously: requests an actual adapter and device, then compiles an actual shader
|
|
36
60
|
* module and reads back its compilation diagnostics. Feed the result to
|
|
37
61
|
* `inspectGraphicsCapabilities` via `probe.webgpu`/`probe.wgsl` once resolved.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { detectWebGpu, inspectGraphicsCapabilities } from '@datamoc/mw_games/two-d/render';
|
|
66
|
+
*
|
|
67
|
+
* const detected = await detectWebGpu();
|
|
68
|
+
* const capabilities = inspectGraphicsCapabilities({ webgpu: detected.webgpu, wgsl: detected.wgsl });
|
|
69
|
+
* console.log(capabilities.wgsl); // true only if a real WGSL shader actually compiled
|
|
70
|
+
* ```
|
|
38
71
|
*/
|
|
39
72
|
export async function detectWebGpu() {
|
|
40
73
|
const gpu = globalThis.navigator?.gpu;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Capabilities.js","sourceRoot":"","sources":["../../../src/two-d/render/Capabilities.ts"],"names":[],"mappings":"AAgCA
|
|
1
|
+
{"version":3,"file":"Capabilities.js","sourceRoot":"","sources":["../../../src/two-d/render/Capabilities.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiC;IAChE,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,6BAA6B,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,EAAE,iCAAiC,EAAE;IACtI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,qBAAqB,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,EAAE,8BAA8B,EAAE;IAC7H,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,+CAA+C,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,iEAAiE,EAAE;IACjM,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,kCAAkC,EAAE,QAAQ,EAAE,0BAA0B,EAAE,MAAM,EAAE,yCAAyC,EAAE;IACjK,EAAE,QAAQ,EAAE,mBAAmB,EAAE,SAAS,EAAE,2BAA2B,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,EAAE,mCAAmC,EAAE;IACzJ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,2BAA2B,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,EAAE,yBAAyB,EAAE;IAC7H,EAAE,QAAQ,EAAE,iBA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AC,cAAc,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,aAAa,EAAE,CAAC;QAC9C,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;QAEnD,MAAM,MAAM,GAAG,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,0CAA0C,EAAE,CAAC,CAAC;QAC/F,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,kBAAkB,EAAE,CAAC;QAC/C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACvC,CAAC;AACF,CAAC"}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { ColorMatrixFilter } from 'pixi.js';
|
|
2
2
|
import type { ColorMatrix } from 'pixi.js';
|
|
3
3
|
export type ColorBlindnessType = 'protanopia' | 'deuteranopia' | 'tritanopia';
|
|
4
|
+
/**
|
|
5
|
+
* Brettel/Viénot-derived simulation matrices, the same values widely used by colourblindness
|
|
6
|
+
* simulators - a 5x4 (20-value) row-major RGBA matrix, Pixi's own `ColorMatrixFilter` format.
|
|
7
|
+
* Exported so the matrix data itself can be tested without constructing a `ColorMatrixFilter`,
|
|
8
|
+
* which (like `BitmapText`) needs a real WebGL context even to construct.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { COLOR_BLINDNESS_MATRICES } from '@datamoc/mw_games/two-d/render';
|
|
13
|
+
*
|
|
14
|
+
* console.log(COLOR_BLINDNESS_MATRICES.deuteranopia.length); // 20
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
4
17
|
export declare const COLOR_BLINDNESS_MATRICES: Record<ColorBlindnessType, ColorMatrix>;
|
|
5
18
|
/**
|
|
6
19
|
* A whole-scene filter simulating one of the three common types of colour vision deficiency.
|
|
@@ -11,6 +24,16 @@ export declare const COLOR_BLINDNESS_MATRICES: Record<ColorBlindnessType, ColorM
|
|
|
11
24
|
* first step toward choosing a palette that reads clearly for them. It does not correct an
|
|
12
25
|
* existing palette automatically; that would need the source colours' own intent (which one
|
|
13
26
|
* is the "danger" colour, say), not just their RGB values.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { createColorBlindnessFilter } from '@datamoc/mw_games/two-d/render';
|
|
31
|
+
* import type { Container2D } from '@datamoc/mw_games/two-d/render';
|
|
32
|
+
*
|
|
33
|
+
* declare const stage: Container2D;
|
|
34
|
+
*
|
|
35
|
+
* stage.filters = [createColorBlindnessFilter('deuteranopia')];
|
|
36
|
+
* ```
|
|
14
37
|
*/
|
|
15
38
|
export declare function createColorBlindnessFilter(type: ColorBlindnessType): ColorMatrixFilter;
|
|
16
39
|
//# sourceMappingURL=ColorBlindness.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorBlindness.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/ColorBlindness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,cAAc,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ColorBlindness.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/ColorBlindness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,cAAc,GAAG,YAAY,CAAC;AAE9E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,kBAAkB,EAAE,WAAW,CAmB5E,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,kBAAkB,GAAG,iBAAiB,CAItF"}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { ColorMatrixFilter } from 'pixi.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Brettel/Viénot-derived simulation matrices, the same values widely used by colourblindness
|
|
4
|
+
* simulators - a 5x4 (20-value) row-major RGBA matrix, Pixi's own `ColorMatrixFilter` format.
|
|
5
|
+
* Exported so the matrix data itself can be tested without constructing a `ColorMatrixFilter`,
|
|
6
|
+
* which (like `BitmapText`) needs a real WebGL context even to construct.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { COLOR_BLINDNESS_MATRICES } from '@datamoc/mw_games/two-d/render';
|
|
11
|
+
*
|
|
12
|
+
* console.log(COLOR_BLINDNESS_MATRICES.deuteranopia.length); // 20
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
6
15
|
export const COLOR_BLINDNESS_MATRICES = {
|
|
7
16
|
protanopia: [
|
|
8
17
|
0.567, 0.433, 0, 0, 0,
|
|
@@ -32,6 +41,16 @@ export const COLOR_BLINDNESS_MATRICES = {
|
|
|
32
41
|
* first step toward choosing a palette that reads clearly for them. It does not correct an
|
|
33
42
|
* existing palette automatically; that would need the source colours' own intent (which one
|
|
34
43
|
* is the "danger" colour, say), not just their RGB values.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { createColorBlindnessFilter } from '@datamoc/mw_games/two-d/render';
|
|
48
|
+
* import type { Container2D } from '@datamoc/mw_games/two-d/render';
|
|
49
|
+
*
|
|
50
|
+
* declare const stage: Container2D;
|
|
51
|
+
*
|
|
52
|
+
* stage.filters = [createColorBlindnessFilter('deuteranopia')];
|
|
53
|
+
* ```
|
|
35
54
|
*/
|
|
36
55
|
export function createColorBlindnessFilter(type) {
|
|
37
56
|
const filter = new ColorMatrixFilter();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorBlindness.js","sourceRoot":"","sources":["../../../src/two-d/render/ColorBlindness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAK5C
|
|
1
|
+
{"version":3,"file":"ColorBlindness.js","sourceRoot":"","sources":["../../../src/two-d/render/ColorBlindness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAK5C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAA4C;IAChF,UAAU,EAAE;QACX,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACrB,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACrB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACrB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KACb;IACD,YAAY,EAAE;QACb,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACrB,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACjB,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;QACjB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KACb;IACD,UAAU,EAAE;QACX,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QACnB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACrB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QACrB,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;KACb;CACD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAwB;IAClE,MAAM,MAAM,GAAG,IAAI,iBAAiB,EAAE,CAAC;IACvC,MAAM,CAAC,MAAM,GAAG,wBAAwB,CAAC,IAAI,CAAC,CAAC;IAC/C,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -19,11 +19,34 @@ type QuadElement = BatchableQuadElement & PackedElement;
|
|
|
19
19
|
*
|
|
20
20
|
* Anything drawn through this batcher may set `colorAdd` on itself; anything that does not
|
|
21
21
|
* is packed with zero and renders exactly as it would have with the default batcher.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import type { HasColorAdd } from '@datamoc/mw_games/two-d/render';
|
|
26
|
+
* import { packColorAdd } from '@datamoc/mw_games/two-d/render';
|
|
27
|
+
*
|
|
28
|
+
* function tintTowardsWhite(renderable: HasColorAdd, strength: number): void {
|
|
29
|
+
* renderable.colorAdd = packColorAdd(strength, strength, strength);
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
22
32
|
*/
|
|
23
33
|
export interface HasColorAdd {
|
|
24
34
|
/** additive colour, packed as 0xAABBGGRR to match the attribute's byte order */
|
|
25
35
|
colorAdd?: number;
|
|
26
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The Pixi batcher extension `TintedSprite` (and everything built on it) renders through -
|
|
39
|
+
* see the module doc comment above for what it adds and why.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { ColorTransformBatcher } from '@datamoc/mw_games/two-d/render';
|
|
44
|
+
*
|
|
45
|
+
* // registered automatically by TintedSprite.ts; naming the class directly is only ever
|
|
46
|
+
* // needed to check which batcher an object ended up in, or in Pixi extension diagnostics
|
|
47
|
+
* console.log(ColorTransformBatcher.extension.name); // 'mwg-color-transform'
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
27
50
|
export declare class ColorTransformBatcher extends Batcher {
|
|
28
51
|
/** @internal */
|
|
29
52
|
static extension: {
|
|
@@ -53,6 +76,17 @@ export declare const TINTED_SPRITE_PIPE = "mwg-tinted-sprite";
|
|
|
53
76
|
* `GameOptions.extensions` itself. This stays exported, idempotent (`registered` guards a
|
|
54
77
|
* second call from double-adding it), and public for the rare case of a game building its
|
|
55
78
|
* own renderer setup outside `Game`.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { registerColorTransform } from '@datamoc/mw_games/two-d/render';
|
|
83
|
+
*
|
|
84
|
+
* // a game that assembles its own Pixi renderer extensions manually, instead of going
|
|
85
|
+
* // through `Game`/`GameOptions.extensions`, registers the batcher itself before creating
|
|
86
|
+
* // that renderer - importing `TintedSprite` (directly or transitively) already does this,
|
|
87
|
+
* // so most games never call it
|
|
88
|
+
* registerColorTransform();
|
|
89
|
+
* ```
|
|
56
90
|
*/
|
|
57
91
|
export declare function registerColorTransform(): void;
|
|
58
92
|
/**
|
|
@@ -62,10 +96,42 @@ export declare function registerColorTransform(): void;
|
|
|
62
96
|
* @param g green, 0 to 1
|
|
63
97
|
* @param b blue, 0 to 1
|
|
64
98
|
* @param a how much to add to the sprite's own alpha, 0 to 1; usually 0
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* import { packColorAdd } from '@datamoc/mw_games/two-d/render';
|
|
103
|
+
* import { TintedSprite } from '@datamoc/mw_games/two-d/render';
|
|
104
|
+
*
|
|
105
|
+
* declare const rat: TintedSprite;
|
|
106
|
+
*
|
|
107
|
+
* rat.colorAdd = packColorAdd(0, 1, 0); // pull the sprite towards pure green
|
|
108
|
+
* ```
|
|
65
109
|
*/
|
|
66
110
|
export declare function packColorAdd(r: number, g: number, b: number, a?: number): number;
|
|
67
|
-
/** the additive half of `lerp(texel, colour, strength)`; pair with a tint of `1 - strength`
|
|
111
|
+
/** the additive half of `lerp(texel, colour, strength)`; pair with a tint of `1 - strength`
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* import { packTintAdd, TintedSprite } from '@datamoc/mw_games/two-d/render';
|
|
116
|
+
*
|
|
117
|
+
* declare const rat: TintedSprite;
|
|
118
|
+
*
|
|
119
|
+
* rat.colorAdd = packTintAdd(0x00ff00, 0.5); // half-way to green, the additive half of lerpTint
|
|
120
|
+
* rat.tint = 0x808080; // pair with 1 - strength (here 0.5) for the multiply half
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
68
123
|
export declare function packTintAdd(color: number, strength: number): number;
|
|
124
|
+
/** the packed value of no additive colour at all - what an untinted sprite carries.
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { NO_COLOR_ADD, TintedSprite } from '@datamoc/mw_games/two-d/render';
|
|
129
|
+
*
|
|
130
|
+
* declare const rat: TintedSprite;
|
|
131
|
+
*
|
|
132
|
+
* console.log(rat.colorAdd === NO_COLOR_ADD); // true - fresh sprites start with no additive colour
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
69
135
|
export declare const NO_COLOR_ADD = 0;
|
|
70
136
|
export {};
|
|
71
137
|
//# sourceMappingURL=ColorTransformBatcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ColorTransformBatcher.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/ColorTransformBatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EAGP,aAAa,EACb,QAAQ,EACR,MAAM,EAWN,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACX,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,MAAM,EAKN,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,UAAU,aAAa;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,WAAW,GAAG,oBAAoB,GAAG,aAAa,CAAC;AACxD,KAAK,WAAW,GAAG,oBAAoB,GAAG,aAAa,CAAC;AA6HxD
|
|
1
|
+
{"version":3,"file":"ColorTransformBatcher.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/ColorTransformBatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,OAAO,EAGP,aAAa,EACb,QAAQ,EACR,MAAM,EAWN,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EACX,oBAAoB,EACpB,oBAAoB,EACpB,cAAc,EACd,MAAM,EAKN,MAAM,SAAS,CAAC;AAEjB;;;;;GAKG;AACH,UAAU,aAAa;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,KAAK,WAAW,GAAG,oBAAoB,GAAG,aAAa,CAAC;AACxD,KAAK,WAAW,GAAG,oBAAoB,GAAG,aAAa,CAAC;AA6HxD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,WAAW;IAC3B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAmCD;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAsB,SAAQ,OAAO;IACjD,gBAAgB;IAChB,MAAM,CAAC,SAAS;iBACf,IAAI;iBACJ,IAAI,EAAE,qBAAqB;MACjB;IAEX,QAAQ,EAAE,QAAQ,CAAgC;IAClD,MAAM,EAAE,MAAM,CAAC;IACN,IAAI,wBAAwC;IAC5C,UAAU,SAAe;IAElC,YAAY,OAAO,EAAE,cAAc,EAGlC;IAED,cAAc,CACb,OAAO,EAAE,WA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