Skip to content

Commit

Permalink
Chore: BloomFilter deprecations (#415)
Browse files Browse the repository at this point in the history
* Chore: Bloom Filter Deprecations

* Address Feedback

* Cleanup

* Update src/bloom/BloomFilter.ts

* Update src/bloom/BloomFilter.ts

* Update src/bloom/BloomFilter.ts

* Update src/bloom/BloomFilter.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 bdad3a0 commit c358242
Showing 1 changed file with 106 additions and 4 deletions.
110 changes: 106 additions & 4 deletions src/bloom/BloomFilter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
import { AlphaFilter, BlurFilterPass, FilterSystem, PointData, RenderSurface, Texture, TexturePool } from 'pixi.js';
/* eslint-disable max-len */
import {
AlphaFilter,
BlurFilterPass,
deprecation,
FilterSystem,
PointData,
RenderSurface,
Texture,
TexturePool,
} from 'pixi.js';

type DeprecatedBlurValue = number | PointData | number[];

export interface BloomFilterOptions
{
Expand All @@ -12,6 +24,11 @@ export interface BloomFilterOptions
* @default 4
*/
quality?: number;
/**
* The resolution of the blurX & blurY filter.
* @default 1
*/
resolution?: number;
/**
* The kernel size of the blur filter. Must be an odd number between 5 and 15 (inclusive).
* @default 5
Expand All @@ -34,16 +51,45 @@ export class BloomFilter extends AlphaFilter
public static readonly DEFAULT_OPTIONS: BloomFilterOptions = {
strength: { x: 2, y: 2 },
quality: 4,
resolution: 1,
kernelSize: 5
};

private _blurXFilter: BlurFilterPass;
private _blurYFilter: BlurFilterPass;
private _strength: PointData;

constructor(options?: BloomFilterOptions)
constructor(options?: BloomFilterOptions);
/**
* @deprecated since 6.0.0
*
* @param {number|PIXI.PointData|number[]} [blur=2] - Sets the strength of both the blurX and blurY properties simultaneously
* @param {number} [quality=4] - The quality of the blurX & blurY filter.
* @param {number} [resolution=1] - The resolution of the blurX & blurY filter.
* @param {number} [kernelSize=5] - The kernelSize of the blurX & blurY filter.Options: 5, 7, 9, 11, 13, 15.
*/
constructor(blur?: DeprecatedBlurValue, quality?: number, resolution?: number, kernelSize?: number);
constructor(...args: [BloomFilterOptions?] | [DeprecatedBlurValue?, number?, number?, number?])
{
options = { ...BloomFilter.DEFAULT_OPTIONS, ...options };
let options = args[0] ?? {};

if (typeof options === 'number' || Array.isArray(options) || ('x' in options && 'y' in options))
{
// eslint-disable-next-line max-len
deprecation('6.0.0', 'BloomFilter constructor params are now options object. See params: { strength, quality, resolution, kernelSize }');

let strength = options;

if (Array.isArray(strength)) strength = { x: strength[0], y: strength[1] };

options = { strength };

if (args[1] !== undefined) options.quality = args[1];
if (args[2] !== undefined) options.resolution = args[2];
if (args[3] !== undefined) options.kernelSize = args[3];
}

options = { ...BloomFilter.DEFAULT_OPTIONS, ...options } as BloomFilterOptions;

super();

Expand Down Expand Up @@ -139,5 +185,61 @@ export class BloomFilter extends AlphaFilter
this._blurXFilter.blur = this.strengthX;
this._blurYFilter.blur = this.strengthY;
}
}

/**
* @deprecated since 6.0.0
*
* The strength of both the blurX and blurY properties simultaneously
* @default 2
*/
get blur(): number
{
deprecation('6.0.0', 'BloomFilter.blur is deprecated, please use BloomFilter.strength instead');

return this.strengthX;
}
set blur(value: number)
{
deprecation('6.0.0', 'BloomFilter.blur is deprecated, please use BloomFilter.strength instead');

this.strength = value;
}

/**
* @deprecated since 6.0.0
*
* The strength of the blurX property
* @default 2
*/
get blurX(): number
{
deprecation('6.0.0', 'BloomFilter.blurX is deprecated, please use BloomFilter.strengthX instead');

return this.strengthX;
}
set blurX(value: number)
{
deprecation('6.0.0', 'BloomFilter.blurX is deprecated, please use BloomFilter.strengthX instead');

this.strengthX = value;
}

/**
* @deprecated since 6.0.0
*
* The strength of the blurY property
* @default 2
*/
get blurY(): number
{
deprecation('6.0.0', 'BloomFilter.blurY is deprecated, please use BloomFilter.strengthY instead');

return this.strengthY;
}
set blurY(value: number)
{
deprecation('6.0.0', 'BloomFilter.blurY is deprecated, please use BloomFilter.strengthY instead');

this.strengthY = value;
}
}

0 comments on commit c358242

Please sign in to comment.