Skip to content

Commit

Permalink
Chore: ColorOverlayFilter deprecate non-options constructor (#418)
Browse files Browse the repository at this point in the history
* Chore: Color Overlay Filter Deprecations

* Cleanup

---------

Co-authored-by: Baz Utsahajit <[email protected]>
Co-authored-by: Matt Karl <[email protected]>
  • Loading branch information
3 people authored Feb 14, 2024
1 parent af4b55d commit 0b900f0
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/color-overlay/ColorOverlayFilter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Color, ColorSource, Filter, GlProgram, GpuProgram, UniformGroup } from 'pixi.js';
import { Color, ColorSource, deprecation, Filter, GlProgram, GpuProgram } from 'pixi.js';
import { vertex, wgslVertex } from '../defaults';
import fragment from './color-overlay.frag';
import source from './color-overlay.wgsl';

type DeprecatedColor = number | number[] | Float32Array;

export interface ColorOverlayFilterOptions
{
/**
Expand Down Expand Up @@ -41,8 +43,28 @@ export class ColorOverlayFilter extends Filter

private _color: Color;

constructor(options: ColorOverlayFilterOptions = {})
constructor(options?: ColorOverlayFilterOptions);
/**
* @deprecated since 6.0.0
*
* @param {number|Array<number>} [color=0x000000] - The resulting color, as a 3 component RGB e.g. [1.0, 0.5, 1.0]
* @param {number} [alpha=1] - The alpha value of the color
*/
constructor(color?: DeprecatedColor, alpha?: number);
constructor(...args: [ColorOverlayFilterOptions?] | [DeprecatedColor?, number?])
{
let options = args[0] ?? {};

if (typeof options === 'number' || Array.isArray(options) || options instanceof Float32Array)
{
// eslint-disable-next-line max-len
deprecation('6.0.0', 'ColorOverlayFilter constructor params are now options object. See params: { color, alpha }');

options = { color: options };

if (args[1] !== undefined) options.alpha = args[1];
}

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

const gpuProgram = GpuProgram.from({
Expand All @@ -66,10 +88,10 @@ export class ColorOverlayFilter extends Filter
gpuProgram,
glProgram,
resources: {
colorOverlayUniforms: new UniformGroup({
colorOverlayUniforms: {
uColor: { value: new Float32Array(3), type: 'vec3<f32>' },
uAlpha: { value: options.alpha, type: 'f32' },
})
},
},
});

Expand Down

0 comments on commit 0b900f0

Please sign in to comment.