Skip to content

Commit

Permalink
feat: add createParticle jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
drawcall committed Feb 11, 2025
1 parent 473f643 commit 4f701d3
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 40 deletions.
59 changes: 40 additions & 19 deletions build/proton.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -700,21 +700,30 @@ declare class Span {
getValue(isInt?: boolean): number;
}

/**
* Represents an ArraySpan, a subclass of Span that works with arrays.
* @extends Span
*/
declare class ArraySpan extends Span {
/**
* Make sure that the color is an instance of Proton.ArraySpan, if not it makes a new instance
*
* @method setSpanValue
* @memberof Proton#Proton.Color
* @instance
*
* @param {Proton.Particle} particle
* @param {Number} the integrate time 1/ms
* @param {Int} the particle index
* Creates an ArraySpan instance from the given array.
* If the input is already an ArraySpan instance, it returns the input.
* @static
* @param {Array|ArraySpan|any} arr - The array or ArraySpan instance.
* @returns {ArraySpan|null} A new ArraySpan instance or null if the input is falsy.
*/
static createArraySpan(arr: any[] | ArraySpan | any): ArraySpan | null;
/**
* Creates an instance of ArraySpan.
* @param {Array|*|any} arr - The array or value to be converted to an array.
*/
static createArraySpan(arr: any): ArraySpan | null;
constructor(color: any);
constructor(arr: any[] | any | any);
_arr: any;
/**
* Gets a random value from the array.
* If the value is "random" or "Random", it returns a random color.
* @returns {*} A random value from the array or a random color.
*/
getValue(): any;
}

