Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Color Overlay Filter Deprecations #418

Merged
merged 3 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading