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 Replace Filter Deprecations #419

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Changes from 3 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
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 8.0.0
*
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved
* 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 8.0.0
*
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved
* 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;
}
}
Loading