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;