Skip to content

Commit

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

* Cleanup

* Cleanup 2

---------

Co-authored-by: Baz Utsahajit <[email protected]>
  • Loading branch information
bbazukun123 and bbazukun123 authored Feb 14, 2024
1 parent 0b900f0 commit 4cdc7a8
Showing 1 changed file with 68 additions and 2 deletions.
70 changes: 68 additions & 2 deletions src/color-replace/ColorReplaceFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Color, ColorSource, Filter, GlProgram, GpuProgram } from 'pixi.js';
import { Color, ColorSource, deprecation, Filter, GlProgram, GpuProgram } from 'pixi.js';
import { vertex, wgslVertex } from '../defaults';
import fragment from './color-replace.frag';
import source from './color-replace.wgsl';
Expand All @@ -8,6 +8,8 @@ import source from './color-replace.wgsl';
* http://www.html5gamedevs.com/topic/10640-outline-a-sprite-change-certain-colors/?p=69966
*/

type DeprecatedColor = number | number[] | Float32Array;

export interface ColorReplaceFilterOptions
{
/**
Expand Down Expand Up @@ -73,8 +75,33 @@ export class ColorReplaceFilter extends Filter
private _originalColor: Color;
private _targetColor: Color;

constructor(options?: ColorReplaceFilterOptions)
constructor(options?: ColorReplaceFilterOptions);
/**
* @deprecated since 6.0.0
*
* @param {number|Array<number>|Float32Array} [originalColor=0xFF0000] - The color that will be changed,
* as a 3 component RGB e.g. `[1.0, 1.0, 1.0]`
* @param {number|Array<number>|Float32Array} [newColor=0x000000] - The resulting color, as a 3 component
* RGB e.g. `[1.0, 0.5, 1.0]`
* @param {number} [epsilon=0.4] - Tolerance/sensitivity of the floating-point comparison between colors
* (lower = more exact, higher = more inclusive)
*/
constructor(originalColor?: number, newColor?: number, epsilon?: number);
constructor(...args: [ColorReplaceFilterOptions?] | [DeprecatedColor?, 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', 'ColorReplaceFilter constructor params are now options object. See params: { originalColor, targetColor, tolerance }');

options = { originalColor: options };

if (args[1] !== undefined) options.targetColor = args[1];
if (args[2] !== undefined) options.tolerance = args[2];
}

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

const gpuProgram = GpuProgram.from({
Expand Down Expand Up @@ -154,4 +181,43 @@ export class ColorReplaceFilter extends Filter
*/
get tolerance(): number { return this.uniforms.uTolerance; }
set tolerance(value: number) { this.uniforms.uTolerance = value; }

/**
* @deprecated since 6.0.0
*
* The resulting color, as a 3 component RGB e.g. [1.0, 0.5, 1.0]
* @member {number|Array<number>|Float32Array}
* @default 0x000000
*/
set newColor(value: DeprecatedColor)
{
deprecation('6.0.0', 'ColorReplaceFilter.newColor is deprecated, please use ColorReplaceFilter.targetColor instead');

this.targetColor = value;
}
get newColor(): DeprecatedColor
{
deprecation('6.0.0', 'ColorReplaceFilter.newColor is deprecated, please use ColorReplaceFilter.targetColor instead');

return this.targetColor as DeprecatedColor;
}

/**
* @deprecated since 6.0.0
*
* Tolerance/sensitivity of the floating-point comparison between colors (lower = more exact, higher = more inclusive)
* @default 0.4
*/
set epsilon(value: number)
{
deprecation('6.0.0', 'ColorReplaceFilter.epsilon is deprecated, please use ColorReplaceFilter.tolerance instead');

this.tolerance = value;
}
get epsilon(): number
{
deprecation('6.0.0', 'ColorReplaceFilter.epsilon is deprecated, please use ColorReplaceFilter.tolerance instead');

return this.tolerance;
}
}

0 comments on commit 4cdc7a8

Please sign in to comment.