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: Multi-Color Replace Filter Deprecations #428

Merged
merged 4 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
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;
}
}
Loading