From fcfaa83b176f8ef19fd19c56097be589b91e3641 Mon Sep 17 00:00:00 2001 From: bbazukun123 Date: Wed, 14 Feb 2024 19:44:39 +0000 Subject: [PATCH] Chore: ShockwaveFilter deprecate non-options constructor (#435) * Chore: Shockwave Filter Deprecations * Cleanup * Address Feedback --------- Co-authored-by: Baz Utsahajit --- src/shockwave/ShockwaveFilter.ts | 52 ++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/src/shockwave/ShockwaveFilter.ts b/src/shockwave/ShockwaveFilter.ts index a8c0a6688..d405ab308 100644 --- a/src/shockwave/ShockwaveFilter.ts +++ b/src/shockwave/ShockwaveFilter.ts @@ -1,4 +1,5 @@ import { + deprecation, Filter, FilterSystem, GlProgram, @@ -6,7 +7,6 @@ import { PointData, RenderSurface, Texture, - UniformGroup, } from 'pixi.js'; import { vertex, wgslVertex } from '../defaults'; import fragment from './shockwave.frag'; @@ -44,6 +44,11 @@ export interface ShockwaveFilterOptions * @default -1 */ radius?: number; + /** + * Sets the elapsed time of the shockwave. + * @default 0 + */ + time?: number; } /** @@ -83,8 +88,35 @@ export class ShockwaveFilter extends Filter /** * @param options */ - constructor(options?: ShockwaveFilterOptions) + constructor(options?: ShockwaveFilterOptions); + /** + * @deprecated since 6.0.0 + * + * @param {PIXI.PointData|number[]} [center=[0.5, 0.5]] - See `center` property. + * @param {object} [options] - The optional parameters of shockwave filter. + * @param {number} [options.amplitude=0.5] - See `amplitude`` property. + * @param {number} [options.wavelength=1.0] - See `wavelength` property. + * @param {number} [options.speed=500.0] - See `speed` property. + * @param {number} [options.brightness=8] - See `brightness` property. + * @param {number} [options.radius=4] - See `radius` property. + * @param {number} [time=0] - See `time` property. + */ + constructor(center?: PointData | number[], options?: Omit, time?: number); + // eslint-disable-next-line max-len + constructor(...args: [ShockwaveFilterOptions?] | [(PointData | number[])?, Omit?, number?]) { + let options = args[0] ?? {}; + + if (Array.isArray(options) || ('x' in options && 'y' in options)) + { + // eslint-disable-next-line max-len + deprecation('6.0.0', 'ShockwaveFilter constructor params are now options object. See params: { center, speed, amplitude, wavelength, brightness, radius, time }'); + + options = { center: options, ...args[1] } as ShockwaveFilterOptions; + + if (args[2] !== undefined) options.time = args[2]; + } + options = { ...ShockwaveFilter.DEFAULT_OPTIONS, ...options }; const gpuProgram = GpuProgram.from({ @@ -108,12 +140,12 @@ export class ShockwaveFilter extends Filter gpuProgram, glProgram, resources: { - shockwaveUniforms: new UniformGroup({ - uTime: { value: 0, type: 'f32' }, + shockwaveUniforms: { + uTime: { value: options.time, type: 'f32' }, uCenter: { value: options.center, type: 'vec2' }, uSpeed: { value: options.speed, type: 'f32' }, uWave: { value: new Float32Array(4), type: 'vec4' }, - }) + }, }, }); @@ -143,7 +175,15 @@ export class ShockwaveFilter extends Filter * @default [0,0] */ get center(): PointData { return this.uniforms.uCenter; } - set center(value: PointData) { this.uniforms.uCenter = value; } + set center(value: PointData | number[]) + { + if (Array.isArray(value)) + { + value = { x: value[0], y: value[1] }; + } + + this.uniforms.uCenter = value; + } /** * Sets the center of the effect in normalized screen coords on the `x` axis