Skip to content

Commit

Permalink
1.10.7
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Dec 9, 2024
1 parent e967368 commit 31cadec
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 59 deletions.
19 changes: 13 additions & 6 deletions dist/littlejs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,9 @@ declare module "littlejsengine" {
* @param {Number} digits - precision to display
* @return {String} */
toString(digits?: number): string;
/** Checks if this is a valid vector
* @return {Boolean} */
isValid(): boolean;
}
/**
* Color object (red, green, blue, alpha) with some helpful functions
Expand Down Expand Up @@ -966,6 +969,9 @@ declare module "littlejsengine" {
/** Returns this color expressed as 32 bit RGBA value
* @return {Number} */
rgbaInt(): number;
/** Checks if this is a valid color
* @return {Boolean} */
isValid(): boolean;
}
/**
* Timer object tracks how long has passed since it was set
Expand Down Expand Up @@ -1916,24 +1922,24 @@ declare module "littlejsengine" {
* - Drawn directly to the main canvas without using WebGL
* @namespace TileCollision
*/
/** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
/** The tile collision layer grid, use setTileCollisionData and getTileCollisionData to access
* @type {Array}
* @memberof TileCollision */
export let tileCollision: any[];
/** Size of the tile collision layer
/** Size of the tile collision layer 2d grid
* @type {Vector2}
* @memberof TileCollision */
export let tileCollisionSize: Vector2;
/** Clear and initialize tile collision
* @param {Vector2} size
* @param {Vector2} size - width and height of tile collision 2d grid
* @memberof TileCollision */
export function initTileCollision(size: Vector2): void;
/** Set tile collision data
/** Set tile collision data for a given cell in the grid
* @param {Vector2} pos
* @param {Number} [data]
* @memberof TileCollision */
export function setTileCollisionData(pos: Vector2, data?: number): void;
/** Get tile collision data
/** Get tile collision data for a given cell in the grid
* @param {Vector2} pos
* @return {Number}
* @memberof TileCollision */
Expand All @@ -1945,7 +1951,8 @@ declare module "littlejsengine" {
* @return {Boolean}
* @memberof TileCollision */
export function tileCollisionTest(pos: Vector2, size?: Vector2, object?: EngineObject): boolean;
/** Return the center of first tile hit (does not return the exact intersection)
/** Return the center of first tile hit, undefined if nothing was hit.
* This does not return the exact intersection, but the center of the tile hit.
* @param {Vector2} posStart
* @param {Vector2} posEnd
* @param {EngineObject} [object]
Expand Down
81 changes: 65 additions & 16 deletions dist/littlejs.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,18 +801,24 @@ class Vector2
* @param {Number} [y] - Y axis location */
constructor(x=0, y=0)
{
ASSERT(typeof x == 'number' && typeof y == 'number');
/** @property {Number} - X axis location */
this.x = x;
/** @property {Number} - Y axis location */
this.y = y;
ASSERT(this.isValid());
}

/** Sets values of this vector and returns self
* @param {Number} [x] - X axis location
* @param {Number} [y] - Y axis location
* @return {Vector2} */
set(x=0, y=0) { this.x=x; this.y=y; return this; }
set(x=0, y=0)
{
this.x = x;
this.y = y;
ASSERT(this.isValid());
return this;
}

/** Returns a new vector that is a copy of this
* @return {Vector2} */
Expand Down Expand Up @@ -1004,6 +1010,14 @@ class Vector2
if (debug)
return `(${(this.x<0?'':' ') + this.x.toFixed(digits)},${(this.y<0?'':' ') + this.y.toFixed(digits)} )`;
}

/** Checks if this is a valid vector
* @return {Boolean} */
isValid()
{
return typeof this.x == 'number' && !isNaN(this.x)
&& typeof this.y == 'number' && !isNaN(this.y);
}
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1064,6 +1078,7 @@ class Color
this.b = b;
/** @property {Number} - Alpha */
this.a = a;
ASSERT(this.isValid());
}

/** Sets values of this color and returns self
Expand All @@ -1073,7 +1088,14 @@ class Color
* @param {Number} [a] - alpha
* @return {Color} */
set(r=1, g=1, b=1, a=1)
{ this.r=r; this.g=g; this.b=b; this.a=a; return this; }
{
this.r = r;
this.g = g;
this.b = b;
this.a = a;
ASSERT(this.isValid());
return this;
}

