Skip to content

Commit 4a83b1f

Browse files
committed
chore(cannon): pass linting
1 parent 596330e commit 4a83b1f

File tree

5 files changed

+50
-33
lines changed

5 files changed

+50
-33
lines changed

libs/cannon/.eslintrc.json

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,9 @@
66
"files": ["*.ts"],
77
"extends": ["plugin:@nx/angular", "plugin:@angular-eslint/template/process-inline-templates"],
88
"rules": {
9-
"@angular-eslint/directive-selector": [
10-
"error",
11-
{
12-
"type": "attribute",
13-
"prefix": "lib",
14-
"style": "camelCase"
15-
}
16-
],
17-
"@angular-eslint/component-selector": [
18-
"error",
19-
{
20-
"type": "element",
21-
"prefix": "lib",
22-
"style": "kebab-case"
23-
}
24-
]
9+
"@angular-eslint/directive-class-suffix": "off",
10+
"@angular-eslint/component-class-suffix": "off",
11+
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }]
2512
}
2613
},
2714
{
@@ -33,7 +20,17 @@
3320
"files": ["*.json"],
3421
"parser": "jsonc-eslint-parser",
3522
"rules": {
36-
"@nx/dependency-checks": "error"
23+
"@nx/dependency-checks": ["error", {
24+
"ignoredDependencies": [
25+
"angular-three",
26+
"ngxtension",
27+
"@analogjs/vite-plugin-angular",
28+
"@nx/vite",
29+
"vite",
30+
"@angular/common",
31+
"tslib"
32+
]
33+
}]
3734
}
3835
}
3936
]

libs/cannon/body/src/lib/body.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function injectBody<TShape extends BodyShapeType, TObject extends Object3D>(
5858
if (!_body) return null;
5959
const { worker, ...rest } = physics.api;
6060
if (!worker()) return null;
61-
return makeBodyApi(_body, worker(), physics.api);
61+
return makeBodyApi(_body, worker(), rest);
6262
});
6363

