Skip to content

Commit a418b9f

Browse files
committed
Export EffectDesc and related types to users
1 parent 316532d commit a418b9f

File tree

4 files changed

+65
-62
lines changed

4 files changed

+65
-62
lines changed

src/core/renderers/webgl/shaders/DynamicShader.ts

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
* See the License for the specific language governing permissions and
1717
* limitations under the License.
1818
*/
19-
import type { ExtractProps } from '../../../CoreTextureManager.js';
2019
import type { WebGlCoreRenderer } from '../WebGlCoreRenderer.js';
2120
import {
2221
WebGlCoreShader,
@@ -27,70 +26,14 @@ import type { UniformInfo } from '../internal/ShaderUtils.js';
2726
import type { WebGlCoreCtxTexture } from '../WebGlCoreCtxTexture.js';
2827
import {
2928
ShaderEffect,
29+
type EffectDescUnion,
3030
type ShaderEffectUniform,
3131
type ShaderEffectValueMap,
32+
type BaseEffectDesc,
3233
} from './effects/ShaderEffect.js';
3334
import type { EffectMap } from '../../../CoreShaderManager.js';
3435
import { assertTruthy } from '../../../../utils.js';
3536

36-
export interface BaseEffectDesc {
37-
name?: string;
38-
type: keyof EffectMap;
39-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40-
props: Record<string, any>;
41-
}
42-
43-
export interface EffectDesc<
44-
T extends { name?: string; type: keyof EffectMap } = {
45-
name?: string;
46-
type: keyof EffectMap;
47-
},
48-
> extends BaseEffectDesc {
49-
name?: T['name'];
50-
type: T['type'];
51-
props: ExtractProps<EffectMap[T['type']]>;
52-
}
53-
54-
/**
55-
* Allows the `keyof EffectMap` to be mapped over and form an discriminated
56-
* union of all the EffectDescs structures individually.
57-
*
58-
* @remarks
59-
* When used like the following:
60-
* ```
61-
* MapEffectDescs<keyof EffectMap>[]
62-
* ```
63-
* The resultant type will be a discriminated union like so:
64-
* ```
65-
* (
66-
* {
67-
* name: 'effect1',
68-
* type: 'radius',
69-
* props?: {
70-
* radius?: number | number[];
71-
* }
72-
* } |
73-
* {
74-
* name: 'effect2',
75-
* type: 'border',
76-
* props?: {
77-
* width?: number;
78-
* color?: number;
79-
* }
80-
* } |
81-
* // ...
82-
* )[]
83-
* ```
84-
* Which means TypeScript will now base its type checking on the `type` field
85-
* and will know exactly what the `props` field should be based on the `type`
86-
* field.
87-
*/
88-
type MapEffectDescs<T extends keyof EffectMap> = T extends keyof EffectMap
89-
? EffectDesc<{ type: T; name: string }>
90-
: never;
91-
92-
export type EffectDescUnion = MapEffectDescs<keyof EffectMap>;
93-
9437
export interface DynamicShaderProps
9538
extends DimensionsShaderProp,
9639
AlphaShaderProp {

src/core/renderers/webgl/shaders/effects/ShaderEffect.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { EffectMap } from '../../../../CoreShaderManager.js';
2+
import type { ExtractProps } from '../../../../CoreTextureManager.js';
13
import type {
24
AlphaShaderProp,
35
DimensionsShaderProp,
@@ -7,6 +9,64 @@ import type {
79
UniformMethodMap,
810
} from '../../internal/ShaderUtils.js';
911

12+
export interface BaseEffectDesc {
13+
name?: string;
14+
type: keyof EffectMap;
15+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16+
props: Record<string, any>;
17+
}
18+
19+
export interface EffectDesc<
20+
T extends { name?: string; type: keyof EffectMap } = {
21+
name?: string;
22+
type: keyof EffectMap;
23+
},
24+
> extends BaseEffectDesc {
25+
name?: T['name'];
26+
type: T['type'];
27+
props: ExtractProps<EffectMap[T['type']]>;
28+
}
29+
30+
/**
31+
* Allows the `keyof EffectMap` to be mapped over and form an discriminated
32+
* union of all the EffectDescs structures individually.
33+
*
34+
* @remarks
35+
* When used like the following:
36+
* ```
37+
* MapEffectDescs<keyof EffectMap>[]
38+
* ```
39+
* The resultant type will be a discriminated union like so:
40+
* ```
41+
* (
42+
* {
43+
* name: 'effect1',
44+
* type: 'radius',
45+
* props?: {
46+
* radius?: number | number[];
47+
* }
48+
* } |
49+
* {
50+
* name: 'effect2',
51+
* type: 'border',
52+
* props?: {
53+
* width?: number;
54+
* color?: number;
55+
* }
56+
* } |
57+
* // ...
58+
* )[]
59+
* ```
60+
* Which means TypeScript will now base its type checking on the `type` field
61+
* and will know exactly what the `props` field should be based on the `type`
62+
* field.
63+
*/
64+
type MapEffectDescs<T extends keyof EffectMap> = T extends keyof EffectMap
65+
? EffectDesc<{ type: T; name: string }>
66+
: never;
67+
68+
export type EffectDescUnion = MapEffectDescs<keyof EffectMap>;
69+
1070
export interface ShaderEffectUniform {
1171
value: number | number[] | boolean | string;
1272
type: string;

src/main-api/DynamicShaderController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
ShaderMap,
66
} from '../core/CoreShaderManager.js';
77
import type { ExtractProps } from '../core/CoreTextureManager.js';
8-
import type { EffectDesc } from '../core/renderers/webgl/shaders/DynamicShader.js';
8+
import type { EffectDesc } from '../core/renderers/webgl/shaders/effects/ShaderEffect.js';
99
import type { BaseShaderController } from './ShaderController.js';
1010

1111
type OptionalName<T> = T extends string ? T : never;

src/main-api/Renderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { Inspector } from './Inspector.js';
2929
import { assertTruthy, isProductionEnvironment } from '../utils.js';
3030
import { Stage } from '../core/Stage.js';
3131
import { CoreNode, type CoreNodeProps } from '../core/CoreNode.js';
32-
import { CoreTextNode, type CoreTextNodeProps } from '../core/CoreTextNode.js';
32+
import { type CoreTextNodeProps } from '../core/CoreTextNode.js';
3333
import type {
3434
BaseShaderController,
3535
ShaderController,
@@ -42,7 +42,7 @@ import type {
4242
import type {
4343
EffectDesc,
4444
EffectDescUnion,
45-
} from '../core/renderers/webgl/shaders/DynamicShader.js';
45+
} from '../core/renderers/webgl/shaders/effects/ShaderEffect.js';
4646
import type { TextureMemoryManagerSettings } from '../core/TextureMemoryManager.js';
4747

4848
/**

0 commit comments

Comments
 (0)