From a418b9f46487ac9c6cd36505499d3fc492706e13 Mon Sep 17 00:00:00 2001 From: Frank Weindel <6070611+frank-weindel@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:43:59 -0400 Subject: [PATCH] Export EffectDesc and related types to users --- .../renderers/webgl/shaders/DynamicShader.ts | 61 +------------------ .../webgl/shaders/effects/ShaderEffect.ts | 60 ++++++++++++++++++ src/main-api/DynamicShaderController.ts | 2 +- src/main-api/Renderer.ts | 4 +- 4 files changed, 65 insertions(+), 62 deletions(-) diff --git a/src/core/renderers/webgl/shaders/DynamicShader.ts b/src/core/renderers/webgl/shaders/DynamicShader.ts index 66ef61ca..47bfa2ca 100644 --- a/src/core/renderers/webgl/shaders/DynamicShader.ts +++ b/src/core/renderers/webgl/shaders/DynamicShader.ts @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import type { ExtractProps } from '../../../CoreTextureManager.js'; import type { WebGlCoreRenderer } from '../WebGlCoreRenderer.js'; import { WebGlCoreShader, @@ -27,70 +26,14 @@ import type { UniformInfo } from '../internal/ShaderUtils.js'; import type { WebGlCoreCtxTexture } from '../WebGlCoreCtxTexture.js'; import { ShaderEffect, + type EffectDescUnion, type ShaderEffectUniform, type ShaderEffectValueMap, + type BaseEffectDesc, } from './effects/ShaderEffect.js'; import type { EffectMap } from '../../../CoreShaderManager.js'; import { assertTruthy } from '../../../../utils.js'; -export interface BaseEffectDesc { - name?: string; - type: keyof EffectMap; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - props: Record; -} - -export interface EffectDesc< - T extends { name?: string; type: keyof EffectMap } = { - name?: string; - type: keyof EffectMap; - }, -> extends BaseEffectDesc { - name?: T['name']; - type: T['type']; - props: ExtractProps; -} - -/** - * Allows the `keyof EffectMap` to be mapped over and form an discriminated - * union of all the EffectDescs structures individually. - * - * @remarks - * When used like the following: - * ``` - * MapEffectDescs[] - * ``` - * The resultant type will be a discriminated union like so: - * ``` - * ( - * { - * name: 'effect1', - * type: 'radius', - * props?: { - * radius?: number | number[]; - * } - * } | - * { - * name: 'effect2', - * type: 'border', - * props?: { - * width?: number; - * color?: number; - * } - * } | - * // ... - * )[] - * ``` - * Which means TypeScript will now base its type checking on the `type` field - * and will know exactly what the `props` field should be based on the `type` - * field. - */ -type MapEffectDescs = T extends keyof EffectMap - ? EffectDesc<{ type: T; name: string }> - : never; - -export type EffectDescUnion = MapEffectDescs; - export interface DynamicShaderProps extends DimensionsShaderProp, AlphaShaderProp { diff --git a/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts b/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts index b61872b7..8cb18fc0 100644 --- a/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts +++ b/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts @@ -1,3 +1,5 @@ +import type { EffectMap } from '../../../../CoreShaderManager.js'; +import type { ExtractProps } from '../../../../CoreTextureManager.js'; import type { AlphaShaderProp, DimensionsShaderProp, @@ -7,6 +9,64 @@ import type { UniformMethodMap, } from '../../internal/ShaderUtils.js'; +export interface BaseEffectDesc { + name?: string; + type: keyof EffectMap; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + props: Record; +} + +export interface EffectDesc< + T extends { name?: string; type: keyof EffectMap } = { + name?: string; + type: keyof EffectMap; + }, +> extends BaseEffectDesc { + name?: T['name']; + type: T['type']; + props: ExtractProps; +} + +/** + * Allows the `keyof EffectMap` to be mapped over and form an discriminated + * union of all the EffectDescs structures individually. + * + * @remarks + * When used like the following: + * ``` + * MapEffectDescs[] + * ``` + * The resultant type will be a discriminated union like so: + * ``` + * ( + * { + * name: 'effect1', + * type: 'radius', + * props?: { + * radius?: number | number[]; + * } + * } | + * { + * name: 'effect2', + * type: 'border', + * props?: { + * width?: number; + * color?: number; + * } + * } | + * // ... + * )[] + * ``` + * Which means TypeScript will now base its type checking on the `type` field + * and will know exactly what the `props` field should be based on the `type` + * field. + */ +type MapEffectDescs = T extends keyof EffectMap + ? EffectDesc<{ type: T; name: string }> + : never; + +export type EffectDescUnion = MapEffectDescs; + export interface ShaderEffectUniform { value: number | number[] | boolean | string; type: string; diff --git a/src/main-api/DynamicShaderController.ts b/src/main-api/DynamicShaderController.ts index 413bc260..2e0686d0 100644 --- a/src/main-api/DynamicShaderController.ts +++ b/src/main-api/DynamicShaderController.ts @@ -5,7 +5,7 @@ import type { ShaderMap, } from '../core/CoreShaderManager.js'; import type { ExtractProps } from '../core/CoreTextureManager.js'; -import type { EffectDesc } from '../core/renderers/webgl/shaders/DynamicShader.js'; +import type { EffectDesc } from '../core/renderers/webgl/shaders/effects/ShaderEffect.js'; import type { BaseShaderController } from './ShaderController.js'; type OptionalName = T extends string ? T : never; diff --git a/src/main-api/Renderer.ts b/src/main-api/Renderer.ts index 68ac2e37..22d8427e 100644 --- a/src/main-api/Renderer.ts +++ b/src/main-api/Renderer.ts @@ -29,7 +29,7 @@ import { Inspector } from './Inspector.js'; import { assertTruthy, isProductionEnvironment } from '../utils.js'; import { Stage } from '../core/Stage.js'; import { CoreNode, type CoreNodeProps } from '../core/CoreNode.js'; -import { CoreTextNode, type CoreTextNodeProps } from '../core/CoreTextNode.js'; +import { type CoreTextNodeProps } from '../core/CoreTextNode.js'; import type { BaseShaderController, ShaderController, @@ -42,7 +42,7 @@ import type { import type { EffectDesc, EffectDescUnion, -} from '../core/renderers/webgl/shaders/DynamicShader.js'; +} from '../core/renderers/webgl/shaders/effects/ShaderEffect.js'; import type { TextureMemoryManagerSettings } from '../core/TextureMemoryManager.js'; /**