Skip to content

Commit

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

* Address Feedback

---------

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 75c3fef commit af4b55d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/color-map/ColorMapFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Filter, GlProgram, GpuProgram, SCALE_MODE, Texture, TextureSource } from 'pixi.js';
import { deprecation, Filter, GlProgram, GpuProgram, SCALE_MODE, Texture, TextureSource } from 'pixi.js';
import { vertex, wgslVertex } from '../defaults';
import fragment from './color-map.frag';
import source from './color-map.wgsl';
Expand Down Expand Up @@ -54,8 +54,31 @@ export class ColorMapFilter extends Filter
private _scaleMode: SCALE_MODE = 'linear';
private _colorMap!: ColorMapTexture;

constructor(options: ColorMapFilterOptions)
constructor(options: ColorMapFilterOptions);
/**
* @deprecated since 6.0.0
*
* @param {HTMLImageElement|HTMLCanvasElement|PIXI.BaseTexture|PIXI.Texture} [colorMap] - The
* colorMap texture of the filter.
* @param {boolean} [nearest=false] - Whether use NEAREST for colorMap texture.
* @param {number} [mix=1] - The mix from 0 to 1, where 0 is the original image and 1 is the color mapped image.
*/
constructor(colorMap: ColorMapTexture, nearest?: boolean, mix?: number);
constructor(...args: [ColorMapFilterOptions] | [ColorMapTexture, boolean?, number?])
{
let options = args[0] ?? {};

if (options instanceof Texture || options instanceof TextureSource)
{
// eslint-disable-next-line max-len
deprecation('6.0.0', 'ColorMapFilter constructor params are now options object. See params: { colorMap, nearest, mix }');

options = { colorMap: options };

if (args[1] !== undefined) options.nearest = args[1];
if (args[2] !== undefined) options.mix = args[2];
}

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

if (!options.colorMap) throw Error('No color map texture source was provided to ColorMapFilter');
Expand Down

0 comments on commit af4b55d

Please sign in to comment.