From 5889cca71710ec6d2f9403cd876baeb846b057f2 Mon Sep 17 00:00:00 2001 From: Gregory Athons Date: Thu, 31 Oct 2024 18:58:09 -0600 Subject: [PATCH] feat: adding `userData` with a type of `any` (#84) --- dist/bodies/circle.d.ts | 4 ++++ dist/bodies/circle.js | 4 ++++ dist/bodies/polygon.d.ts | 4 ++++ dist/bodies/polygon.js | 4 ++++ dist/demo/demo.js | 9 +++++++++ dist/model.d.ts | 4 ++++ dist/utils.js | 1 + src/bodies/circle.ts | 5 +++++ src/bodies/polygon.ts | 5 +++++ src/model.ts | 5 +++++ src/utils.ts | 1 + tslint.json | 2 +- 12 files changed, 47 insertions(+), 1 deletion(-) diff --git a/dist/bodies/circle.d.ts b/dist/bodies/circle.d.ts index 377ac85b..a30777fd 100644 --- a/dist/bodies/circle.d.ts +++ b/dist/bodies/circle.d.ts @@ -66,6 +66,10 @@ export declare class Circle extends SATCircle implements BBox, BodyProps { * was the polygon modified and needs update in the next checkCollision */ dirty: boolean; + /** + * allows the user to set any misc data for client use + */ + userData: null; readonly isConvex = true; /** * circle type diff --git a/dist/bodies/circle.js b/dist/bodies/circle.js index 306c416d..84cd6fe9 100644 --- a/dist/bodies/circle.js +++ b/dist/bodies/circle.js @@ -21,6 +21,10 @@ class Circle extends sat_1.Circle { * was the polygon modified and needs update in the next checkCollision */ this.dirty = false; + /** + * allows the user to set any misc data for client use + */ + this.userData = null; /* * circles are convex */ diff --git a/dist/bodies/polygon.d.ts b/dist/bodies/polygon.d.ts index 33726c2d..3352a231 100644 --- a/dist/bodies/polygon.d.ts +++ b/dist/bodies/polygon.d.ts @@ -65,6 +65,10 @@ export declare class Polygon extends SATPolygon implements BBox, BodyProps { * was the polygon modified and needs update in the next checkCollision */ dirty: boolean; + /** + * allows the user to set any misc data for client use + */ + userData: null; /** * type of body */ diff --git a/dist/bodies/polygon.js b/dist/bodies/polygon.js index 6fe535eb..e40e3098 100644 --- a/dist/bodies/polygon.js +++ b/dist/bodies/polygon.js @@ -28,6 +28,10 @@ class Polygon extends sat_1.Polygon { * was the polygon modified and needs update in the next checkCollision */ this.dirty = false; + /** + * allows the user to set any misc data for client use + */ + this.userData = null; /** * type of body */ diff --git a/dist/demo/demo.js b/dist/demo/demo.js index f8e110ee..754fddd7 100644 --- a/dist/demo/demo.js +++ b/dist/demo/demo.js @@ -2635,6 +2635,10 @@ which is good. See: http://baagoe.com/en/RandomMusings/hash/avalanche.xhtml * was the polygon modified and needs update in the next checkCollision */ this.dirty = false; + /** + * allows the user to set any misc data for client use + */ + this.userData = null; /* * circles are convex */ @@ -3152,6 +3156,10 @@ which is good. See: http://baagoe.com/en/RandomMusings/hash/avalanche.xhtml * was the polygon modified and needs update in the next checkCollision */ this.dirty = false; + /** + * allows the user to set any misc data for client use + */ + this.userData = null; /** * type of body */ @@ -4344,6 +4352,7 @@ which is good. See: http://baagoe.com/en/RandomMusings/hash/avalanche.xhtml // Default value should be reflected in documentation of `BodyOptions.group` body.group = (_a = options.group) !== null && _a !== void 0 ? _a : 0x7fffffff; + body.userData = options.userData || null; if ( body.typeGroup !== model_1.BodyGroup.Circle && options.isCentered diff --git a/dist/model.d.ts b/dist/model.d.ts index 403f6b48..c27aa1ca 100644 --- a/dist/model.d.ts +++ b/dist/model.d.ts @@ -104,6 +104,10 @@ export interface BodyOptions { * @default 0x7fffffff // member of all groups (can interact with everyting) */ group?: number; + /** + * allows the user to set any misc data for client use + */ + userData?: any; } /** * system.raycast(from, to) result diff --git a/dist/utils.js b/dist/utils.js index eccf42c3..c39e12a3 100644 --- a/dist/utils.js +++ b/dist/utils.js @@ -147,6 +147,7 @@ function extendBody(body, options = {}) { 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; + body.userData = options.userData || null; if (body.typeGroup !== model_1.BodyGroup.Circle && options.isCentered) { body.isCentered = true; } diff --git a/src/bodies/circle.ts b/src/bodies/circle.ts index a5494a0c..4f2ceed9 100644 --- a/src/bodies/circle.ts +++ b/src/bodies/circle.ts @@ -89,6 +89,11 @@ export class Circle extends SATCircle implements BBox, BodyProps { */ dirty = false; + /** + * allows the user to set any misc data for client use + */ + userData = null; + /* * circles are convex */ diff --git a/src/bodies/polygon.ts b/src/bodies/polygon.ts index 12d51083..98fe314b 100644 --- a/src/bodies/polygon.ts +++ b/src/bodies/polygon.ts @@ -94,6 +94,11 @@ export class Polygon extends SATPolygon implements BBox, BodyProps { */ dirty = false; + /** + * allows the user to set any misc data for client use + */ + userData = null; + /** * type of body */ diff --git a/src/model.ts b/src/model.ts index 5a1146ec..035c70d1 100644 --- a/src/model.ts +++ b/src/model.ts @@ -125,6 +125,11 @@ export interface BodyOptions { * @default 0x7fffffff // member of all groups (can interact with everyting) */ group?: number; + + /** + * allows the user to set any misc data for client use + */ + userData?: any; } /** diff --git a/src/utils.ts b/src/utils.ts index b077590c..c9fbba01 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -175,6 +175,7 @@ export function extendBody(body: Body, options: BodyOptions = {}): void { body.padding = options.padding || 0; // Default value should be reflected in documentation of `BodyOptions.group` body.group = options.group ?? 0x7fffffff; + body.userData = options.userData || null; if (body.typeGroup !== BodyGroup.Circle && options.isCentered) { body.isCentered = true; diff --git a/tslint.json b/tslint.json index 710047bd..21e48af0 100644 --- a/tslint.json +++ b/tslint.json @@ -4,7 +4,7 @@ "ban-types": [true], "member-access": [true, "no-public"], "member-ordering": [true, { "order": "fields-first" }], - "no-any": true, + "no-any": false, "no-empty-interface": true, "no-import-side-effect": false, "no-inferrable-types": true,