From 7fe5291380e7ec661b42ce2b80b1ca9294975610 Mon Sep 17 00:00:00 2001 From: Baz Utsahajit Date: Thu, 8 Feb 2024 12:24:43 +0000 Subject: [PATCH 1/3] Chore: Multi-Color Replace Filter Deprecations --- .../MultiColorReplaceFilter.ts | 58 +++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/src/multi-color-replace/MultiColorReplaceFilter.ts b/src/multi-color-replace/MultiColorReplaceFilter.ts index 5363d39bb..1320444ad 100644 --- a/src/multi-color-replace/MultiColorReplaceFilter.ts +++ b/src/multi-color-replace/MultiColorReplaceFilter.ts @@ -1,8 +1,11 @@ -import { Color, ColorSource, Filter, GlProgram, GpuProgram } from 'pixi.js'; +// eslint-disable-next-line camelcase +import { Color, ColorSource, deprecation, Filter, GlProgram, GpuProgram, v8_0_0 } 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 { /** @@ -72,13 +75,40 @@ export class MultiColorReplaceFilter extends Filter private _replacements: Array<[ColorSource, ColorSource]> = []; private _maxColors: number; - constructor(options?: MultiColorReplaceFilterOptions) + constructor(options?: MultiColorReplaceFilterOptions); + /** + * @deprecated since 8.0.0 + * + * @param {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(v8_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; - const gpuProgram = new GpuProgram({ + const gpuProgram = GpuProgram.from({ vertex: { source: wgslVertex, entryPoint: 'mainVertex', @@ -89,7 +119,7 @@ export class MultiColorReplaceFilter extends Filter }, }); - const glProgram = new GlProgram({ + const glProgram = GlProgram.from({ vertex, fragment: fragment.replace(/\$\{MAX_COLORS\}/g, (maxColors).toFixed(0)), name: 'multi-color-replace-filter', @@ -199,4 +229,24 @@ export class MultiColorReplaceFilter extends Filter */ get tolerance(): number { return this.uniforms.uTolerance; } set tolerance(value: number) { this.uniforms.uTolerance = value; } + + /** + * @deprecated since 8.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(v8_0_0, 'MultiColorReplaceFilter.epsilon is deprecated, please use MultiColorReplaceFilter.tolerance instead'); + this.tolerance = value; + } + get epsilon(): number + { + // eslint-disable-next-line max-len + deprecation(v8_0_0, 'MultiColorReplaceFilter.epsilon is deprecated, please use MultiColorReplaceFilter.tolerance instead'); + + return this.tolerance; + } } From c4a8aea6090fe74a263e1187089e02435bce0c8f Mon Sep 17 00:00:00 2001 From: Baz Utsahajit Date: Wed, 14 Feb 2024 14:44:07 +0000 Subject: [PATCH 2/3] Cleanup --- src/multi-color-replace/MultiColorReplaceFilter.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/multi-color-replace/MultiColorReplaceFilter.ts b/src/multi-color-replace/MultiColorReplaceFilter.ts index 1320444ad..c97846250 100644 --- a/src/multi-color-replace/MultiColorReplaceFilter.ts +++ b/src/multi-color-replace/MultiColorReplaceFilter.ts @@ -1,5 +1,4 @@ -// eslint-disable-next-line camelcase -import { Color, ColorSource, deprecation, Filter, GlProgram, GpuProgram, v8_0_0 } 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'; @@ -77,7 +76,7 @@ export class MultiColorReplaceFilter extends Filter constructor(options?: MultiColorReplaceFilterOptions); /** - * @deprecated since 8.0.0 + * @deprecated since 6.0.0 * * @param {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 @@ -96,7 +95,7 @@ export class MultiColorReplaceFilter extends Filter if (Array.isArray(options)) { // eslint-disable-next-line max-len - deprecation(v8_0_0, 'MultiColorReplaceFilter constructor params are now options object. See params: { replacements, tolerance, maxColors }'); + deprecation('6.0.0', 'MultiColorReplaceFilter constructor params are now options object. See params: { replacements, tolerance, maxColors }'); options = { replacements: options }; @@ -239,13 +238,13 @@ export class MultiColorReplaceFilter extends Filter set epsilon(value: number) { // eslint-disable-next-line max-len - deprecation(v8_0_0, 'MultiColorReplaceFilter.epsilon is deprecated, please use MultiColorReplaceFilter.tolerance instead'); + 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(v8_0_0, 'MultiColorReplaceFilter.epsilon is deprecated, please use MultiColorReplaceFilter.tolerance instead'); + deprecation('6.0.0', 'MultiColorReplaceFilter.epsilon is deprecated, please use MultiColorReplaceFilter.tolerance instead'); return this.tolerance; } From 8e4fac75b0789ff94bde47b479f6a9a535772495 Mon Sep 17 00:00:00 2001 From: Matt Karl Date: Wed, 14 Feb 2024 11:01:38 -0500 Subject: [PATCH 3/3] Update src/multi-color-replace/MultiColorReplaceFilter.ts --- src/multi-color-replace/MultiColorReplaceFilter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multi-color-replace/MultiColorReplaceFilter.ts b/src/multi-color-replace/MultiColorReplaceFilter.ts index c97846250..7dbea5a87 100644 --- a/src/multi-color-replace/MultiColorReplaceFilter.ts +++ b/src/multi-color-replace/MultiColorReplaceFilter.ts @@ -230,7 +230,7 @@ export class MultiColorReplaceFilter extends Filter set tolerance(value: number) { this.uniforms.uTolerance = value; } /** - * @deprecated since 8.0.0 + * @deprecated since 6.0.0 * * Tolerance of the floating-point comparison between colors (lower = more exact, higher = more inclusive) * @default 0.05