Skip to content

Commit fcfaa83

Browse files
authored
Chore: ShockwaveFilter deprecate non-options constructor (#435)
* Chore: Shockwave Filter Deprecations * Cleanup * Address Feedback --------- Co-authored-by: Baz Utsahajit <[email protected]>
1 parent b57679c commit fcfaa83

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

src/shockwave/ShockwaveFilter.ts

+46-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {
2+
deprecation,
23
Filter,
34
FilterSystem,
45
GlProgram,
56
GpuProgram,
67
PointData,
78
RenderSurface,
89
Texture,
9-
UniformGroup,
1010
} from 'pixi.js';
1111
import { vertex, wgslVertex } from '../defaults';
1212
import fragment from './shockwave.frag';
@@ -44,6 +44,11 @@ export interface ShockwaveFilterOptions
4444
* @default -1
4545
*/
4646
radius?: number;
47+
/**
48+
* Sets the elapsed time of the shockwave.
49+
* @default 0
50+
*/
51+
time?: number;
4752
}
4853

4954
/**
@@ -83,8 +88,35 @@ export class ShockwaveFilter extends Filter
8388
/**
8489
* @param options
8590
*/
86-
constructor(options?: ShockwaveFilterOptions)
91+
constructor(options?: ShockwaveFilterOptions);
92+
/**
93+
* @deprecated since 6.0.0
94+
*
95+
* @param {PIXI.PointData|number[]} [center=[0.5, 0.5]] - See `center` property.
96+
* @param {object} [options] - The optional parameters of shockwave filter.
97+
* @param {number} [options.amplitude=0.5] - See `amplitude`` property.
98+
* @param {number} [options.wavelength=1.0] - See `wavelength` property.
99+
* @param {number} [options.speed=500.0] - See `speed` property.
100+
* @param {number} [options.brightness=8] - See `brightness` property.
101+
* @param {number} [options.radius=4] - See `radius` property.
102+
* @param {number} [time=0] - See `time` property.
103+
*/
104+
constructor(center?: PointData | number[], options?: Omit<ShockwaveFilterOptions, 'time' | 'center'>, time?: number);
105+
// eslint-disable-next-line max-len
106+
constructor(...args: [ShockwaveFilterOptions?] | [(PointData | number[])?, Omit<ShockwaveFilterOptions, 'time' | 'center'>?, number?])
87107
{
108+
let options = args[0] ?? {};
109+
110+
if (Array.isArray(options) || ('x' in options && 'y' in options))
111+
{
112+
// eslint-disable-next-line max-len
113+
deprecation('6.0.0', 'ShockwaveFilter constructor params are now options object. See params: { center, speed, amplitude, wavelength, brightness, radius, time }');
114+
115+
options = { center: options, ...args[1] } as ShockwaveFilterOptions;
116+
117+
if (args[2] !== undefined) options.time = args[2];
118+
}
119+
88120
options = { ...ShockwaveFilter.DEFAULT_OPTIONS, ...options };
89121

90122
const gpuProgram = GpuProgram.from({
@@ -108,12 +140,12 @@ export class ShockwaveFilter extends Filter
108140
gpuProgram,
109141
glProgram,
110142
resources: {
111-
shockwaveUniforms: new UniformGroup({
112-
uTime: { value: 0, type: 'f32' },
143+
shockwaveUniforms: {
144+
uTime: { value: options.time, type: 'f32' },
113145
uCenter: { value: options.center, type: 'vec2<f32>' },
114146
uSpeed: { value: options.speed, type: 'f32' },
115147
uWave: { value: new Float32Array(4), type: 'vec4<f32>' },
116-
})
148+
},
117149
},
118150
});
119151

@@ -143,7 +175,15 @@ export class ShockwaveFilter extends Filter
143175
* @default [0,0]
144176
*/
145177
get center(): PointData { return this.uniforms.uCenter; }
146-
set center(value: PointData) { this.uniforms.uCenter = value; }
178+
set center(value: PointData | number[])
179+
{
180+
if (Array.isArray(value))
181+
{
182+
value = { x: value[0], y: value[1] };
183+
}
184+
185+
this.uniforms.uCenter = value;
186+
}
147187

148188
/**
149189
* Sets the center of the effect in normalized screen coords on the `x` axis

0 commit comments

Comments
 (0)