/** Returns a new color that is a copy of this
* @return {Color} */
Expand Down Expand Up @@ -1156,6 +1178,7 @@ class Color
this.g = f(p, q, h);
this.b = f(p, q, h - 1/3);
this.a = a;
ASSERT(this.isValid());
return this;
}

Expand Down Expand Up @@ -1183,7 +1206,6 @@ class Color
else if (b == max)
h = (r - g) / d + 4;
}

return [h / 6, s, l, a];
}

Expand Down Expand Up @@ -1216,11 +1238,27 @@ class Color
* @return {Color} */
setHex(hex)
{
const fromHex = (c)=> clamp(parseInt(hex.slice(c,c+2),16)/255);
this.r = fromHex(1);
this.g = fromHex(3),
this.b = fromHex(5);
this.a = hex.length > 7 ? fromHex(7) : 1;
ASSERT(typeof hex == 'string' && hex[0] == '#');
ASSERT([4,5,7,9].includes(hex.length), 'Invalid hex');

if (hex.length < 6)
{
const fromHex = (c)=> clamp(parseInt(hex[c],16)/15);
this.r = fromHex(1);
this.g = fromHex(2),
this.b = fromHex(3);
this.a = hex.length == 5 ? fromHex(4) : 1;
}
else
{
const fromHex = (c)=> clamp(parseInt(hex.slice(c,c+2),16)/255);
this.r = fromHex(1);
this.g = fromHex(3),
this.b = fromHex(5);
this.a = hex.length == 9 ? fromHex(7) : 1;
}

ASSERT(this.isValid());
return this;
}

Expand All @@ -1234,6 +1272,16 @@ class Color
const a = clamp(this.a)*255<<24;
return r + g + b + a;
}

/** Checks if this is a valid color
* @return {Boolean} */
isValid()
{
return typeof this.r == 'number' && !isNaN(this.r)
&& typeof this.g == 'number' && !isNaN(this.g)
&& typeof this.b == 'number' && !isNaN(this.b)
&& typeof this.a == 'number' && !isNaN(this.a);
}
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3975,18 +4023,18 @@ function zzfxM(instruments, patterns, sequence, BPM = 125)



/** The tile collision layer array, use setTileCollisionData and getTileCollisionData to access
/** The tile collision layer grid, use setTileCollisionData and getTileCollisionData to access
* @type {Array}
* @memberof TileCollision */
let tileCollision = [];

/** Size of the tile collision layer
/** Size of the tile collision layer 2d grid
* @type {Vector2}
* @memberof TileCollision */
let tileCollisionSize = vec2();

/** Clear and initialize tile collision
* @param {Vector2} size
* @param {Vector2} size - width and height of tile collision 2d grid
* @memberof TileCollision */
function initTileCollision(size)
{
Expand All @@ -3996,7 +4044,7 @@ function initTileCollision(size)
tileCollision[i] = 0;
}

/** Set tile collision data
/** Set tile collision data for a given cell in the grid
* @param {Vector2} pos
* @param {Number} [data]
* @memberof TileCollision */
Expand All @@ -4005,7 +4053,7 @@ function setTileCollisionData(pos, data=0)
pos.arrayCheck(tileCollisionSize) && (tileCollision[(pos.y|0)*tileCollisionSize.x+pos.x|0] = data);
}

/** Get tile collision data
/** Get tile collision data for a given cell in the grid
* @param {Vector2} pos
* @return {Number}
* @memberof TileCollision */
Expand Down Expand Up @@ -4036,7 +4084,8 @@ function tileCollisionTest(pos, size=vec2(), object)
return false;
}

/** Return the center of first tile hit (does not return the exact intersection)
/** Return the center of first tile hit, undefined if nothing was hit.
* This does not return the exact intersection, but the center of the tile hit.
* @param {Vector2} posStart
* @param {Vector2} posEnd
* @param {EngineObject} [object]
Expand Down Expand Up @@ -5214,7 +5263,7 @@ const engineName = 'LittleJS';
* @type {String}
* @default
* @memberof Engine */
const engineVersion = '1.10.6';
const engineVersion = '1.10.7';

/** Frames per second to update
* @type {Number}
Expand Down
2 changes: 1 addition & 1 deletion dist/littlejs.esm.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 31cadec

Please sign in to comment.