Skip to content

Commit

Permalink
feat: publish to npm after pull#82
Browse files Browse the repository at this point in the history
  • Loading branch information
Prozi committed Oct 3, 2024
1 parent a64ac95 commit 829a255
Show file tree
Hide file tree
Showing 54 changed files with 1,434 additions and 503 deletions.
3 changes: 0 additions & 3 deletions dist/bodies/circle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ export declare class Circle extends SATCircle implements BBox, BodyProps {
* scaleY = scale in case of Circles
*/
get scaleY(): number;
/**
* group for collision filtering
*/
get group(): number;
set group(group: number);
/**
Expand Down
4 changes: 1 addition & 3 deletions dist/bodies/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ class Circle extends sat_1.Circle {
get scaleY() {
return this.scale;
}
/**
* group for collision filtering
*/
// Don't overwrite docs from BodyProps
get group() {
return this._group;
}
Expand Down
3 changes: 0 additions & 3 deletions dist/bodies/polygon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ export declare class Polygon extends SATPolygon implements BBox, BodyProps {
* allow easier setting of scale
*/
set scale(scale: number);
/**
* group for collision filtering
*/
get group(): number;
set group(group: number);
/**
Expand Down
4 changes: 1 addition & 3 deletions dist/bodies/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ class Polygon extends sat_1.Polygon {
set scale(scale) {
this.setScale(scale);
}
/**
* group for collision filtering
*/
// Don't overwrite docs from BodyProps
get group() {
return this._group;
}
Expand Down
69 changes: 49 additions & 20 deletions dist/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2704,9 +2704,7 @@ which is good. See: http://baagoe.com/en/RandomMusings/hash/avalanche.xhtml
get scaleY() {
return this.scale;
}
/**
* group for collision filtering
*/
// Don't overwrite docs from BodyProps
get group() {
return this._group;
}
Expand Down Expand Up @@ -3240,9 +3238,7 @@ which is good. See: http://baagoe.com/en/RandomMusings/hash/avalanche.xhtml
set scale(scale) {
this.setScale(scale);
}
/**
* group for collision filtering
*/
// Don't overwrite docs from BodyProps
get group() {
return this._group;
}
Expand Down Expand Up @@ -4345,6 +4341,7 @@ which is good. See: http://baagoe.com/en/RandomMusings/hash/avalanche.xhtml
body.isStatic = !!options.isStatic;
body.isTrigger = !!options.isTrigger;
body.padding = options.padding || 0;
// Default value should be reflected in documentation of `BodyOptions.group`
body.group =
(_a = options.group) !== null && _a !== void 0 ? _a : 0x7fffffff;
if (
Expand Down Expand Up @@ -4389,8 +4386,37 @@ which is good. See: http://baagoe.com/en/RandomMusings/hash/avalanche.xhtml
/**
* checks if two bodies can interact (for collision filtering)
*
* Based on {@link https://box2d.org/documentation/md_simulation.html#filtering Box2D}
* ({@link https://aurelienribon.wordpress.com/2011/07/01/box2d-tutorial-collision-filtering/ tutorial})
*
* @param bodyA
* @param bodyB
*
* @example
* const body1 = { group: 0b00000000_00000000_00000001_00000000 }
* const body2 = { group: 0b11111111_11111111_00000011_00000000 }
* const body3 = { group: 0b00000010_00000000_00000100_00000000 }
*
* // Body 1 has the first custom group but cannot interact with any other groups
* // except itself because the first 16 bits are all zeros, only bodies with an
* // identical value can interact with it.
* canInteract(body1, body1) // returns true (identical groups can always interact)
* canInteract(body1, body2) // returns false
* canInteract(body1, body3) // returns false
*
* // Body 2 has the first and second group and can interact with all other
* // groups, but only if that body also can interact with is custom group.
* canInteract(body2, body1) // returns false (body1 cannot interact with others)
* canInteract(body2, body2) // returns true (identical groups can always interact)
* canInteract(body2, body3) // returns true
*
* // Body 3 has the third group but can interact with the second group.
* // This means that Body 2 and Body 3 can interact with each other but no other
* // body can interact with Body 1 because it doesn't allow interactions with
* // any other custom group.
* canInteract(body3, body1) // returns false (body1 cannot interact with others)
* canInteract(body3, body2) // returns true
* canInteract(body3, body3) // returns true (identical groups can always interact)
*/
function canInteract({ group: groupA }, { group: groupB }) {
return (
Expand Down Expand Up @@ -6173,26 +6199,29 @@ which is good. See: http://baagoe.com/en/RandomMusings/hash/avalanche.xhtml
/******/
/************************************************************************/
var __webpack_exports__ = {};
/*!***************************!*\
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
/*!***************************!*\
!*** ./src/demo/index.js ***!
\***************************/
const { TestCanvas } = __webpack_require__(
/*! ./canvas */ "./src/demo/canvas.js",
);
const { TestCanvas } = __webpack_require__(
/*! ./canvas */ "./src/demo/canvas.js",
);

const isStressTest = window.location.search.indexOf("?stress") !== -1;
const Test = isStressTest
? __webpack_require__(/*! ./stress */ "./src/demo/stress.js")
: __webpack_require__(/*! ./tank */ "./src/demo/tank.js");
const isStressTest = window.location.search.indexOf("?stress") !== -1;
const Test = isStressTest
? __webpack_require__(/*! ./stress */ "./src/demo/stress.js")
: __webpack_require__(/*! ./tank */ "./src/demo/tank.js");

const test = new Test();
const canvas = new TestCanvas(test);
const test = new Test();
const canvas = new TestCanvas(test);

document.body.appendChild(canvas.element);
document.body.appendChild(canvas.element);

if (test.start) {
test.start();
}
if (test.start) {
test.start();
}
})();

/******/
})();
11 changes: 11 additions & 0 deletions dist/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ export interface BodyOptions {
padding?: number;
/**
* group for collision filtering
*
* Based on {@link https://box2d.org/documentation/md_simulation.html#filtering Box2D}
* ({@link https://aurelienribon.wordpress.com/2011/07/01/box2d-tutorial-collision-filtering/ tutorial})
*
* Values in {@link BodyGroup} are predefined and used each the body type and
* should not be used for custom filtering
*
* `0b00000001 << 16` to `0b01000000 << 16` (max 0x7fffffff) are free to use for custom groups
*
* @see {@link canInteract} for how groups are used
* @default 0x7fffffff // member of all groups (can interact with everyting)
*/
group?: number;
}
Expand Down
29 changes: 29 additions & 0 deletions dist/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,37 @@ export declare function intersectAABB(bodyA: BBox, bodyB: BBox): boolean;
/**
* checks if two bodies can interact (for collision filtering)
*
* Based on {@link https://box2d.org/documentation/md_simulation.html#filtering Box2D}
* ({@link https://aurelienribon.wordpress.com/2011/07/01/box2d-tutorial-collision-filtering/ tutorial})
*
* @param bodyA
* @param bodyB
*
* @example
* const body1 = { group: 0b00000000_00000000_00000001_00000000 }
* const body2 = { group: 0b11111111_11111111_00000011_00000000 }
* const body3 = { group: 0b00000010_00000000_00000100_00000000 }
*
* // Body 1 has the first custom group but cannot interact with any other groups
* // except itself because the first 16 bits are all zeros, only bodies with an
* // identical value can interact with it.
* canInteract(body1, body1) // returns true (identical groups can always interact)
* canInteract(body1, body2) // returns false
* canInteract(body1, body3) // returns false
*
* // Body 2 has the first and second group and can interact with all other
* // groups, but only if that body also can interact with is custom group.
* canInteract(body2, body1) // returns false (body1 cannot interact with others)
* canInteract(body2, body2) // returns true (identical groups can always interact)
* canInteract(body2, body3) // returns true
*
* // Body 3 has the third group but can interact with the second group.
* // This means that Body 2 and Body 3 can interact with each other but no other
* // body can interact with Body 1 because it doesn't allow interactions with
* // any other custom group.
* canInteract(body3, body1) // returns false (body1 cannot interact with others)
* canInteract(body3, body2) // returns true
* canInteract(body3, body3) // returns true (identical groups can always interact)
*/
export declare function canInteract(
{ group: groupA }: Body,
Expand Down
30 changes: 30 additions & 0 deletions dist/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function extendBody(body, options = {}) {
body.isStatic = !!options.isStatic;
body.isTrigger = !!options.isTrigger;
body.padding = options.padding || 0;
// Default value should be reflected in documentation of `BodyOptions.group`
body.group = (_a = options.group) !== null && _a !== void 0 ? _a : 0x7fffffff;
if (body.typeGroup !== model_1.BodyGroup.Circle && options.isCentered) {
body.isCentered = true;
Expand Down Expand Up @@ -182,8 +183,37 @@ function intersectAABB(bodyA, bodyB) {
/**
* checks if two bodies can interact (for collision filtering)
*
* Based on {@link https://box2d.org/documentation/md_simulation.html#filtering Box2D}
* ({@link https://aurelienribon.wordpress.com/2011/07/01/box2d-tutorial-collision-filtering/ tutorial})
*
* @param bodyA
* @param bodyB
*
* @example
* const body1 = { group: 0b00000000_00000000_00000001_00000000 }
* const body2 = { group: 0b11111111_11111111_00000011_00000000 }
* const body3 = { group: 0b00000010_00000000_00000100_00000000 }
*
* // Body 1 has the first custom group but cannot interact with any other groups
* // except itself because the first 16 bits are all zeros, only bodies with an
* // identical value can interact with it.
* canInteract(body1, body1) // returns true (identical groups can always interact)
* canInteract(body1, body2) // returns false
* canInteract(body1, body3) // returns false
*
* // Body 2 has the first and second group and can interact with all other
* // groups, but only if that body also can interact with is custom group.
* canInteract(body2, body1) // returns false (body1 cannot interact with others)
* canInteract(body2, body2) // returns true (identical groups can always interact)
* canInteract(body2, body3) // returns true
*
* // Body 3 has the third group but can interact with the second group.
* // This means that Body 2 and Body 3 can interact with each other but no other
* // body can interact with Body 1 because it doesn't allow interactions with
* // any other custom group.
* canInteract(body3, body1) // returns false (body1 cannot interact with others)
* canInteract(body3, body2) // returns true
* canInteract(body3, body3) // returns true (identical groups can always interact)
*/
function canInteract({ group: groupA }, { group: groupB }) {
return (
Expand Down
Loading

0 comments on commit 829a255

Please sign in to comment.