Skip to content

Commit

Permalink
Chore: Shockwave Filter Deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
bbazukun123 committed Feb 8, 2024
1 parent 9d610bb commit 0e88a9f
Showing 1 changed file with 65 additions and 8 deletions.
73 changes: 65 additions & 8 deletions src/shockwave/ShockwaveFilter.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import {
deprecation,
Filter,
FilterSystem,
GlProgram,
GpuProgram,
PointData,
RenderSurface,
Texture,
UniformGroup,
// eslint-disable-next-line camelcase
v8_0_0,
} from 'pixi.js';
import { vertex, wgslVertex } from '../defaults';
import fragment from './shockwave.frag';
import source from './shockwave.wgsl';

type DeprecatedPointLike = PointData | number[];

interface DeprecatedShockwaveFilterOptions
{
amplitude: number;
wavelength: number;
speed: number;
brightness: number;
radius: number;
}

export interface ShockwaveFilterOptions
{
/**
Expand Down Expand Up @@ -44,6 +57,11 @@ export interface ShockwaveFilterOptions
* @default -1
*/
radius?: number;
/**
* Sets the elapsed time of the shockwave.
* @default 0
*/
time?: number;
}

/**
Expand Down Expand Up @@ -83,11 +101,41 @@ export class ShockwaveFilter extends Filter
/**
* @param options
*/
constructor(options?: ShockwaveFilterOptions)
constructor(options?: ShockwaveFilterOptions);
/**
* @deprecated since 8.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?: DeprecatedPointLike, options?: Partial<DeprecatedShockwaveFilterOptions>, time?: number);
// eslint-disable-next-line max-len
constructor(...args: [ShockwaveFilterOptions?] | [DeprecatedPointLike?, Partial<DeprecatedShockwaveFilterOptions>?, number?])
{
let options = args[0] ?? {};

if (Array.isArray(options) || ('x' in options && 'y' in options))
{
// eslint-disable-next-line max-len
deprecation(v8_0_0, 'ShockwaveFilter constructor params are now options object. See params: { center, speed, amplitude, wavelength, brightness, radius, time }');

const x = 'x' in options ? options.x : options[0];
const y = 'y' in options ? options.y : options[1];

options = { center: { x, y }, ...args[1] };

if (args[2]) options.time = args[2];
}

options = { ...ShockwaveFilter.DEFAULT_OPTIONS, ...options };

const gpuProgram = new GpuProgram({
const gpuProgram = GpuProgram.from({
vertex: {
source: wgslVertex,
entryPoint: 'mainVertex',
Expand All @@ -98,7 +146,7 @@ export class ShockwaveFilter extends Filter
},
});

const glProgram = new GlProgram({
const glProgram = GlProgram.from({
vertex,
fragment,
name: 'shockwave-filter'
Expand All @@ -108,12 +156,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 +191,16 @@ 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 | DeprecatedPointLike)
{
if (Array.isArray(value))
{
deprecation(v8_0_0, 'ShockwaveFilter.center now only accepts {x,y} PointData.');
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 0e88a9f

Please sign in to comment.