Skip to content

Commit

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

* Cleanup

* Update src/multi-color-replace/MultiColorReplaceFilter.ts

---------

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 c4c6933 commit 1ed388d
Showing 1 changed file with 51 additions and 2 deletions.
53 changes: 51 additions & 2 deletions src/multi-color-replace/MultiColorReplaceFilter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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 './multi-color-replace.frag';
import source from './multi-color-replace.wgsl';

type DeprecatedColor = number | number[] | Float32Array;

export interface MultiColorReplaceFilterOptions
{
/**
Expand Down Expand Up @@ -72,8 +74,35 @@ export class MultiColorReplaceFilter extends Filter
private _replacements: Array<[ColorSource, ColorSource]> = [];
private _maxColors: number;

constructor(options?: MultiColorReplaceFilterOptions)
constructor(options?: MultiColorReplaceFilterOptions);
/**
* @deprecated since 6.0.0
*
* @param {Array<Array>} replacements - The collection of replacement items. Each item is color-pair
* (an array length is 2). In the pair, the first value is original color , the second value
* is target color.
* @param {number} [epsilon=0.05] - Tolerance of the floating-point comparison between colors
* (lower = more exact, higher = more inclusive)
* @param {number} [maxColors] - The maximum number of replacements filter is able to use. Because the
* fragment is only compiled once, this cannot be changed after construction.
* If omitted, the default value is the length of `replacements`.
*/
constructor(replacements: Array<[DeprecatedColor, DeprecatedColor]>, epsilon?: number, maxColors?: number);
constructor(...args: [MultiColorReplaceFilterOptions?] | [Array<[DeprecatedColor, DeprecatedColor]>, number?, number?])
{
let options = args[0] ?? {} as MultiColorReplaceFilterOptions;

if (Array.isArray(options))
{
// eslint-disable-next-line max-len
deprecation('6.0.0', 'MultiColorReplaceFilter constructor params are now options object. See params: { replacements, tolerance, maxColors }');

options = { replacements: options };

if (args[1]) options.tolerance = args[1];
if (args[2]) options.maxColors = args[2];
}

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

const maxColors = options.maxColors ?? options.replacements.length;
Expand Down Expand Up @@ -199,4 +228,24 @@ export class MultiColorReplaceFilter extends Filter
*/
get tolerance(): number { return this.uniforms.uTolerance; }
set tolerance(value: number) { this.uniforms.uTolerance = value; }

/**
* @deprecated since 6.0.0
*
* Tolerance of the floating-point comparison between colors (lower = more exact, higher = more inclusive)
* @default 0.05
*/
set epsilon(value: number)
{
// eslint-disable-next-line max-len
deprecation('6.0.0', 'MultiColorReplaceFilter.epsilon is deprecated, please use MultiColorReplaceFilter.tolerance instead');
this.tolerance = value;
}
get epsilon(): number
{
// eslint-disable-next-line max-len
deprecation('6.0.0', 'MultiColorReplaceFilter.epsilon is deprecated, please use MultiColorReplaceFilter.tolerance instead');

return this.tolerance;
}
}

0 comments on commit 1ed388d

Please sign in to comment.