Skip to content

Commit

Permalink
Chore: ShockwaveFilter deprecate non-options constructor (#435)
Browse files Browse the repository at this point in the history
* Chore: Shockwave Filter Deprecations

* Cleanup

* Address Feedback

---------

Co-authored-by: Baz Utsahajit <[email protected]>
  • Loading branch information
bbazukun123 and bbazukun123 authored Feb 14, 2024
1 parent b57679c commit fcfaa83
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions src/shockwave/ShockwaveFilter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
deprecation,
Filter,
FilterSystem,
GlProgram,
GpuProgram,
PointData,
RenderSurface,
Texture,
UniformGroup,
} from 'pixi.js';
import { vertex, wgslVertex } from '../defaults';
import fragment from './shockwave.frag';
Expand Down Expand Up @@ -44,6 +44,11 @@ export interface ShockwaveFilterOptions
* @default -1
*/
radius?: number;
/**
* Sets the elapsed time of the shockwave.
* @default 0
*/
time?: number;
}

/**
Expand Down Expand Up @@ -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<ShockwaveFilterOptions, 'time' | 'center'>, time?: number);
// eslint-disable-next-line max-len
constructor(...args: [ShockwaveFilterOptions?] | [(PointData | number[])?, Omit<ShockwaveFilterOptions, 'time' | 'center'>?, 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({
Expand All @@ -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<f32>' },
uSpeed: { value: options.speed, type: 'f32' },
uWave: { value: new Float32Array(4), type: 'vec4<f32>' },
})
},
},
});

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fcfaa83

Please sign in to comment.