6464
afterNextRender(() => {
@@ -109,7 +109,12 @@ function injectBody<TShape extends BodyShapeType, TObject extends Object3D>(
109109
// Register on mount, unregister on unmount
110110
currentWorker.addBodies({
111111
props: props.map(({ onCollide, onCollideBegin, onCollideEnd, ...serializableProps }) => {
112-
return { onCollide: Boolean(onCollide), ...serializableProps };
112+
return {
113+
onCollide: Boolean(onCollide),
114+
onCollideBegin: Boolean(onCollideBegin),
115+
onCollideEnd: Boolean(onCollideEnd),
116+
...serializableProps,
117+
};
113118
}),
114119
type,
115120
uuid,

libs/cannon/body/src/lib/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function setupCollision(
8484
export function makeBodyApi(
8585
body: Object3D,
8686
worker: CannonWorkerAPI,
87-
{ subscriptions, scaleOverrides }: NgtcPhysicsApi,
87+
{ subscriptions, scaleOverrides }: Pick<NgtcPhysicsApi, 'subscriptions' | 'scaleOverrides'>,
8888
) {
8989
const makeAtomic = <T extends AtomicName>(type: T, index?: number) => {
9090
const op: SetOpName<T> = `set${capitalize(type)}`;
@@ -221,10 +221,10 @@ export function makeBodyApi(
221221
}
222222

223223
export const defaultTransformArgs = {
224-
Plane: (args: PlaneProps['args']) => [],
224+
Plane: (_: PlaneProps['args']) => [],
225225
Box: (args: BoxProps['args'] = [1, 1, 1]) => args,
226226
Trimesh: (args: TrimeshArgs) => args,
227-
Cylinder: (args: CylinderArgs = []) => [],
227+
Cylinder: (_: CylinderArgs = []) => [],
228228
Heightfield: (args: HeightfieldArgs) => args,
229229
ConvexPolyhedron: ([vertices, faces, normals, axes, boundingSphereRadius]: ConvexPolyhedronArgs = []) => [
230230
vertices && vertices.map(makeTriplet),
@@ -233,7 +233,7 @@ export const defaultTransformArgs = {
233233
axes && axes.map(makeTriplet),
234234
boundingSphereRadius,
235235
],
236-
Particle: (args: ParticleProps['args']) => [],
236+
Particle: (_: ParticleProps['args']) => [],
237237
Sphere: (args: SphereArgs = [1]) => {
238238
if (!Array.isArray(args)) throw new Error('Sphere body args must be an array');
239239
return [args[0]];

libs/cannon/constraint/src/lib/constraint.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ function injectConstraint<
7070
type: TConstraint,
7171
bodyA: ElementRef<A> | A | Signal<ElementRef<A> | A | undefined>,
7272
bodyB: ElementRef<B> | B | Signal<ElementRef<B> | B | undefined>,
73-
{ injector, options = {} as any, disableOnStart = false }: NgtcConstraintOptions<TConstraint> = {},
73+
{
74+
injector,
75+
options = {} as NgtcConstraintOptionsMap[TConstraint],
76+
disableOnStart = false,
77+
}: NgtcConstraintOptions<TConstraint> = {},
7478
) {
7579
return assertInjector(injectConstraint, injector, () => {
7680
const physics = inject(NgtcPhysics, { optional: true });

libs/cannon/src/lib/physics.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ import { injectAutoEffect } from 'ngxtension/auto-effect';
3333
import { mergeInputs } from 'ngxtension/inject-inputs';
3434
import { InstancedMesh, Matrix4, Object3D, Quaternion, QuaternionTuple, Vector3 } from 'three';
3535

36+
export interface NgtcCannonWorkerEvents {
37+
collide: WorkerCollideEvent;
38+
collideBegin: WorkerCollideBeginEvent;
39+
collideEnd: WorkerCollideEndEvent;
40+
frame: WorkerFrameMessage;
41+
rayhit: WorkerRayhitEvent;
42+
}
43+
44+
export interface NgtcCannonWorker extends CannonWorkerAPI {
45+
on: <K extends keyof NgtcCannonWorkerEvents>(event: K, cb: (data: NgtcCannonWorkerEvents[K]['data']) => void) => void;
46+
removeAllListeners: () => void;
47+
}
48+
3649
const v = new Vector3();
3750
const s = new Vector3(1, 1, 1);
3851
const q = new Quaternion();
@@ -122,7 +135,8 @@ export class NgtcPhysics {
122135
options = input(defaultOptions, { transform: mergeInputs(defaultOptions) });
123136

124137
private invalidate = this.store.select('invalidate');
125-
private worker = signal<CannonWorkerAPI>(null!);
138+
// @ts-expect-error - worker is not nullable, and we don't want to use ! operator
139+
private worker = signal<CannonWorkerAPI>(null);
126140

127141
api: NgtcPhysicsApi = {
128142
bodies: {},
@@ -155,11 +169,8 @@ export class NgtcPhysics {
155169
}
156170

157171
private connectWorker() {
158-
this.autoEffect((injector) => {
159-
const worker = this.worker() as CannonWorkerAPI & {
160-
on: (event: string, cb: (...args: any[]) => void) => void;
161-
removeAllListeners: () => void;
162-
};
172+
this.autoEffect(() => {
173+
const worker = this.worker() as NgtcCannonWorker;
163174
if (!worker) return;
164175

165176
worker.connect();
@@ -183,7 +194,7 @@ export class NgtcPhysics {
183194

184195
this.autoEffect(() => {
185196
const [worker, value] = [untracked(this.worker), computedValue()];
186-
// @ts-expect-error
197+
// @ts-expect-error - we know key is a valid key of CannonWorkerAPI
187198
worker[key] = value;
188199
});
189200
}
@@ -193,9 +204,9 @@ export class NgtcPhysics {
193204
injectBeforeRender(
194205
({ delta }) => {
195206
const [{ isPaused, maxSubSteps, stepSize }, worker] = [this.options(), this.worker()];
196-
if (isPaused || !worker) return;
207+
if (isPaused || !worker || stepSize == null) return;
197208
timeSinceLastCalled += delta;
198-
worker.step({ maxSubSteps, stepSize: stepSize!, timeSinceLastCalled });
209+
worker.step({ maxSubSteps, stepSize, timeSinceLastCalled });
199210
timeSinceLastCalled = 0;
200211
},
201212
{ injector: this.injector },

0 commit comments

Comments
 (0)