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: Bloom Filter Deprecations #415

Merged
merged 8 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
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]) options.quality = args[1];
if (args[2]) options.resolution = args[2];
if (args[3]) options.kernelSize = args[3];
}
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved

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 8.0.0
*
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved
* 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 8.0.0
*
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved
* 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 8.0.0
*
bigtimebuddy marked this conversation as resolved.
Show resolved Hide resolved
* 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;
}
}
Loading