Skip to content

Commit

Permalink
feat: adding userData with a type of any (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmax17 authored Nov 1, 2024
1 parent 829a255 commit 5889cca
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 1 deletion.
4 changes: 4 additions & 0 deletions dist/bodies/circle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions dist/bodies/circle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions dist/bodies/polygon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions dist/bodies/polygon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
9 changes: 9 additions & 0 deletions dist/demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions dist/model.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions dist/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 5 additions & 0 deletions src/bodies/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 5 additions & 0 deletions src/bodies/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 5 additions & 0 deletions src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5889cca

Please sign in to comment.