Expand Down Expand Up @@ -1035,11 +1044,11 @@ declare class Radius extends Initialize {
declare class Body extends Initialize {
/**
* Creates a new Body instance.
* @param {string|object|ArraySpan} image - The image source or object to use for the particle body.
* @param {string|object|Image|HTMLImageElement|ArraySpan} image - The image source or object to use for the particle body.
* @param {number} [w=20] - The width of the particle body.
* @param {number} [h] - The height of the particle body. Defaults to the width if not provided.
*/
constructor(image: string | object | ArraySpan, w?: number, h?: number);
constructor(image: string | object | (new (width?: number, height?: number) => HTMLImageElement) | HTMLImageElement | ArraySpan, w?: number, h?: number);
/**
* @type {ArraySpan}
* @private
Expand All @@ -1058,7 +1067,7 @@ declare class Body extends Initialize {
initialize(particle: object): void;
/**
* Sets the span value for the image.
* @param {string|object|ArraySpan} image - The image source or object to set as span value.
* @param {string|object|Image|HTMLImageElement|ArraySpan} image - The image source or object to set as span value.
* @returns {ArraySpan} The ArraySpan instance.
* @private
*/
Expand Down Expand Up @@ -1840,13 +1849,25 @@ declare class Emitter$1 extends Particle$1 {
dispatch(event: any, target: any): void;
emitting(time: any): void;
/**
* create single particle;
* Creates a single particle.
*
* can use emit({x:10},new Gravity(10),{'particleUpdate',fun}) or emit([{x:10},new Initialize],new Gravity(10),{'particleUpdate',fun})
* @method removeAllParticles
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
* @returns {Particle} The created particle.
*
*/
createParticle(initialize?: Object | any[], behaviour?: Object | any[]): Particle$1;
/**
* Sets up a particle with initialization and behavior.
*
* @param {Particle} particle - The particle to set up.
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
*/
setupParticle(particle: Particle$1, initialize?: Object | any[], behaviour?: Object | any[]): void;
/**
* Removes all particles and stops the emitter.
*/
createParticle(initialize: any, behaviour: any): any;
setupParticle(particle: any, initialize: any, behaviour: any): void;
remove(): void;
}

Expand Down
2 changes: 1 addition & 1 deletion build/proton.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/proton.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/proton.web.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/proton.web.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "proton-engine",
"version": "7.1.1",
"version": "7.1.3",
"description": "Proton is a simple and powerful javascript particle animation engine.",
"keywords": [
"particle",
Expand Down
18 changes: 15 additions & 3 deletions src/emitter/Emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ export default class Emitter extends Particle {
}

/**
* create single particle;
* Creates a single particle.
*
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
* @returns {Particle} The created particle.
*
* can use emit({x:10},new Gravity(10),{'particleUpdate',fun}) or emit([{x:10},new Initialize],new Gravity(10),{'particleUpdate',fun})
* @method removeAllParticles
*/
createParticle(initialize, behaviour) {
const particle = this.parent.pool.get(Particle);
Expand All @@ -281,6 +283,13 @@ export default class Emitter extends Particle {
return particle;
}

/**
* Sets up a particle with initialization and behavior.
*
* @param {Particle} particle - The particle to set up.
* @param {Object|Array} [initialize] - Initialization parameters or array of initialization objects.
* @param {Object|Array} [behaviour] - Behavior object or array of behavior objects.
*/
setupParticle(particle, initialize, behaviour) {
let initializes = this.initializes;
let behaviours = this.behaviours;
Expand All @@ -296,6 +305,9 @@ export default class Emitter extends Particle {
this.particles.push(particle);
}

/**
* Removes all particles and stops the emitter.
*/
remove() {
this.stop();
Util.destroyAll(this.particles);
Expand Down
4 changes: 2 additions & 2 deletions src/initialize/Body.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class Body extends Initialize {

/**
* Creates a new Body instance.
* @param {string|object|ArraySpan} image - The image source or object to use for the particle body.
* @param {string|object|Image|HTMLImageElement|ArraySpan} image - The image source or object to use for the particle body.
* @param {number} [w=20] - The width of the particle body.
* @param {number} [h] - The height of the particle body. Defaults to the width if not provided.
*/
Expand Down Expand Up @@ -55,7 +55,7 @@ export default class Body extends Initialize {

/**
* Sets the span value for the image.
* @param {string|object|ArraySpan} image - The image source or object to set as span value.
* @param {string|object|Image|HTMLImageElement|ArraySpan} image - The image source or object to set as span value.
* @returns {ArraySpan} The ArraySpan instance.
* @private
*/
Expand Down
32 changes: 21 additions & 11 deletions src/math/ArraySpan.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,36 @@ import Span from "./Span";
import Util from "../utils/Util";
import MathUtil from "./MathUtil";

/**
* Represents an ArraySpan, a subclass of Span that works with arrays.
* @extends Span
*/
export default class ArraySpan extends Span {
constructor(color) {
/**
* Creates an instance of ArraySpan.
* @param {Array|*|any} arr - The array or value to be converted to an array.
*/
constructor(arr) {
super();
this._arr = Util.toArray(color);
this._arr = Util.toArray(arr);
}

/**
* Gets a random value from the array.
* If the value is "random" or "Random", it returns a random color.
* @returns {*} A random value from the array or a random color.
*/
getValue() {
const val = Util.getRandFromArray(this._arr);
return val === "random" || val === "Random" ? MathUtil.randomColor() : val;
}

/**
* Make sure that the color is an instance of Proton.ArraySpan, if not it makes a new instance
*
* @method setSpanValue
* @memberof Proton#Proton.Color
* @instance
*
* @param {Proton.Particle} particle
* @param {Number} the integrate time 1/ms
* @param {Int} the particle index
* Creates an ArraySpan instance from the given array.
* If the input is already an ArraySpan instance, it returns the input.
* @static
* @param {Array|ArraySpan|any} arr - The array or ArraySpan instance.
* @returns {ArraySpan|null} A new ArraySpan instance or null if the input is falsy.
*/
static createArraySpan(arr) {
if (!arr) return null;
Expand All @@ -31,3 +40,4 @@ export default class ArraySpan extends Span {
else return new ArraySpan(arr);
}
}

Check failure on line 43 in src/math/ArraySpan.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Too many blank lines at the end of file. Max of 0 allowed

Check failure on line 43 in src/math/ArraySpan.js

View workflow job for this annotation

GitHub Actions / build (18.x)

Too many blank lines at the end of file. Max of 0 allowed

0 comments on commit 4f701d3

Please sign in to comment.