From c6abfc5433bc4733b243bcda8ceff8ec8225ae92 Mon Sep 17 00:00:00 2001 From: D8H Date: Wed, 27 Jul 2022 09:47:32 +0200 Subject: [PATCH] Add type definitions on the Physics2 extension (#4147) --- Extensions/Physics2Behavior/box2d.d.ts | 1804 ++++++++++++++++- .../physics2runtimebehavior.ts | 1288 +++++++----- 2 files changed, 2566 insertions(+), 526 deletions(-) diff --git a/Extensions/Physics2Behavior/box2d.d.ts b/Extensions/Physics2Behavior/box2d.d.ts index 08e0b867f9..90b4674127 100644 --- a/Extensions/Physics2Behavior/box2d.d.ts +++ b/Extensions/Physics2Behavior/box2d.d.ts @@ -1,2 +1,1804 @@ // TODO: Improve type checking by using proper typings for Box2D. -declare var Box2D: any; +// It comes from a TypeScript port of box2d 2.4.1: https://github.com/Birch-san/box2d-wasm +// We use a port of box2d 2.3.1 from: https://github.com/kripken/box2d.js/tree/b0e491ce91f05b5390d86655ad6cf3102fabdb95/build + +// As the versions don't match, some adaptations were made. +// Sources must be checked if there is any doubt. + +declare namespace Box2D { + export function _free(object: any): void; + export function _malloc(size: number, type: string, stack: any): any; + export const ALLOC_STACK: any; + export const HEAPF32: any[]; + export class b2Contact extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Contact; + }; + protected readonly __class__: typeof b2Contact; + GetManifold(): b2Manifold; + GetWorldManifold(manifold: b2WorldManifold | number): void; + IsTouching(): boolean; + SetEnabled(flag: boolean): void; + IsEnabled(): boolean; + GetNext(): b2Contact; + GetFixtureA(): b2Fixture; + GetChildIndexA(): number; + GetFixtureB(): b2Fixture; + GetChildIndexB(): number; + SetFriction(friction: number): void; + GetFriction(): number; + ResetFriction(): void; + SetRestitution(restitution: number): void; + GetRestitution(): number; + ResetRestitution(): void; + SetRestitutionThreshold(threshold: number): void; + GetRestitutionThreshold(): number; + ResetRestitutionThreshold(): void; + SetTangentSpeed(speed: number): void; + GetTangentSpeed(): number; + } + export class b2ContactListener extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2ContactListener; + }; + protected readonly __class__: typeof b2ContactListener; + __destroy__(): void; + } + export class JSContactListener extends b2ContactListener { + protected static readonly __cache__: { + [ptr: number]: JSContactListener; + }; + protected readonly __class__: typeof JSContactListener; + __destroy__(): void; + protected ptr: number; + BeginContact(contact: b2Contact | number): void; + EndContact(contact: b2Contact | number): void; + PreSolve( + contact: b2Contact | number, + oldManifold: b2Manifold | number + ): void; + PostSolve( + contact: b2Contact | number, + impulse: b2ContactImpulse | number + ): void; + } + export class b2World extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2World; + }; + protected readonly __class__: typeof b2World; + __destroy__(): void; + protected ptr: number; + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(gravity: b2Vec2 | number); + SetDestructionListener(listener: b2DestructionListener | number): void; + SetContactFilter(filter: JSContactFilter | number): void; + SetContactListener(listener: JSContactListener | number): void; + SetDebugDraw(debugDraw: b2Draw | number): void; + CreateBody(def: b2BodyDef | number): b2Body; + DestroyBody(body: b2Body | number): void; + CreateJoint(def: b2JointDef | number): b2Joint; + DestroyJoint(joint: b2Joint | number): void; + Step( + timeStep: number, + velocityIterations: number, + positionIterations: number + ): void; + ClearForces(): void; + DebugDraw(): void; + QueryAABB(callback: b2QueryCallback | number, aabb: b2AABB | number): void; + RayCast( + callback: b2RayCastCallback | number, + point1: b2Vec2 | number, + point2: b2Vec2 | number + ): void; + GetBodyList(): b2Body; + GetJointList(): b2Joint; + GetContactList(): b2Contact; + SetAllowSleeping(flag: boolean): void; + GetAllowSleeping(): boolean; + SetWarmStarting(flag: boolean): void; + GetWarmStarting(): boolean; + SetContinuousPhysics(flag: boolean): void; + GetContinuousPhysics(): boolean; + SetSubStepping(flag: boolean): void; + GetSubStepping(): boolean; + GetProxyCount(): number; + GetBodyCount(): number; + GetJointCount(): number; + GetContactCount(): number; + GetTreeHeight(): number; + GetTreeBalance(): number; + GetTreeQuality(): number; + SetGravity(gravity: b2Vec2 | number): void; + GetGravity(): b2Vec2; + IsLocked(): boolean; + SetAutoClearForces(flag: boolean): void; + GetAutoClearForces(): boolean; + GetProfile(): b2Profile; + Dump(): void; + } + export namespace b2Shape { + const e_circle: number; + const e_edge: number; + const e_polygon: number; + const e_chain: number; + const e_typeCount: number; + } + export class b2Shape extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Shape; + }; + protected readonly __class__: typeof b2Shape; + __destroy__(): void; + GetType(): number; + GetChildCount(): number; + TestPoint(xf: b2Transform | number, p: b2Vec2 | number): boolean; + RayCast( + output: b2RayCastOutput | number, + input: b2RayCastInput | number, + transform: b2Transform | number, + childIndex: number + ): boolean; + ComputeAABB( + aabb: b2AABB | number, + xf: b2Transform | number, + childIndex: number + ): void; + ComputeMass(massData: b2MassData | number, density: number): void; + m_type: number; + get_m_type(): number; + set_m_type(m_type: number): void; + m_radius: number; + get_m_radius(): number; + set_m_radius(m_radius: number): void; + } + export class b2FixtureUserData extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2FixtureUserData; + }; + protected readonly __class__: typeof b2FixtureUserData; + __destroy__(): void; + pointer: number; + get_pointer(): number; + set_pointer(pointer: number): void; + } + export class b2FixtureDef extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2FixtureDef; + }; + protected readonly __class__: typeof b2FixtureDef; + __destroy__(): void; + protected ptr: number; + shape: b2Shape; + get_shape(): b2Shape; + set_shape(shape: b2Shape): void; + userData: b2FixtureUserData; + get_userData(): b2FixtureUserData; + set_userData(userData: b2FixtureUserData): void; + friction: number; + get_friction(): number; + set_friction(friction: number): void; + restitution: number; + get_restitution(): number; + set_restitution(restitution: number): void; + restitutionThreshold: number; + get_restitutionThreshold(): number; + set_restitutionThreshold(restitutionThreshold: number): void; + density: number; + get_density(): number; + set_density(density: number): void; + isSensor: boolean; + get_isSensor(): boolean; + set_isSensor(isSensor: boolean): void; + filter: b2Filter; + get_filter(): b2Filter; + set_filter(filter: b2Filter): void; + } + export class b2Fixture extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Fixture; + }; + protected readonly __class__: typeof b2Fixture; + __destroy__(): void; + GetType(): number; + GetShape(): b2Shape; + SetSensor(sensor: boolean): void; + IsSensor(): boolean; + SetFilterData(filter: b2Filter | number): void; + GetFilterData(): b2Filter; + Refilter(): void; + GetBody(): b2Body; + GetNext(): b2Fixture; + GetUserData(): b2FixtureUserData; + TestPoint(p: b2Vec2 | number): boolean; + RayCast( + output: b2RayCastOutput | number, + input: b2RayCastInput | number, + childIndex: number + ): boolean; + GetMassData(massData: b2MassData | number): void; + SetDensity(density: number): void; + GetDensity(): number; + GetFriction(): number; + SetFriction(friction: number): void; + GetRestitution(): number; + SetRestitution(restitution: number): void; + GetRestitutionThreshold(): number; + SetRestitutionThreshold(threshold: number): void; + GetAABB(childIndex: number): b2AABB; + Dump(bodyIndex: number): void; + } + export class b2Transform extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Transform; + }; + protected readonly __class__: typeof b2Transform; + __destroy__(): void; + protected ptr: number; + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(position: b2Vec2 | number, rotation: b2Rot | number); + SetIdentity(): void; + Set(position: b2Vec2 | number, angle: number): void; + p: b2Vec2; + get_p(): b2Vec2; + set_p(p: b2Vec2): void; + q: b2Rot; + get_q(): b2Rot; + set_q(q: b2Rot): void; + } + export class b2RayCastCallback extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2RayCastCallback; + }; + protected readonly __class__: typeof b2RayCastCallback; + __destroy__(): void; + } + export class JSRayCastCallback extends b2RayCastCallback { + protected static readonly __cache__: { + [ptr: number]: JSRayCastCallback; + }; + protected readonly __class__: typeof JSRayCastCallback; + __destroy__(): void; + protected ptr: number; + ReportFixture( + fixture: b2Fixture | number, + point: b2Vec2 | number, + normal: b2Vec2 | number, + fraction: number + ): number; + } + export class b2QueryCallback extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2QueryCallback; + }; + protected readonly __class__: typeof b2QueryCallback; + __destroy__(): void; + } + export class JSQueryCallback extends b2QueryCallback { + protected static readonly __cache__: { + [ptr: number]: JSQueryCallback; + }; + protected readonly __class__: typeof JSQueryCallback; + __destroy__(): void; + protected ptr: number; + ReportFixture(fixture: b2Fixture | number): boolean; + } + export class b2MassData extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2MassData; + }; + protected readonly __class__: typeof b2MassData; + __destroy__(): void; + protected ptr: number; + mass: number; + get_mass(): number; + set_mass(mass: number): void; + center: b2Vec2; + get_center(): b2Vec2; + set_center(center: b2Vec2): void; + I: number; + get_I(): number; + set_I(I: number): void; + } + export class b2Vec2 extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Vec2; + }; + protected readonly __class__: typeof b2Vec2; + __destroy__(): void; + protected ptr: number; + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(x: number, y: number); + SetZero(): void; + Set(x: number, y: number): void; + op_add(v: b2Vec2 | number): void; + op_sub(v: b2Vec2 | number): void; + op_mul(s: number): void; + Length(): number; + LengthSquared(): number; + Normalize(): number; + IsValid(): boolean; + Skew(): b2Vec2; + x: number; + get_x(): number; + set_x(x: number): void; + y: number; + get_y(): number; + set_y(y: number): void; + } + export class b2Vec3 extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Vec3; + }; + protected readonly __class__: typeof b2Vec3; + __destroy__(): void; + protected ptr: number; + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(x: number, y: number, z: number); + SetZero(): void; + Set(x: number, y: number, z: number): void; + op_add(v: b2Vec3 | number): void; + op_sub(v: b2Vec3 | number): void; + op_mul(s: number): void; + x: number; + get_x(): number; + set_x(x: number): void; + y: number; + get_y(): number; + set_y(y: number): void; + z: number; + get_z(): number; + set_z(z: number): void; + } + export class b2BodyUserData extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2BodyUserData; + }; + protected readonly __class__: typeof b2BodyUserData; + __destroy__(): void; + pointer: number; + get_pointer(): number; + set_pointer(pointer: number): void; + } + export class b2Body extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Body; + }; + protected readonly __class__: typeof b2Body; + CreateFixture(def: b2FixtureDef | number): b2Fixture; + CreateFixture(shape: b2Shape | number, density: number): b2Fixture; + DestroyFixture(fixture: b2Fixture | number): void; + SetTransform(position: b2Vec2 | number, angle: number): void; + GetTransform(): b2Transform; + GetPosition(): b2Vec2; + GetAngle(): number; + GetWorldCenter(): b2Vec2; + GetLocalCenter(): b2Vec2; + SetLinearVelocity(v: b2Vec2 | number): void; + GetLinearVelocity(): b2Vec2; + SetAngularVelocity(omega: number): void; + GetAngularVelocity(): number; + ApplyForce( + force: b2Vec2 | number, + point: b2Vec2 | number, + wake: boolean + ): void; + ApplyForceToCenter(force: b2Vec2 | number, wake: boolean): void; + ApplyTorque(torque: number, awake: boolean): void; + ApplyLinearImpulse( + impulse: b2Vec2 | number, + point: b2Vec2 | number, + wake: boolean + ): void; + ApplyLinearImpulseToCenter(impulse: b2Vec2 | number, wake: boolean): void; + ApplyAngularImpulse(impulse: number, wake: boolean): void; + GetMass(): number; + GetInertia(): number; + GetMassData(data: b2MassData | number): void; + SetMassData(data: b2MassData | number): void; + ResetMassData(): void; + GetWorldPoint(localPoint: b2Vec2 | number): b2Vec2; + GetWorldVector(localVector: b2Vec2 | number): b2Vec2; + GetLocalPoint(worldPoint: b2Vec2 | number): b2Vec2; + GetLocalVector(worldVector: b2Vec2 | number): b2Vec2; + GetLinearVelocityFromWorldPoint(worldPoint: b2Vec2 | number): b2Vec2; + GetLinearVelocityFromLocalPoint(localPoint: b2Vec2 | number): b2Vec2; + GetLinearDamping(): number; + SetLinearDamping(linearDamping: number): void; + GetAngularDamping(): number; + SetAngularDamping(angularDamping: number): void; + GetGravityScale(): number; + SetGravityScale(scale: number): void; + SetType(type: number | number): void; + GetType(): number; + SetBullet(flag: boolean): void; + IsBullet(): boolean; + SetSleepingAllowed(flag: boolean): void; + IsSleepingAllowed(): boolean; + SetAwake(flag: boolean): void; + IsAwake(): boolean; + SetEnabled(flag: boolean): void; + IsEnabled(): boolean; + SetFixedRotation(flag: boolean): void; + IsFixedRotation(): boolean; + GetFixtureList(): b2Fixture; + GetJointList(): b2JointEdge; + GetContactList(): b2ContactEdge; + GetNext(): b2Body; + GetUserData(): b2BodyUserData; + GetWorld(): b2World; + Dump(): void; + } + const b2_staticBody: number; + const b2_kinematicBody: number; + const b2_dynamicBody: number; + export class b2BodyDef extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2BodyDef; + }; + protected readonly __class__: typeof b2BodyDef; + __destroy__(): void; + protected ptr: number; + type: number; + get_type(): number; + set_type(type: number): void; + position: b2Vec2; + get_position(): b2Vec2; + set_position(position: b2Vec2): void; + angle: number; + get_angle(): number; + set_angle(angle: number): void; + linearVelocity: b2Vec2; + get_linearVelocity(): b2Vec2; + set_linearVelocity(linearVelocity: b2Vec2): void; + angularVelocity: number; + get_angularVelocity(): number; + set_angularVelocity(angularVelocity: number): void; + linearDamping: number; + get_linearDamping(): number; + set_linearDamping(linearDamping: number): void; + angularDamping: number; + get_angularDamping(): number; + set_angularDamping(angularDamping: number): void; + allowSleep: boolean; + get_allowSleep(): boolean; + set_allowSleep(allowSleep: boolean): void; + awake: boolean; + get_awake(): boolean; + set_awake(awake: boolean): void; + fixedRotation: boolean; + get_fixedRotation(): boolean; + set_fixedRotation(fixedRotation: boolean): void; + bullet: boolean; + get_bullet(): boolean; + set_bullet(bullet: boolean): void; + enabled: boolean; + get_enabled(): boolean; + set_enabled(enabled: boolean): void; + userData: b2BodyUserData; + get_userData(): b2BodyUserData; + set_userData(userData: b2BodyUserData): void; + gravityScale: number; + get_gravityScale(): number; + set_gravityScale(gravityScale: number): void; + } + export class b2Filter extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Filter; + }; + protected readonly __class__: typeof b2Filter; + __destroy__(): void; + protected ptr: number; + categoryBits: number; + get_categoryBits(): number; + set_categoryBits(categoryBits: number): void; + maskBits: number; + get_maskBits(): number; + set_maskBits(maskBits: number): void; + groupIndex: number; + get_groupIndex(): number; + set_groupIndex(groupIndex: number): void; + } + export class b2AABB extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2AABB; + }; + protected readonly __class__: typeof b2AABB; + __destroy__(): void; + protected ptr: number; + IsValid(): boolean; + GetCenter(): b2Vec2; + GetExtents(): b2Vec2; + GetPerimeter(): number; + Combine(aabb: b2AABB | number): void; + Combine(aabb1: b2AABB | number, aabb2: b2AABB | number): void; + Contains(aabb: b2AABB | number): boolean; + RayCast( + output: b2RayCastOutput | number, + input: b2RayCastInput | number + ): boolean; + lowerBound: b2Vec2; + get_lowerBound(): b2Vec2; + set_lowerBound(lowerBound: b2Vec2): void; + upperBound: b2Vec2; + get_upperBound(): b2Vec2; + set_upperBound(upperBound: b2Vec2): void; + } + export class b2CircleShape extends b2Shape { + protected static readonly __cache__: { + [ptr: number]: b2CircleShape; + }; + protected readonly __class__: typeof b2CircleShape; + __destroy__(): void; + protected ptr: number; + m_p: b2Vec2; + get_m_p(): b2Vec2; + set_m_p(m_p: b2Vec2): void; + } + export class b2EdgeShape extends b2Shape { + protected static readonly __cache__: { + [ptr: number]: b2EdgeShape; + }; + protected readonly __class__: typeof b2EdgeShape; + __destroy__(): void; + protected ptr: number; + SetOneSided( + v0: b2Vec2 | number, + v1: b2Vec2 | number, + v2: b2Vec2 | number, + v3: b2Vec2 | number + ): void; + SetTwoSided(v1: b2Vec2 | number, v2: b2Vec2 | number): void; + m_vertex1: b2Vec2; + get_m_vertex1(): b2Vec2; + set_m_vertex1(m_vertex1: b2Vec2): void; + m_vertex2: b2Vec2; + get_m_vertex2(): b2Vec2; + set_m_vertex2(m_vertex2: b2Vec2): void; + m_vertex0: b2Vec2; + get_m_vertex0(): b2Vec2; + set_m_vertex0(m_vertex0: b2Vec2): void; + m_vertex3: b2Vec2; + get_m_vertex3(): b2Vec2; + set_m_vertex3(m_vertex3: b2Vec2): void; + m_oneSided: boolean; + get_m_oneSided(): boolean; + set_m_oneSided(m_oneSided: boolean): void; + } + const e_unknownJoint: number; + const e_revoluteJoint: number; + const e_prismaticJoint: number; + const e_distanceJoint: number; + const e_pulleyJoint: number; + const e_mouseJoint: number; + const e_gearJoint: number; + const e_wheelJoint: number; + const e_weldJoint: number; + const e_frictionJoint: number; + const e_ropeJoint: number; + const e_motorJoint: number; + export class b2JointUserData extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2JointUserData; + }; + protected readonly __class__: typeof b2JointUserData; + __destroy__(): void; + pointer: number; + get_pointer(): number; + set_pointer(pointer: number): void; + } + export class b2JointDef extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2JointDef; + }; + protected readonly __class__: typeof b2JointDef; + __destroy__(): void; + type: number; + get_type(): number; + set_type(type: number): void; + userData: b2JointUserData; + get_userData(): b2JointUserData; + set_userData(userData: b2JointUserData): void; + bodyA: b2Body; + get_bodyA(): b2Body; + set_bodyA(bodyA: b2Body): void; + bodyB: b2Body; + get_bodyB(): b2Body; + set_bodyB(bodyB: b2Body): void; + collideConnected: boolean; + get_collideConnected(): boolean; + set_collideConnected(collideConnected: boolean): void; + set_dampingRatio(dampingRatio: number): void; + set_frequencyHz(frequencyHz: number): void; + } + export class b2Joint extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Joint; + }; + protected readonly __class__: typeof b2Joint; + GetType(): number; + GetBodyA(): b2Body; + GetBodyB(): b2Body; + GetAnchorA(): b2Vec2; + GetAnchorB(): b2Vec2; + GetReactionForce(inv_dt: number): b2Vec2; + GetReactionTorque(inv_dt: number): number; + GetNext(): b2Joint; + GetUserData(): b2JointUserData; + GetCollideConnected(): boolean; + Dump(): void; + } + export class b2WeldJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2WeldJoint; + }; + protected readonly __class__: typeof b2WeldJoint; + __destroy__(): void; + GetLocalAnchorA(): b2Vec2; + GetLocalAnchorB(): b2Vec2; + GetReferenceAngle(): number; + GetFrequency(): number; + SetFrequency(frequency: number): void; + GetDampingRatio(): number; + SetDampingRatio(dampingRatio: number): void; + Dump(): void; + } + export class b2WeldJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2WeldJointDef; + }; + protected readonly __class__: typeof b2WeldJointDef; + __destroy__(): void; + protected ptr: number; + Initialize( + bodyA: b2Body | number, + bodyB: b2Body | number, + anchor: b2Vec2 | number + ): void; + localAnchorA: b2Vec2; + get_localAnchorA(): b2Vec2; + set_localAnchorA(localAnchorA: b2Vec2): void; + localAnchorB: b2Vec2; + get_localAnchorB(): b2Vec2; + set_localAnchorB(localAnchorB: b2Vec2): void; + referenceAngle: number; + get_referenceAngle(): number; + set_referenceAngle(referenceAngle: number): void; + frequencyHz: number; + get_frequencyHz(): number; + set_frequencyHz(frequencyHz: number): void; + dampingRatio: number; + get_dampingRatio(): number; + set_dampingRatio(dampingRatio: number): void; + } + export class b2RopeJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2RopeJoint; + }; + protected readonly __class__: typeof b2RopeJoint; + __destroy__(): void; + GetLocalAnchorA(): b2Vec2; + GetLocalAnchorB(): b2Vec2; + GetMaxLength(): number; + SetMaxLength(maxLength: number): void; + Dump(): void; + } + export class b2RopeJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2RopeJointDef; + }; + protected readonly __class__: typeof b2RopeJointDef; + __destroy__(): void; + protected ptr: number; + Initialize( + bodyA: b2Body | number, + bodyB: b2Body | number, + anchor: b2Vec2 | number + ): void; + localAnchorA: b2Vec2; + get_localAnchorA(): b2Vec2; + set_localAnchorA(localAnchorA: b2Vec2): void; + localAnchorB: b2Vec2; + get_localAnchorB(): b2Vec2; + set_localAnchorB(localAnchorB: b2Vec2): void; + maxLength: number; + get_maxLength(): number; + set_maxLength(maxLength: number): void; + length: number; + get_length(): number; + set_length(length: number): void; + impulse: number; + get_impulse(): number; + set_impulse(impulse: number): void; + } + export class b2ChainShape extends b2Shape { + protected static readonly __cache__: { + [ptr: number]: b2ChainShape; + }; + protected readonly __class__: typeof b2ChainShape; + __destroy__(): void; + protected ptr: number; + Clear(): void; + CreateLoop(vertices: b2Vec2 | number, count: number): void; + CreateChain( + vertices: b2Vec2 | number, + count: number, + prevVertex: b2Vec2 | number, + nextVertex: b2Vec2 | number + ): void; + GetChildEdge(edge: b2EdgeShape | number, index: number): void; + m_vertices: b2Vec2; + get_m_vertices(): b2Vec2; + set_m_vertices(m_vertices: b2Vec2): void; + m_count: number; + get_m_count(): number; + set_m_count(m_count: number): void; + m_prevVertex: b2Vec2; + get_m_prevVertex(): b2Vec2; + set_m_prevVertex(m_prevVertex: b2Vec2): void; + m_nextVertex: b2Vec2; + get_m_nextVertex(): b2Vec2; + set_m_nextVertex(m_nextVertex: b2Vec2): void; + } + export class b2Color extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Color; + }; + protected readonly __class__: typeof b2Color; + __destroy__(): void; + protected ptr: number; + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(r: number, g: number, b: number); + Set(ri: number, gi: number, bi: number): void; + r: number; + get_r(): number; + set_r(r: number): void; + g: number; + get_g(): number; + set_g(g: number): void; + b: number; + get_b(): number; + set_b(b: number): void; + } + export class b2ContactEdge extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2ContactEdge; + }; + protected readonly __class__: typeof b2ContactEdge; + __destroy__(): void; + protected ptr: number; + other: b2Body; + get_other(): b2Body; + set_other(other: b2Body): void; + contact: b2Contact; + get_contact(): b2Contact; + set_contact(contact: b2Contact): void; + prev: b2ContactEdge; + get_prev(): b2ContactEdge; + set_prev(prev: b2ContactEdge): void; + next: b2ContactEdge; + get_next(): b2ContactEdge; + set_next(next: b2ContactEdge): void; + } + export namespace b2ContactFeature { + const e_vertex: number; + const e_face: number; + } + export class b2ContactFeature extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2ContactFeature; + }; + protected readonly __class__: typeof b2ContactFeature; + __destroy__(): void; + indexA: number; + get_indexA(): number; + set_indexA(indexA: number): void; + indexB: number; + get_indexB(): number; + set_indexB(indexB: number): void; + typeA: number; + get_typeA(): number; + set_typeA(typeA: number): void; + typeB: number; + get_typeB(): number; + set_typeB(typeB: number): void; + } + export class b2ContactFilter extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2ContactFilter; + }; + protected readonly __class__: typeof b2ContactFilter; + __destroy__(): void; + } + export class JSContactFilter extends b2ContactFilter { + protected static readonly __cache__: { + [ptr: number]: JSContactFilter; + }; + protected readonly __class__: typeof JSContactFilter; + __destroy__(): void; + protected ptr: number; + ShouldCollide( + fixtureA: b2Fixture | number, + fixtureB: b2Fixture | number + ): boolean; + } + export class b2ContactID extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2ContactID; + }; + protected readonly __class__: typeof b2ContactID; + __destroy__(): void; + cf: b2ContactFeature; + get_cf(): b2ContactFeature; + set_cf(cf: b2ContactFeature): void; + key: number; + get_key(): number; + set_key(key: number): void; + } + export class b2ContactImpulse extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2ContactImpulse; + }; + protected readonly __class__: typeof b2ContactImpulse; + __destroy__(): void; + normalImpulses: number; + get_normalImpulses(index?: number): number; + set_normalImpulses(index: number, normalImpulses_elem: number): void; + tangentImpulses: number; + get_tangentImpulses(index?: number): number; + set_tangentImpulses(index: number, tangentImpulses_elem: number): void; + count: number; + get_count(): number; + set_count(count: number): void; + } + export class b2DestructionListener extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2DestructionListener; + }; + protected readonly __class__: typeof b2DestructionListener; + __destroy__(): void; + } + export class b2DestructionListenerWrapper extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2DestructionListenerWrapper; + }; + protected readonly __class__: typeof b2DestructionListenerWrapper; + __destroy__(): void; + } + export class JSDestructionListener extends b2DestructionListenerWrapper { + protected static readonly __cache__: { + [ptr: number]: JSDestructionListener; + }; + protected readonly __class__: typeof JSDestructionListener; + __destroy__(): void; + protected ptr: number; + SayGoodbyeJoint(joint: b2Joint | number): void; + SayGoodbyeFixture(joint: b2Fixture | number): void; + } + export class b2DistanceJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2DistanceJoint; + }; + protected readonly __class__: typeof b2DistanceJoint; + __destroy__(): void; + GetLocalAnchorA(): b2Vec2; + GetLocalAnchorB(): b2Vec2; + GetLength(): number; + SetLength(length: number): void; + GetFrequency(): number; + SetFrequency(frequency: number): void; + GetDampingRatio(): number; + SetDampingRatio(dampingRatio: number): void; + } + export class b2DistanceJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2DistanceJointDef; + }; + protected readonly __class__: typeof b2DistanceJointDef; + __destroy__(): void; + protected ptr: number; + Initialize( + bodyA: b2Body | number, + bodyB: b2Body | number, + anchorA: b2Vec2 | number, + anchorB: b2Vec2 | number + ): void; + localAnchorA: b2Vec2; + get_localAnchorA(): b2Vec2; + set_localAnchorA(localAnchorA: b2Vec2): void; + localAnchorB: b2Vec2; + get_localAnchorB(): b2Vec2; + set_localAnchorB(localAnchorB: b2Vec2): void; + length: number; + get_length(): number; + set_length(length: number): void; + frequencyHz: number; + get_frequencyHz(): number; + set_frequencyHz(frequencyHz: number): void; + dampingRatio: number; + get_dampingRatio(): number; + set_dampingRatio(dampingRatio: number): void; + } + export namespace b2Draw { + const e_shapeBit: number; + const e_jointBit: number; + const e_aabbBit: number; + const e_pairBit: number; + const e_centerOfMassBit: number; + } + export class b2Draw extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Draw; + }; + protected readonly __class__: typeof b2Draw; + __destroy__(): void; + SetFlags(flags: number): void; + GetFlags(): number; + AppendFlags(flags: number): void; + ClearFlags(flags: number): void; + } + export class JSDraw extends b2Draw { + protected static readonly __cache__: { + [ptr: number]: JSDraw; + }; + protected readonly __class__: typeof JSDraw; + __destroy__(): void; + protected ptr: number; + DrawPolygon( + vertices: b2Vec2 | number, + vertexCount: number, + color: b2Color | number + ): void; + DrawSolidPolygon( + vertices: b2Vec2 | number, + vertexCount: number, + color: b2Color | number + ): void; + DrawCircle( + center: b2Vec2 | number, + radius: number, + color: b2Color | number + ): void; + DrawSolidCircle( + center: b2Vec2 | number, + radius: number, + axis: b2Vec2 | number, + color: b2Color | number + ): void; + DrawSegment( + p1: b2Vec2 | number, + p2: b2Vec2 | number, + color: b2Color | number + ): void; + DrawTransform(xf: b2Transform | number): void; + DrawPoint(p: b2Vec2 | number, size: number, color: b2Color | number): void; + } + export class b2FrictionJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2FrictionJoint; + }; + protected readonly __class__: typeof b2FrictionJoint; + __destroy__(): void; + GetLocalAnchorA(): b2Vec2; + GetLocalAnchorB(): b2Vec2; + SetMaxForce(force: number): void; + GetMaxForce(): number; + SetMaxTorque(torque: number): void; + GetMaxTorque(): number; + } + export class b2FrictionJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2FrictionJointDef; + }; + protected readonly __class__: typeof b2FrictionJointDef; + __destroy__(): void; + protected ptr: number; + Initialize( + bodyA: b2Body | number, + bodyB: b2Body | number, + anchor: b2Vec2 | number + ): void; + localAnchorA: b2Vec2; + get_localAnchorA(): b2Vec2; + set_localAnchorA(localAnchorA: b2Vec2): void; + localAnchorB: b2Vec2; + get_localAnchorB(): b2Vec2; + set_localAnchorB(localAnchorB: b2Vec2): void; + maxForce: number; + get_maxForce(): number; + set_maxForce(maxForce: number): void; + maxTorque: number; + get_maxTorque(): number; + set_maxTorque(maxTorque: number): void; + } + export class b2GearJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2GearJoint; + }; + protected readonly __class__: typeof b2GearJoint; + __destroy__(): void; + GetJoint1(): b2Joint; + GetJoint2(): b2Joint; + SetRatio(ratio: number): void; + GetRatio(): number; + } + export class b2GearJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2GearJointDef; + }; + protected readonly __class__: typeof b2GearJointDef; + __destroy__(): void; + protected ptr: number; + joint1: b2Joint; + get_joint1(): b2Joint; + set_joint1(joint1: b2Joint): void; + joint2: b2Joint; + get_joint2(): b2Joint; + set_joint2(joint2: b2Joint): void; + ratio: number; + get_ratio(): number; + set_ratio(ratio: number): void; + } + export class b2JointEdge extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2JointEdge; + }; + protected readonly __class__: typeof b2JointEdge; + __destroy__(): void; + protected ptr: number; + other: b2Body; + get_other(): b2Body; + set_other(other: b2Body): void; + joint: b2Joint; + get_joint(): b2Joint; + set_joint(joint: b2Joint): void; + prev: b2JointEdge; + get_prev(): b2JointEdge; + set_prev(prev: b2JointEdge): void; + next: b2JointEdge; + get_next(): b2JointEdge; + set_next(next: b2JointEdge): void; + } + export namespace b2Manifold { + const e_circles: number; + const e_faceA: number; + const e_faceB: number; + } + export class b2Manifold extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Manifold; + }; + protected readonly __class__: typeof b2Manifold; + __destroy__(): void; + protected ptr: number; + points: b2ManifoldPoint; + get_points(index?: number): b2ManifoldPoint; + set_points(index: number, points_elem: b2ManifoldPoint): void; + localNormal: b2Vec2; + get_localNormal(): b2Vec2; + set_localNormal(localNormal: b2Vec2): void; + localPoint: b2Vec2; + get_localPoint(): b2Vec2; + set_localPoint(localPoint: b2Vec2): void; + type: number; + get_type(): number; + set_type(type: number): void; + pointCount: number; + get_pointCount(): number; + set_pointCount(pointCount: number): void; + } + export class b2WorldManifold extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2WorldManifold; + }; + protected readonly __class__: typeof b2WorldManifold; + __destroy__(): void; + protected ptr: number; + Initialize( + manifold: b2Manifold | number, + xfA: b2Transform | number, + radiusA: number, + xfB: b2Transform | number, + radiusB: number + ): void; + normal: b2Vec2; + get_normal(): b2Vec2; + set_normal(normal: b2Vec2): void; + points: b2Vec2; + get_points(index?: number): b2Vec2; + set_points(index: number, points_elem: b2Vec2): void; + separations: number; + get_separations(index?: number): number; + set_separations(index: number, separations_elem: number): void; + } + export class b2ManifoldPoint extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2ManifoldPoint; + }; + protected readonly __class__: typeof b2ManifoldPoint; + __destroy__(): void; + protected ptr: number; + localPoint: b2Vec2; + get_localPoint(): b2Vec2; + set_localPoint(localPoint: b2Vec2): void; + normalImpulse: number; + get_normalImpulse(): number; + set_normalImpulse(normalImpulse: number): void; + tangentImpulse: number; + get_tangentImpulse(): number; + set_tangentImpulse(tangentImpulse: number): void; + id: b2ContactID; + get_id(): b2ContactID; + set_id(id: b2ContactID): void; + } + export class b2Mat22 extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Mat22; + }; + protected readonly __class__: typeof b2Mat22; + __destroy__(): void; + protected ptr: number; + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(c1: b2Vec2 | number, c2: b2Vec2 | number); + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(a11: number, a12: number, a21: number, a22: number); + Set(c1: b2Vec2 | number, c2: b2Vec2 | number): void; + SetIdentity(): void; + SetZero(): void; + GetInverse(): b2Mat22; + Solve(b: b2Vec2 | number): b2Vec2; + ex: b2Vec2; + get_ex(): b2Vec2; + set_ex(ex: b2Vec2): void; + ey: b2Vec2; + get_ey(): b2Vec2; + set_ey(ey: b2Vec2): void; + } + export class b2Mat33 extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Mat33; + }; + protected readonly __class__: typeof b2Mat33; + __destroy__(): void; + protected ptr: number; + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(c1: b2Vec3 | number, c2: b2Vec3 | number, c3: b2Vec3 | number); + SetZero(): void; + Solve33(b: b2Vec3 | number): b2Vec3; + Solve22(b: b2Vec2 | number): b2Vec2; + GetInverse22(M: b2Mat33 | number): void; + GetSymInverse33(M: b2Mat33 | number): void; + ex: b2Vec3; + get_ex(): b2Vec3; + set_ex(ex: b2Vec3): void; + ey: b2Vec3; + get_ey(): b2Vec3; + set_ey(ey: b2Vec3): void; + ez: b2Vec3; + get_ez(): b2Vec3; + set_ez(ez: b2Vec3): void; + } + export class b2MouseJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2MouseJoint; + }; + protected readonly __class__: typeof b2MouseJoint; + __destroy__(): void; + SetTarget(target: b2Vec2 | number): void; + GetTarget(): b2Vec2; + SetMaxForce(force: number): void; + GetMaxForce(): number; + GetFrequency(): number; + SetFrequency(frequency: number): void; + GetDampingRatio(): number; + SetDampingRatio(dampingRatio: number): void; + } + export class b2MouseJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2MouseJointDef; + }; + protected readonly __class__: typeof b2MouseJointDef; + __destroy__(): void; + protected ptr: number; + target: b2Vec2; + get_target(): b2Vec2; + set_target(target: b2Vec2): void; + maxForce: number; + get_maxForce(): number; + set_maxForce(maxForce: number): void; + frequencyHz: number; + get_frequencyHz(): number; + set_frequencyHz(frequencyHz: number): void; + dampingRatio: number; + get_dampingRatio(): number; + set_dampingRatio(dampingRatio: number): void; + } + export class b2PolygonShape extends b2Shape { + protected static readonly __cache__: { + [ptr: number]: b2PolygonShape; + }; + protected readonly __class__: typeof b2PolygonShape; + __destroy__(): void; + protected ptr: number; + Set(vertices: b2Vec2 | number, vertexCount: number): void; + SetAsBox(hx: number, hy: number): void; + SetAsBox( + hx: number, + hy: number, + center: b2Vec2 | number, + angle: number + ): void; + m_centroid: b2Vec2; + get_m_centroid(): b2Vec2; + set_m_centroid(m_centroid: b2Vec2): void; + m_vertices: b2Vec2; + get_m_vertices(index?: number): b2Vec2; + set_m_vertices(index: number, m_vertices_elem: b2Vec2): void; + m_normals: b2Vec2; + get_m_normals(index?: number): b2Vec2; + set_m_normals(index: number, m_normals_elem: b2Vec2): void; + m_count: number; + get_m_count(): number; + set_m_count(m_count: number): void; + } + export class b2PrismaticJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2PrismaticJoint; + }; + protected readonly __class__: typeof b2PrismaticJoint; + __destroy__(): void; + GetLocalAnchorA(): b2Vec2; + GetLocalAnchorB(): b2Vec2; + GetLocalAxisA(): b2Vec2; + GetReferenceAngle(): number; + GetJointTranslation(): number; + GetJointSpeed(): number; + IsLimitEnabled(): boolean; + EnableLimit(flag: boolean): void; + GetLowerLimit(): number; + GetUpperLimit(): number; + SetLimits(lower: number, upper: number): void; + IsMotorEnabled(): boolean; + EnableMotor(flag: boolean): void; + SetMotorSpeed(speed: number): void; + GetMotorSpeed(): number; + SetMaxMotorForce(force: number): void; + GetMaxMotorForce(): number; + GetMotorForce(inv_dt: number): number; + } + export class b2PrismaticJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2PrismaticJointDef; + }; + protected readonly __class__: typeof b2PrismaticJointDef; + __destroy__(): void; + protected ptr: number; + Initialize( + bodyA: b2Body | number, + bodyB: b2Body | number, + anchor: b2Vec2 | number, + axis: b2Vec2 | number + ): void; + localAnchorA: b2Vec2; + get_localAnchorA(): b2Vec2; + set_localAnchorA(localAnchorA: b2Vec2): void; + localAnchorB: b2Vec2; + get_localAnchorB(): b2Vec2; + set_localAnchorB(localAnchorB: b2Vec2): void; + localAxisA: b2Vec2; + get_localAxisA(): b2Vec2; + set_localAxisA(localAxisA: b2Vec2): void; + referenceAngle: number; + get_referenceAngle(): number; + set_referenceAngle(referenceAngle: number): void; + enableLimit: boolean; + get_enableLimit(): boolean; + set_enableLimit(enableLimit: boolean): void; + lowerTranslation: number; + get_lowerTranslation(): number; + set_lowerTranslation(lowerTranslation: number): void; + upperTranslation: number; + get_upperTranslation(): number; + set_upperTranslation(upperTranslation: number): void; + enableMotor: boolean; + get_enableMotor(): boolean; + set_enableMotor(enableMotor: boolean): void; + maxMotorForce: number; + get_maxMotorForce(): number; + set_maxMotorForce(maxMotorForce: number): void; + motorSpeed: number; + get_motorSpeed(): number; + set_motorSpeed(motorSpeed: number): void; + } + export class b2Profile extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Profile; + }; + protected readonly __class__: typeof b2Profile; + __destroy__(): void; + step: number; + get_step(): number; + set_step(step: number): void; + collide: number; + get_collide(): number; + set_collide(collide: number): void; + solve: number; + get_solve(): number; + set_solve(solve: number): void; + solveInit: number; + get_solveInit(): number; + set_solveInit(solveInit: number): void; + solveVelocity: number; + get_solveVelocity(): number; + set_solveVelocity(solveVelocity: number): void; + solvePosition: number; + get_solvePosition(): number; + set_solvePosition(solvePosition: number): void; + broadphase: number; + get_broadphase(): number; + set_broadphase(broadphase: number): void; + solveTOI: number; + get_solveTOI(): number; + set_solveTOI(solveTOI: number): void; + } + export class b2PulleyJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2PulleyJoint; + }; + protected readonly __class__: typeof b2PulleyJoint; + __destroy__(): void; + GetGroundAnchorA(): b2Vec2; + GetGroundAnchorB(): b2Vec2; + GetLengthA(): number; + GetLengthB(): number; + GetRatio(): number; + GetCurrentLengthA(): number; + GetCurrentLengthB(): number; + } + export class b2PulleyJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2PulleyJointDef; + }; + protected readonly __class__: typeof b2PulleyJointDef; + __destroy__(): void; + protected ptr: number; + Initialize( + bodyA: b2Body | number, + bodyB: b2Body | number, + groundAnchorA: b2Vec2 | number, + groundAnchorB: b2Vec2 | number, + anchorA: b2Vec2 | number, + anchorB: b2Vec2 | number, + ratio: number + ): void; + groundAnchorA: b2Vec2; + get_groundAnchorA(): b2Vec2; + set_groundAnchorA(groundAnchorA: b2Vec2): void; + groundAnchorB: b2Vec2; + get_groundAnchorB(): b2Vec2; + set_groundAnchorB(groundAnchorB: b2Vec2): void; + localAnchorA: b2Vec2; + get_localAnchorA(): b2Vec2; + set_localAnchorA(localAnchorA: b2Vec2): void; + localAnchorB: b2Vec2; + get_localAnchorB(): b2Vec2; + set_localAnchorB(localAnchorB: b2Vec2): void; + lengthA: number; + get_lengthA(): number; + set_lengthA(lengthA: number): void; + lengthB: number; + get_lengthB(): number; + set_lengthB(lengthB: number): void; + ratio: number; + get_ratio(): number; + set_ratio(ratio: number): void; + } + export class b2RayCastInput extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2RayCastInput; + }; + protected readonly __class__: typeof b2RayCastInput; + __destroy__(): void; + p1: b2Vec2; + get_p1(): b2Vec2; + set_p1(p1: b2Vec2): void; + p2: b2Vec2; + get_p2(): b2Vec2; + set_p2(p2: b2Vec2): void; + maxFraction: number; + get_maxFraction(): number; + set_maxFraction(maxFraction: number): void; + } + export class b2RayCastOutput extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2RayCastOutput; + }; + protected readonly __class__: typeof b2RayCastOutput; + __destroy__(): void; + normal: b2Vec2; + get_normal(): b2Vec2; + set_normal(normal: b2Vec2): void; + fraction: number; + get_fraction(): number; + set_fraction(fraction: number): void; + } + export class b2RevoluteJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2RevoluteJoint; + }; + protected readonly __class__: typeof b2RevoluteJoint; + __destroy__(): void; + GetLocalAnchorA(): b2Vec2; + GetLocalAnchorB(): b2Vec2; + GetReferenceAngle(): number; + GetJointAngle(): number; + GetJointSpeed(): number; + IsLimitEnabled(): boolean; + EnableLimit(flag: boolean): void; + GetLowerLimit(): number; + GetUpperLimit(): number; + SetLimits(lower: number, upper: number): void; + IsMotorEnabled(): boolean; + EnableMotor(flag: boolean): void; + SetMotorSpeed(speed: number): void; + GetMotorSpeed(): number; + SetMaxMotorTorque(torque: number): void; + GetMaxMotorTorque(): number; + GetMotorTorque(inv_dt: number): number; + } + export class b2RevoluteJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2RevoluteJointDef; + }; + protected readonly __class__: typeof b2RevoluteJointDef; + __destroy__(): void; + protected ptr: number; + Initialize( + bodyA: b2Body | number, + bodyB: b2Body | number, + anchor: b2Vec2 | number + ): void; + localAnchorA: b2Vec2; + get_localAnchorA(): b2Vec2; + set_localAnchorA(localAnchorA: b2Vec2): void; + localAnchorB: b2Vec2; + get_localAnchorB(): b2Vec2; + set_localAnchorB(localAnchorB: b2Vec2): void; + referenceAngle: number; + get_referenceAngle(): number; + set_referenceAngle(referenceAngle: number): void; + enableLimit: boolean; + get_enableLimit(): boolean; + set_enableLimit(enableLimit: boolean): void; + lowerAngle: number; + get_lowerAngle(): number; + set_lowerAngle(lowerAngle: number): void; + upperAngle: number; + get_upperAngle(): number; + set_upperAngle(upperAngle: number): void; + enableMotor: boolean; + get_enableMotor(): boolean; + set_enableMotor(enableMotor: boolean): void; + motorSpeed: number; + get_motorSpeed(): number; + set_motorSpeed(motorSpeed: number): void; + maxMotorTorque: number; + get_maxMotorTorque(): number; + set_maxMotorTorque(maxMotorTorque: number): void; + } + export class b2Rot extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Rot; + }; + protected readonly __class__: typeof b2Rot; + __destroy__(): void; + protected ptr: number; + /** + * @deprecated no-arg construction is forbidden (throws errors). + * it's exposed in the types solely so that this class can be structurally-compatible with {@link WrapperObject}. + * @throws {string} + */ + constructor(); + constructor(angle: number); + Set(angle: number): void; + SetIdentity(): void; + GetAngle(): number; + GetXAxis(): b2Vec2; + GetYAxis(): b2Vec2; + s: number; + get_s(): number; + set_s(s: number): void; + c: number; + get_c(): number; + set_c(c: number): void; + } + export class b2WheelJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2WheelJoint; + }; + protected readonly __class__: typeof b2WheelJoint; + __destroy__(): void; + GetLocalAnchorA(): b2Vec2; + GetLocalAnchorB(): b2Vec2; + GetLocalAxisA(): b2Vec2; + GetJointTranslation(): number; + GetJointSpeed(): number; + IsMotorEnabled(): boolean; + EnableMotor(flag: boolean): void; + SetMotorSpeed(speed: number): void; + GetMotorSpeed(): number; + SetMaxMotorTorque(torque: number): void; + GetMaxMotorTorque(): number; + GetMotorTorque(inv_dt: number): number; + GetSpringFrequencyHz(): number; + SetSpringFrequencyHz(frequency: number): void; + GetSpringDampingRatio(): number; + SetSpringDampingRatio(dampingRatio: number): void; + } + export class b2WheelJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2WheelJointDef; + }; + protected readonly __class__: typeof b2WheelJointDef; + __destroy__(): void; + protected ptr: number; + Initialize( + bodyA: b2Body | number, + bodyB: b2Body | number, + anchor: b2Vec2 | number, + axis: b2Vec2 | number + ): void; + localAnchorA: b2Vec2; + get_localAnchorA(): b2Vec2; + set_localAnchorA(localAnchorA: b2Vec2): void; + localAnchorB: b2Vec2; + get_localAnchorB(): b2Vec2; + set_localAnchorB(localAnchorB: b2Vec2): void; + localAxisA: b2Vec2; + get_localAxisA(): b2Vec2; + set_localAxisA(localAxisA: b2Vec2): void; + enableMotor: boolean; + get_enableMotor(): boolean; + set_enableMotor(enableMotor: boolean): void; + maxMotorTorque: number; + get_maxMotorTorque(): number; + set_maxMotorTorque(maxMotorTorque: number): void; + motorSpeed: number; + get_motorSpeed(): number; + set_motorSpeed(motorSpeed: number): void; + frequencyHz: number; + get_frequencyHz(): number; + set_frequencyHz(frequencyHz: number): void; + dampingRatio: number; + get_dampingRatio(): number; + set_dampingRatio(dampingRatio: number): void; + } + export class b2MotorJoint extends b2Joint { + protected static readonly __cache__: { + [ptr: number]: b2MotorJoint; + }; + protected readonly __class__: typeof b2MotorJoint; + __destroy__(): void; + SetLinearOffset(linearOffset: b2Vec2 | number): void; + GetLinearOffset(): b2Vec2; + SetAngularOffset(angularOffset: number): void; + GetAngularOffset(): number; + SetMaxForce(force: number): void; + GetMaxForce(): number; + SetMaxTorque(torque: number): void; + GetMaxTorque(): number; + SetCorrectionFactor(factor: number): void; + GetCorrectionFactor(): number; + } + export class b2MotorJointDef extends b2JointDef { + protected static readonly __cache__: { + [ptr: number]: b2MotorJointDef; + }; + protected readonly __class__: typeof b2MotorJointDef; + __destroy__(): void; + protected ptr: number; + Initialize(bodyA: b2Body | number, bodyB: b2Body | number): void; + linearOffset: b2Vec2; + get_linearOffset(): b2Vec2; + set_linearOffset(linearOffset: b2Vec2): void; + angularOffset: number; + get_angularOffset(): number; + set_angularOffset(angularOffset: number): void; + maxForce: number; + get_maxForce(): number; + set_maxForce(maxForce: number): void; + maxTorque: number; + get_maxTorque(): number; + set_maxTorque(maxTorque: number): void; + correctionFactor: number; + get_correctionFactor(): number; + set_correctionFactor(correctionFactor: number): void; + } + const b2_nullState: number; + const b2_addState: number; + const b2_persistState: number; + const b2_removeState: number; + const b2_pbdStretchingModel: number; + const b2_xpbdStretchingModel: number; + const b2_springAngleBendingModel: number; + const b2_pbdAngleBendingModel: number; + const b2_xpbdAngleBendingModel: number; + const b2_pbdDistanceBendingModel: number; + const b2_pbdHeightBendingModel: number; + export class b2RopeTuning extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2RopeTuning; + }; + protected readonly __class__: typeof b2RopeTuning; + __destroy__(): void; + protected ptr: number; + stretchingModel: number; + get_stretchingModel(): number; + set_stretchingModel(stretchingModel: number): void; + bendingModel: number; + get_bendingModel(): number; + set_bendingModel(bendingModel: number): void; + damping: number; + get_damping(): number; + set_damping(damping: number): void; + stretchStiffness: number; + get_stretchStiffness(): number; + set_stretchStiffness(stretchStiffness: number): void; + stretchHertz: number; + get_stretchHertz(): number; + set_stretchHertz(stretchHertz: number): void; + stretchDamping: number; + get_stretchDamping(): number; + set_stretchDamping(stretchDamping: number): void; + bendStiffness: number; + get_bendStiffness(): number; + set_bendStiffness(bendStiffness: number): void; + bendHertz: number; + get_bendHertz(): number; + set_bendHertz(bendHertz: number): void; + bendDamping: number; + get_bendDamping(): number; + set_bendDamping(bendDamping: number): void; + isometric: boolean; + get_isometric(): boolean; + set_isometric(isometric: boolean): void; + fixedEffectiveMass: boolean; + get_fixedEffectiveMass(): boolean; + set_fixedEffectiveMass(fixedEffectiveMass: boolean): void; + warmStart: boolean; + get_warmStart(): boolean; + set_warmStart(warmStart: boolean): void; + } + export class b2RopeDef extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2RopeDef; + }; + protected readonly __class__: typeof b2RopeDef; + __destroy__(): void; + protected ptr: number; + position: b2Vec2; + get_position(): b2Vec2; + set_position(position: b2Vec2): void; + vertices: b2Vec2; + get_vertices(): b2Vec2; + set_vertices(vertices: b2Vec2): void; + count: number; + get_count(): number; + set_count(count: number): void; + gravity: b2Vec2; + get_gravity(): b2Vec2; + set_gravity(gravity: b2Vec2): void; + tuning: b2RopeTuning; + get_tuning(): b2RopeTuning; + set_tuning(tuning: b2RopeTuning): void; + } + export class b2Rope extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2Rope; + }; + protected readonly __class__: typeof b2Rope; + __destroy__(): void; + protected ptr: number; + Create(def: b2RopeDef | number): void; + SetTuning(tuning: b2RopeTuning | number): void; + Step(timeStep: number, iterations: number, position: b2Vec2 | number): void; + Reset(position: b2Vec2 | number): void; + Draw(draw: b2Draw | number): void; + } + export class b2ClipVertex extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: b2ClipVertex; + }; + protected readonly __class__: typeof b2ClipVertex; + __destroy__(): void; + protected ptr: number; + v: b2Vec2; + get_v(): b2Vec2; + set_v(v: b2Vec2): void; + id: b2ContactID; + get_id(): b2ContactID; + set_id(id: b2ContactID): void; + } + export class WrapperObject { + protected static readonly __cache__: { + [ptr: number]: WrapperObject; + }; + protected readonly __class__: typeof WrapperObject; + protected ptr?: number; + } + export class VoidPtr extends WrapperObject { + protected static readonly __cache__: { + [ptr: number]: VoidPtr; + }; + protected readonly __class__: typeof VoidPtr; + protected ptr?: number; + } + export const wrapPointer: ; + } = typeof WrapperObject>( + pointer: number, + targetType?: TargetClass + ) => InstanceType; + export const getPointer: (instance: WrapperObject) => number; + export const castObject: ; + } = typeof WrapperObject>( + instance: WrapperObject, + targetType?: TargetClass + ) => InstanceType; + export const compare: ( + instance: WrapperObject, + instance2: WrapperObject + ) => boolean; + export const getCache: ( + type?: Class + ) => { + [ptr: number]: InstanceType; + }; + export const destroy: (instance: { __destroy__(): void }) => void; + export const getClass: ( + instance: InstanceType + ) => Class; + export const NULL: WrapperObject; +} diff --git a/Extensions/Physics2Behavior/physics2runtimebehavior.ts b/Extensions/Physics2Behavior/physics2runtimebehavior.ts index a2cbfa20f5..3b42e637da 100644 --- a/Extensions/Physics2Behavior/physics2runtimebehavior.ts +++ b/Extensions/Physics2Behavior/physics2runtimebehavior.ts @@ -1,31 +1,41 @@ +namespace Box2D { + export interface b2Body { + gdjsAssociatedBehavior: gdjs.Physics2RuntimeBehavior | null; + } +} namespace gdjs { + export interface RuntimeScene { + physics2SharedData: gdjs.Physics2SharedData | null; + } export class Physics2SharedData { - gravityX: any; - gravityY: any; - scaleX: any; - scaleY: any; - invScaleX: any; - invScaleY: any; - timeStep: any; + gravityX: float; + gravityY: float; + scaleX: float; + scaleY: float; + invScaleX: float; + invScaleY: float; + timeStep: float; frameTime: float = 0; stepped: boolean = false; timeScale: float = 1; - world: any; - staticBody: any; + world: Box2D.b2World; + staticBody: Box2D.b2Body; - // Contact listener to keep track of current collisions - contactListener: any; + /** Contact listener to keep track of current collisions */ + contactListener: Box2D.JSContactListener; _nextJointId: number = 1; - // Start with 1 so the user is safe from default variables value (0) - joints: any = {}; + /** Start with 1 so the user is safe from default variables value (0) */ + joints: { [key: string]: Box2D.b2Joint } = {}; - // List of physics behavior in the runtimeScene. It should be updated - // when a new physics object is created (constructor), on destruction (onDestroy), - // on behavior activation (onActivate) and on behavior deactivation (onDeActivate). + /** + * List of physics behavior in the runtimeScene. It should be updated + * when a new physics object is created (constructor), on destruction (onDestroy), + * on behavior activation (onActivate) and on behavior deactivation (onDeActivate). + */ _registeredBehaviors: Set; - constructor(runtimeScene, sharedData) { + constructor(runtimeScene: gdjs.RuntimeScene, sharedData) { this._registeredBehaviors = new Set(); this.gravityX = sharedData.gravityX; this.gravityY = sharedData.gravityY; @@ -35,14 +45,16 @@ namespace gdjs { this.invScaleY = 1 / this.scaleY; this.timeStep = 1 / 60; this.world = new Box2D.b2World( - new Box2D.b2Vec2(this.gravityX, this.gravityY), - true + new Box2D.b2Vec2(this.gravityX, this.gravityY) ); this.staticBody = this.world.CreateBody(new Box2D.b2BodyDef()); this.contactListener = new Box2D.JSContactListener(); this.contactListener.BeginContact = function (contactPtr) { // Get the contact - const contact = Box2D.wrapPointer(contactPtr, Box2D.b2Contact); + const contact = Box2D.wrapPointer( + contactPtr as number, + Box2D.b2Contact + ); // There is no body, return if ( @@ -54,9 +66,9 @@ namespace gdjs { // Get associated behaviors const behaviorA = contact.GetFixtureA().GetBody() - .gdjsAssociatedBehavior as Physics2RuntimeBehavior | null; + .gdjsAssociatedBehavior; const behaviorB = contact.GetFixtureB().GetBody() - .gdjsAssociatedBehavior as Physics2RuntimeBehavior | null; + .gdjsAssociatedBehavior; if (!behaviorA || !behaviorB) { return; @@ -67,7 +79,10 @@ namespace gdjs { }; this.contactListener.EndContact = function (contactPtr) { // Get the contact - const contact = Box2D.wrapPointer(contactPtr, Box2D.b2Contact); + const contact = Box2D.wrapPointer( + contactPtr as number, + Box2D.b2Contact + ); // There is no body, return if ( @@ -96,7 +111,10 @@ namespace gdjs { } // (string)jointId -> (b2Joint)b2Joint - static getSharedData(runtimeScene, behaviorName) { + static getSharedData( + runtimeScene: gdjs.RuntimeScene, + behaviorName: string + ): gdjs.Physics2SharedData { // Create one if needed if (!runtimeScene.physics2SharedData) { const initialData = runtimeScene.getInitialSharedDataForBehavior( @@ -113,14 +131,16 @@ namespace gdjs { /** * Add a physics object to the list of existing object. */ - addToBehaviorsList(physicsBehavior: gdjs.Physics2RuntimeBehavior) { + addToBehaviorsList(physicsBehavior: gdjs.Physics2RuntimeBehavior): void { this._registeredBehaviors.add(physicsBehavior); } /** * Remove a physics object to the list of existing object. */ - removeFromBehaviorsList(physicsBehavior: gdjs.Physics2RuntimeBehavior) { + removeFromBehaviorsList( + physicsBehavior: gdjs.Physics2RuntimeBehavior + ): void { this._registeredBehaviors.delete(physicsBehavior); } @@ -128,7 +148,7 @@ namespace gdjs { * Reset all contactsStartedThisFrame and contactsEndedThisFrame of all * registered physics behavior. */ - resetStartedAndEndedCollisions() { + resetStartedAndEndedCollisions(): void { for (const physicsBehavior of this._registeredBehaviors) { physicsBehavior.contactsStartedThisFrame.length = 0; physicsBehavior.contactsEndedThisFrame.length = 0; @@ -138,13 +158,13 @@ namespace gdjs { /** * Update all registered body. */ - updateBodiesFromObjects() { + updateBodiesFromObjects(): void { for (const physicsBehavior of this._registeredBehaviors) { physicsBehavior.updateBodyFromObject(); } } - step(deltaTime) { + step(deltaTime: float): void { this.frameTime += deltaTime; if (this.frameTime >= this.timeStep) { let numberOfSteps = Math.floor(this.frameTime / this.timeStep); @@ -160,7 +180,7 @@ namespace gdjs { this.stepped = true; } - clearBodyJoints(body) { + clearBodyJoints(body: Box2D.b2Body): void { // Iterate through all the joints for (const jointId in this.joints) { if (this.joints.hasOwnProperty(jointId)) { @@ -175,7 +195,7 @@ namespace gdjs { } } - addJoint(joint) { + addJoint(joint: Box2D.b2Joint): integer { // Add the joint to the list this.joints[this._nextJointId.toString(10)] = joint; @@ -183,7 +203,7 @@ namespace gdjs { return this._nextJointId++; } - getJoint(jointId) { + getJoint(jointId: integer | string): Box2D.b2Joint | null { // Cast to string jointId = jointId.toString(10); @@ -196,7 +216,7 @@ namespace gdjs { return null; } - getJointId(joint): integer { + getJointId(joint: Box2D.b2Joint): integer { // Search the joint in the list and return the ID for (const jointId in this.joints) { if (this.joints.hasOwnProperty(jointId)) { @@ -210,7 +230,7 @@ namespace gdjs { return 0; } - removeJoint(jointId) { + removeJoint(jointId: integer | string) { // Cast to string jointId = jointId.toString(10); @@ -227,13 +247,15 @@ namespace gdjs { ) { for (const jId in this.joints) { if (this.joints.hasOwnProperty(jId)) { - // Must check pointers becuase gears store non-casted joints (b2Joint) + // Must check pointers because gears store non-casted joints (b2Joint) if ( this.joints[jId].GetType() === Box2D.e_gearJoint && - (Box2D.getPointer(this.joints[jId].GetJoint1()) === - Box2D.getPointer(joint) || - Box2D.getPointer(this.joints[jId].GetJoint2()) === - Box2D.getPointer(joint)) + (Box2D.getPointer( + (this.joints[jId] as Box2D.b2GearJoint).GetJoint1() + ) === Box2D.getPointer(joint) || + Box2D.getPointer( + (this.joints[jId] as Box2D.b2GearJoint).GetJoint2() + ) === Box2D.getPointer(joint)) ) { // We could pass it a string, but lets do it right this.removeJoint(parseInt(jId, 10)); @@ -261,25 +283,25 @@ namespace gdjs { }); export class Physics2RuntimeBehavior extends gdjs.RuntimeBehavior { - bodyType: any; - bullet: any; + bodyType: string; + bullet: boolean; fixedRotation: boolean; - canSleep: any; - shape: any; + canSleep: boolean; + shape: string; shapeDimensionA: any; shapeDimensionB: any; - shapeOffsetX: any; - shapeOffsetY: any; - polygonOrigin: any; - polygon: any; - density: any; - friction: any; - restitution: any; - linearDamping: any; - angularDamping: any; - gravityScale: any; - layers: any; - masks: any; + shapeOffsetX: float; + shapeOffsetY: float; + polygonOrigin: string; + polygon: gdjs.Polygon | null; + density: float; + friction: float; + restitution: float; + linearDamping: float; + angularDamping: float; + gravityScale: float; + layers: integer; + masks: integer; shapeScale: number = 1; /** @@ -306,8 +328,9 @@ namespace gdjs { */ currentContacts: Array; destroyedDuringFrameLogic: boolean; - _body: any = null; - _tempb2Vec2: any; + _body: Box2D.b2Body | null = null; + /** Avoid creating new vectors all the time */ + _tempb2Vec2: Box2D.b2Vec2; /** * sharedData is a reference to the shared data of the scene, that registers @@ -315,10 +338,9 @@ namespace gdjs { * before stepping the world. */ _sharedData: Physics2SharedData; - // Avoid creating new vectors all the time - _tempb2Vec2Sec: any; + /** Sometimes two vectors are needed on the same function call */ + _tempb2Vec2Sec: Box2D.b2Vec2; - // Sometimes two vectors are needed on the same function call _objectOldX: number = 0; _objectOldY: number = 0; _objectOldAngle: float = 0; @@ -326,7 +348,11 @@ namespace gdjs { _objectOldHeight: float = 0; _verticesBuffer: integer = 0; - constructor(runtimeScene, behaviorData, owner) { + constructor( + runtimeScene: gdjs.RuntimeScene, + behaviorData, + owner: gdjs.RuntimeObject + ) { super(runtimeScene, behaviorData, owner); this.bodyType = behaviorData.bodyType; this.bullet = behaviorData.bullet; @@ -365,13 +391,13 @@ namespace gdjs { } // Stores a Box2D pointer of created vertices - b2Vec2(x, y) { + b2Vec2(x: float, y: float): Box2D.b2Vec2 { this._tempb2Vec2.set_x(x); this._tempb2Vec2.set_y(y); return this._tempb2Vec2; } - b2Vec2Sec(x, y) { + b2Vec2Sec(x: float, y: float): Box2D.b2Vec2 { this._tempb2Vec2Sec.set_x(x); this._tempb2Vec2Sec.set_y(y); return this._tempb2Vec2Sec; @@ -480,7 +506,7 @@ namespace gdjs { this.onDeActivate(); } - static getPolygon(verticesData) { + static getPolygon(verticesData: Box2D.b2Vec2[]): gdjs.Polygon | null { if (!verticesData) { return null; } @@ -496,7 +522,7 @@ namespace gdjs { return polygon; } - static isPolygonConvex(polygon) { + static isPolygonConvex(polygon: gdjs.Polygon): boolean { if (!polygon.isConvex()) { return false; } @@ -526,7 +552,7 @@ namespace gdjs { return true; } - createShape() { + createShape(): Box2D.b2FixtureDef { // Get the scaled offset const offsetX = this.shapeOffsetX ? this.shapeOffsetX * this.shapeScale * this._sharedData.invScaleX @@ -721,38 +747,39 @@ namespace gdjs { return fixDef; } - recreateShape() { + recreateShape(): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Destroy the old shape - this._body.DestroyFixture(this._body.GetFixtureList()); - this._body.CreateFixture(this.createShape()); + body.DestroyFixture(body.GetFixtureList()); + body.CreateFixture(this.createShape()); // Update cached size this._objectOldWidth = this.owner.getWidth(); this._objectOldHeight = this.owner.getHeight(); } - getShapeScale() { + getShapeScale(): float { return this.shapeScale; } - setShapeScale(shapeScale): void { + setShapeScale(shapeScale: float): void { if (shapeScale !== this.shapeScale && shapeScale > 0) { this.shapeScale = shapeScale; this.recreateShape(); } } - getBody() { + getBody(): Box2D.b2Body { // If there is no body, set a new one if (this._body === null) { this.createBody(); } - return this._body; + return this._body!; } createBody(): boolean { @@ -797,7 +824,7 @@ namespace gdjs { return true; } - doStepPreEvents(runtimeScene) { + doStepPreEvents(runtimeScene: gdjs.RuntimeScene) { // Step the world if not done this frame yet if (!this._sharedData.stepped) { // Reset started and ended contacts array for all physics instances. @@ -835,7 +862,7 @@ namespace gdjs { this._objectOldAngle = this.owner.getAngle(); } - doStepPostEvents(runtimeScene) { + doStepPostEvents(runtimeScene: gdjs.RuntimeScene) { // Reset world step to update next frame this._sharedData.stepped = false; } @@ -849,6 +876,7 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // The object size has changed, recreate the shape. // The width has changed and there is no custom dimension A (box: width, circle: radius, edge: length) or @@ -877,8 +905,8 @@ namespace gdjs { (this.owner.getDrawableY() + this.owner.getHeight() / 2) * this._sharedData.invScaleY ); - this._body.SetTransform(pos, gdjs.toRad(this.owner.getAngle())); - this._body.SetAwake(true); + body.SetTransform(pos, gdjs.toRad(this.owner.getAngle())); + body.SetAwake(true); } } @@ -890,7 +918,7 @@ namespace gdjs { return this._sharedData.gravityY; } - setGravity(x, y): void { + setGravity(x: float, y: float): void { // Check if there is no modification if (this._sharedData.gravityX === x && this._sharedData.gravityY === y) { return; @@ -909,7 +937,7 @@ namespace gdjs { return this._sharedData.timeScale; } - setTimeScale(timeScale): void { + setTimeScale(timeScale: float): void { // Invalid value if (timeScale < 0) { return; @@ -946,10 +974,11 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update body type - this._body.SetType(Box2D.b2_dynamicBody); - this._body.SetAwake(true); + body.SetType(Box2D.b2_dynamicBody); + body.SetAwake(true); } isStatic(): boolean { @@ -969,10 +998,11 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update body type - this._body.SetType(Box2D.b2_staticBody); - this._body.SetAwake(true); + body.SetType(Box2D.b2_staticBody); + body.SetAwake(true); } isKinematic(): boolean { @@ -992,17 +1022,18 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update body type - this._body.SetType(Box2D.b2_kinematicBody); - this._body.SetAwake(true); + body.SetType(Box2D.b2_kinematicBody); + body.SetAwake(true); } isBullet(): boolean { return this.bullet; } - setBullet(enable): void { + setBullet(enable: boolean): void { // Check if there is no modification if (this.bullet === enable) { return; @@ -1015,33 +1046,36 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update body bullet flag - this._body.SetBullet(this.bullet); + body.SetBullet(this.bullet); } hasFixedRotation(): boolean { return this.fixedRotation; } - setFixedRotation(enable): void { + setFixedRotation(enable: boolean): void { this.fixedRotation = enable; if (this._body === null) { if (!this.createBody()) return; } - this._body.SetFixedRotation(this.fixedRotation); + const body = this._body!; + body.SetFixedRotation(this.fixedRotation); } isSleepingAllowed(): boolean { return this.canSleep; } - setSleepingAllowed(enable): void { + setSleepingAllowed(enable: boolean): void { this.canSleep = enable; if (this._body === null) { if (!this.createBody()) return; } - this._body.SetSleepingAllowed(this.canSleep); + const body = this._body!; + body.SetSleepingAllowed(this.canSleep); } isSleeping(): boolean { @@ -1049,16 +1083,17 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return true; } + const body = this._body!; // Get the body sleeping state - return !this._body.IsAwake(); + return !body.IsAwake(); } getDensity() { return this.density; } - setDensity(density): void { + setDensity(density: float): void { // Non-negative values only if (density < 0) { density = 0; @@ -1076,13 +1111,14 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update the body density - this._body.GetFixtureList().SetDensity(this.density); - this._body.ResetMassData(); + body.GetFixtureList().SetDensity(this.density); + body.ResetMassData(); } - getFriction() { + getFriction(): float { return this.friction; } @@ -1104,23 +1140,24 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update the body friction - this._body.GetFixtureList().SetFriction(this.friction); + body.GetFixtureList().SetFriction(this.friction); // Update contacts - let contact = this._body.GetContactList(); + let contact = body.GetContactList(); while (Box2D.getPointer(contact)) { contact.get_contact().ResetFriction(); contact = contact.get_next(); } } - getRestitution() { + getRestitution(): float { return this.restitution; } - setRestitution(restitution): void { + setRestitution(restitution: float): void { // Non-negative values only if (restitution < 0) { restitution = 0; @@ -1138,23 +1175,24 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update the body restitution - this._body.GetFixtureList().SetRestitution(this.restitution); + body.GetFixtureList().SetRestitution(this.restitution); // Update contacts - let contact = this._body.GetContactList(); + let contact = body.GetContactList(); while (Box2D.getPointer(contact)) { contact.get_contact().ResetRestitution(); contact = contact.get_next(); } } - getLinearDamping() { + getLinearDamping(): float { return this.linearDamping; } - setLinearDamping(linearDamping): void { + setLinearDamping(linearDamping: float): void { // Check if there is no modification if (this.linearDamping === linearDamping) { return; @@ -1167,16 +1205,17 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update the body linear damping - this._body.SetLinearDamping(this.linearDamping); + body.SetLinearDamping(this.linearDamping); } - getAngularDamping() { + getAngularDamping(): float { return this.angularDamping; } - setAngularDamping(angularDamping): void { + setAngularDamping(angularDamping: float): void { // Check if there is no modification if (this.angularDamping === angularDamping) { return; @@ -1189,16 +1228,17 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update the body angular damping - this._body.SetAngularDamping(this.angularDamping); + body.SetAngularDamping(this.angularDamping); } - getGravityScale() { + getGravityScale(): float { return this.gravityScale; } - setGravityScale(gravityScale): void { + setGravityScale(gravityScale: float): void { // Check if there is no modification if (this.gravityScale === gravityScale) { return; @@ -1211,12 +1251,13 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update the body gravity scale - this._body.SetGravityScale(this.gravityScale); + body.SetGravityScale(this.gravityScale); } - layerEnabled(layer) { + layerEnabled(layer: integer) { // Layer must be an integer layer = Math.floor(layer); @@ -1227,7 +1268,7 @@ namespace gdjs { return !!(this.layers & (1 << (layer - 1))); } - enableLayer(layer, enable): void { + enableLayer(layer: integer, enable: boolean): void { // Layer must be an integer layer = Math.floor(layer); @@ -1247,14 +1288,15 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update the body layers - const filter = this._body.GetFixtureList().GetFilterData(); + const filter = body.GetFixtureList().GetFilterData(); filter.set_categoryBits(this.layers); - this._body.GetFixtureList().SetFilterData(filter); + body.GetFixtureList().SetFilterData(filter); } - maskEnabled(mask) { + maskEnabled(mask: integer): boolean { // Mask must be an integer mask = Math.floor(mask); @@ -1265,7 +1307,7 @@ namespace gdjs { return !!(this.masks & (1 << (mask - 1))); } - enableMask(mask, enable): void { + enableMask(mask: integer, enable: boolean): void { // Mask must be an integer mask = Math.floor(mask); @@ -1285,11 +1327,12 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Update the body masks - const filter = this._body.GetFixtureList().GetFilterData(); + const filter = body.GetFixtureList().GetFilterData(); filter.set_maskBits(this.masks); - this._body.GetFixtureList().SetFilterData(filter); + body.GetFixtureList().SetFilterData(filter); } getLinearVelocityX(): float { @@ -1297,22 +1340,24 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return 0; } + const body = this._body!; // Get the linear velocity on X - return this._body.GetLinearVelocity().get_x() * this._sharedData.scaleX; + return body.GetLinearVelocity().get_x() * this._sharedData.scaleX; } - setLinearVelocityX(linearVelocityX): void { + setLinearVelocityX(linearVelocityX: float): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Set the linear velocity on X - this._body.SetLinearVelocity( + body.SetLinearVelocity( this.b2Vec2( linearVelocityX * this._sharedData.invScaleX, - this._body.GetLinearVelocity().get_y() + body.GetLinearVelocity().get_y() ) ); } @@ -1322,21 +1367,23 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return 0; } + const body = this._body!; // Get the linear velocity on Y - return this._body.GetLinearVelocity().get_y() * this._sharedData.scaleY; + return body.GetLinearVelocity().get_y() * this._sharedData.scaleY; } - setLinearVelocityY(linearVelocityY): void { + setLinearVelocityY(linearVelocityY: float): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Set the linear velocity on Y - this._body.SetLinearVelocity( + body.SetLinearVelocity( this.b2Vec2( - this._body.GetLinearVelocity().get_x(), + body.GetLinearVelocity().get_x(), linearVelocityY * this._sharedData.invScaleY ) ); @@ -1347,11 +1394,12 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return 0; } + const body = this._body!; // Get the linear velocity length return this.b2Vec2( - this._body.GetLinearVelocity().get_x() * this._sharedData.scaleX, - this._body.GetLinearVelocity().get_y() * this._sharedData.scaleY + body.GetLinearVelocity().get_x() * this._sharedData.scaleX, + body.GetLinearVelocity().get_y() * this._sharedData.scaleY ).Length(); } @@ -1360,169 +1408,231 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return 0; } + const body = this._body!; // Get the angular velocity - return gdjs.toDegrees(this._body.GetAngularVelocity()); + return gdjs.toDegrees(body.GetAngularVelocity()); } - setAngularVelocity(angularVelocity): void { + setAngularVelocity(angularVelocity: float): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Set the angular velocity - this._body.SetAngularVelocity(gdjs.toRad(angularVelocity)); + body.SetAngularVelocity(gdjs.toRad(angularVelocity)); } - applyForce(forceX, forceY, positionX, positionY) { + applyForce( + forceX: float, + forceY: float, + positionX: float, + positionY: float + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); // Apply the force - this._body.ApplyForce( + body.ApplyForce( this.b2Vec2(forceX, forceY), this.b2Vec2Sec( positionX * this._sharedData.invScaleX, positionY * this._sharedData.invScaleY - ) + ), + // TODO Should let Box2d awake the object itself. + false ); } - applyPolarForce(angle, length, positionX, positionY) { + applyPolarForce( + angle: float, + length: float, + positionX: float, + positionY: float + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); // Apply the force angle = gdjs.toRad(angle); - this._body.ApplyForce( + body.ApplyForce( this.b2Vec2(length * Math.cos(angle), length * Math.sin(angle)), this.b2Vec2Sec( positionX * this._sharedData.invScaleX, positionY * this._sharedData.invScaleY - ) + ), + // TODO Should let Box2d awake the object itself. + false ); } - applyForceTowardPosition(length, towardX, towardY, positionX, positionY) { + applyForceTowardPosition( + length: float, + towardX: float, + towardY: float, + positionX: float, + positionY: float + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); // Apply the force const angle = Math.atan2( - towardY * this._sharedData.invScaleY - this._body.GetPosition().get_y(), - towardX * this._sharedData.invScaleX - this._body.GetPosition().get_x() + towardY * this._sharedData.invScaleY - body.GetPosition().get_y(), + towardX * this._sharedData.invScaleX - body.GetPosition().get_x() ); - this._body.ApplyForce( + body.ApplyForce( this.b2Vec2(length * Math.cos(angle), length * Math.sin(angle)), this.b2Vec2Sec( positionX * this._sharedData.invScaleX, positionY * this._sharedData.invScaleY - ) + ), + // TODO Should let Box2d awake the object itself. + false ); } - applyImpulse(impulseX, impulseY, positionX, positionY) { + applyImpulse( + impulseX: float, + impulseY: float, + positionX: float, + positionY: float + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); // Apply the impulse - this._body.ApplyLinearImpulse( + body.ApplyLinearImpulse( this.b2Vec2(impulseX, impulseY), this.b2Vec2Sec( positionX * this._sharedData.invScaleX, positionY * this._sharedData.invScaleY - ) + ), + // TODO Should let Box2d awake the object itself. + false ); } - applyPolarImpulse(angle, length, positionX, positionY) { + applyPolarImpulse( + angle: float, + length: float, + positionX: float, + positionY: float + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); // Apply the impulse angle = gdjs.toRad(angle); - this._body.ApplyLinearImpulse( + body.ApplyLinearImpulse( this.b2Vec2(length * Math.cos(angle), length * Math.sin(angle)), this.b2Vec2Sec( positionX * this._sharedData.invScaleX, positionY * this._sharedData.invScaleY - ) + ), + // TODO Should let Box2d awake the object itself. + false ); } - applyImpulseTowardPosition(length, towardX, towardY, positionX, positionY) { + applyImpulseTowardPosition( + length: float, + towardX: float, + towardY: float, + positionX: float, + positionY: float + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); // Apply the impulse const angle = Math.atan2( - towardY * this._sharedData.invScaleY - this._body.GetPosition().get_y(), - towardX * this._sharedData.invScaleX - this._body.GetPosition().get_x() + towardY * this._sharedData.invScaleY - body.GetPosition().get_y(), + towardX * this._sharedData.invScaleX - body.GetPosition().get_x() ); - this._body.ApplyLinearImpulse( + body.ApplyLinearImpulse( this.b2Vec2(length * Math.cos(angle), length * Math.sin(angle)), this.b2Vec2Sec( positionX * this._sharedData.invScaleX, positionY * this._sharedData.invScaleY - ) + ), + // TODO Should let Box2d awake the object itself. + false ); } - applyTorque(torque) { + applyTorque(torque: float): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); // Apply the torque - this._body.ApplyTorque(torque); + body.ApplyTorque( + torque, + // TODO Should let Box2d awake the object itself. + false + ); } - applyAngularImpulse(angularImpulse) { + applyAngularImpulse(angularImpulse: float): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); // Apply the angular impulse - this._body.ApplyAngularImpulse(angularImpulse); + body.ApplyAngularImpulse( + angularImpulse, + // TODO Should let Box2d awake the object itself. + false + ); } getMass(): float { @@ -1530,11 +1640,12 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return 0; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); - return this._body.GetMass(); + return body.GetMass(); } getInertia(): float { @@ -1542,11 +1653,12 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return 0; } + const body = this._body!; // Wake up the object - this._body.SetAwake(true); + body.SetAwake(true); - return this._body.GetInertia(); + return body.GetInertia(); } getMassCenterX(): float { @@ -1554,9 +1666,10 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return 0; } + const body = this._body!; // Get the mass center on X - return this._body.GetWorldCenter().get_x() * this._sharedData.scaleX; + return body.GetWorldCenter().get_x() * this._sharedData.scaleX; } getMassCenterY(): float { @@ -1564,13 +1677,14 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return 0; } + const body = this._body!; // Get the mass center on Y - return this._body.GetWorldCenter().get_y() * this._sharedData.scaleY; + return body.GetWorldCenter().get_y() * this._sharedData.scaleY; } // Joints - isJointFirstObject(jointId): boolean { + isJointFirstObject(jointId: integer | string): boolean { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return false; @@ -1588,7 +1702,7 @@ namespace gdjs { return joint.GetBodyA() === this._body; } - isJointSecondObject(jointId): boolean { + isJointSecondObject(jointId: integer | string): boolean { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return false; @@ -1606,7 +1720,7 @@ namespace gdjs { return joint.GetBodyB() === this._body; } - getJointFirstAnchorX(jointId): float { + getJointFirstAnchorX(jointId: integer | string): float { // Get the joint const joint = this._sharedData.getJoint(jointId); @@ -1616,10 +1730,11 @@ namespace gdjs { } // Get the joint anchor + // @ts-ignore GetLocalAnchorA is implemented by any joint but is not in the interface. return joint.GetBodyA().GetWorldPoint(joint.GetLocalAnchorA()).get_x(); } - getJointFirstAnchorY(jointId): float { + getJointFirstAnchorY(jointId: integer | string): float { // Get the joint const joint = this._sharedData.getJoint(jointId); @@ -1629,10 +1744,11 @@ namespace gdjs { } // Get the joint anchor + // @ts-ignore GetLocalAnchorA is implemented by any joint but is not in the interface. return joint.GetBodyA().GetWorldPoint(joint.GetLocalAnchorA()).get_y(); } - getJointSecondAnchorX(jointId): float { + getJointSecondAnchorX(jointId: integer | string): float { // Get the joint const joint = this._sharedData.getJoint(jointId); @@ -1642,10 +1758,11 @@ namespace gdjs { } // Get the joint anchor + // @ts-ignore GetLocalAnchorA is implemented by any joint but is not in the interface. return joint.GetBodyB().GetWorldPoint(joint.GetLocalAnchorB()).get_x(); } - getJointSecondAnchorY(jointId): float { + getJointSecondAnchorY(jointId: integer | string): float { // Get the joint const joint = this._sharedData.getJoint(jointId); @@ -1655,10 +1772,11 @@ namespace gdjs { } // Get the joint anchor + // @ts-ignore GetLocalAnchorA is implemented by any joint but is not in the interface. return joint.GetBodyB().GetWorldPoint(joint.GetLocalAnchorB()).get_y(); } - getJointReactionForce(jointId) { + getJointReactionForce(jointId: integer | string): float { // Get the joint const joint = this._sharedData.getJoint(jointId); @@ -1671,7 +1789,7 @@ namespace gdjs { return joint.GetReactionForce(1 / this._sharedData.timeStep).Length(); } - getJointReactionTorque(jointId) { + getJointReactionTorque(jointId: integer | string): float { // Get the joint const joint = this._sharedData.getJoint(jointId); @@ -1684,28 +1802,29 @@ namespace gdjs { return joint.GetReactionTorque(1 / this._sharedData.timeStep); } - removeJoint(jointId) { + removeJoint(jointId: integer | string): void { // Just let the sharedData to manage and delete the joint this._sharedData.removeJoint(jointId); } // Distance joint addDistanceJoint( - x1, - y1, - other, - x2, - y2, - length, - frequency, - dampingRatio, - collideConnected, - variable - ) { + x1: float, + y1: float, + other: gdjs.RuntimeObject, + x2: float, + y2: float, + length: float, + frequency: float, + dampingRatio: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // If there is no second object or it doesn't share the behavior, return if (other == null || !other.hasBehavior(this.name)) { @@ -1713,7 +1832,9 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { @@ -1722,9 +1843,9 @@ namespace gdjs { // Set joint settings const jointDef = new Box2D.b2DistanceJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_localAnchorA( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x1 * this._sharedData.invScaleX, y1 * this._sharedData.invScaleY @@ -1764,9 +1885,9 @@ namespace gdjs { variable.setNumber(jointId); } - getDistanceJointLength(jointId) { + getDistanceJointLength(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2DistanceJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_distanceJoint) { @@ -1777,14 +1898,14 @@ namespace gdjs { return joint.GetLength() * this._sharedData.scaleX; } - setDistanceJointLength(jointId, length): void { + setDistanceJointLength(jointId: integer | string, length: float): void { // Invalid value if (length <= 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2DistanceJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_distanceJoint) { @@ -1799,9 +1920,9 @@ namespace gdjs { joint.GetBodyB().SetAwake(true); } - getDistanceJointFrequency(jointId) { + getDistanceJointFrequency(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2DistanceJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_distanceJoint) { @@ -1812,14 +1933,17 @@ namespace gdjs { return joint.GetFrequency(); } - setDistanceJointFrequency(jointId, frequency): void { + setDistanceJointFrequency( + jointId: integer | string, + frequency: float + ): void { // Invalid value if (frequency < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2DistanceJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_distanceJoint) { @@ -1830,9 +1954,9 @@ namespace gdjs { joint.SetFrequency(frequency); } - getDistanceJointDampingRatio(jointId) { + getDistanceJointDampingRatio(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2DistanceJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_distanceJoint) { @@ -1843,14 +1967,17 @@ namespace gdjs { return joint.GetDampingRatio(); } - setDistanceJointDampingRatio(jointId, dampingRatio): void { + setDistanceJointDampingRatio( + jointId: integer | string, + dampingRatio: float + ): void { // Invalid value if (dampingRatio < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2DistanceJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_distanceJoint) { @@ -1862,21 +1989,22 @@ namespace gdjs { // Revolute joint addRevoluteJoint( - x, - y, - enableLimit, - referenceAngle, - lowerAngle, - upperAngle, - enableMotor, - motorSpeed, - maxMotorTorque, - variable - ) { + x: float, + y: float, + enableLimit: boolean, + referenceAngle: float, + lowerAngle: float, + upperAngle: float, + enableMotor: boolean, + motorSpeed: float, + maxMotorTorque: float, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Set joint settings const jointDef = new Box2D.b2RevoluteJointDef(); @@ -1889,9 +2017,9 @@ namespace gdjs { ) ) ); - jointDef.set_bodyB(this._body); + jointDef.set_bodyB(body); jointDef.set_localAnchorB( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x * this._sharedData.invScaleX, y * this._sharedData.invScaleY @@ -1927,21 +2055,21 @@ namespace gdjs { } addRevoluteJointBetweenTwoBodies( - x1, - y1, - other, - x2, - y2, - enableLimit, - referenceAngle, - lowerAngle, - upperAngle, - enableMotor, - motorSpeed, - maxMotorTorque, - collideConnected, - variable - ) { + x1: float, + y1: float, + other: gdjs.RuntimeObject, + x2: float, + y2: float, + enableLimit: boolean, + referenceAngle: float, + lowerAngle: float, + upperAngle: float, + enableMotor: boolean, + motorSpeed: float, + maxMotorTorque: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; @@ -1953,18 +2081,21 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { return; } + const body = this._body!; // Set joint settings const jointDef = new Box2D.b2RevoluteJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_localAnchorA( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x1 * this._sharedData.invScaleX, y1 * this._sharedData.invScaleY @@ -2008,9 +2139,9 @@ namespace gdjs { variable.setNumber(jointId); } - getRevoluteJointReferenceAngle(jointId): float { + getRevoluteJointReferenceAngle(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2021,9 +2152,9 @@ namespace gdjs { return gdjs.toDegrees(joint.GetReferenceAngle()); } - getRevoluteJointAngle(jointId): float { + getRevoluteJointAngle(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2034,9 +2165,9 @@ namespace gdjs { return gdjs.toDegrees(joint.GetJointAngle()); } - getRevoluteJointSpeed(jointId) { + getRevoluteJointSpeed(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2047,9 +2178,9 @@ namespace gdjs { return gdjs.toDegrees(joint.GetJointSpeed()); } - isRevoluteJointLimitsEnabled(jointId): boolean { + isRevoluteJointLimitsEnabled(jointId: integer | string): boolean { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2060,9 +2191,12 @@ namespace gdjs { return joint.IsLimitEnabled(); } - enableRevoluteJointLimits(jointId, enable): void { + enableRevoluteJointLimits( + jointId: integer | string, + enable: boolean + ): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2073,9 +2207,9 @@ namespace gdjs { joint.EnableLimit(enable); } - getRevoluteJointMinAngle(jointId): float { + getRevoluteJointMinAngle(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2086,9 +2220,9 @@ namespace gdjs { return gdjs.toDegrees(joint.GetLowerLimit()); } - getRevoluteJointMaxAngle(jointId): float { + getRevoluteJointMaxAngle(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2099,9 +2233,13 @@ namespace gdjs { return gdjs.toDegrees(joint.GetUpperLimit()); } - setRevoluteJointLimits(jointId, lowerAngle, upperAngle): void { + setRevoluteJointLimits( + jointId: integer | string, + lowerAngle: float, + upperAngle: float + ): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2119,9 +2257,9 @@ namespace gdjs { joint.SetLimits(gdjs.toRad(lowerAngle), gdjs.toRad(upperAngle)); } - isRevoluteJointMotorEnabled(jointId): boolean { + isRevoluteJointMotorEnabled(jointId: integer | string): boolean { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2132,9 +2270,9 @@ namespace gdjs { return joint.IsMotorEnabled(); } - enableRevoluteJointMotor(jointId, enable): void { + enableRevoluteJointMotor(jointId: integer | string, enable): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2145,9 +2283,9 @@ namespace gdjs { joint.EnableMotor(enable); } - getRevoluteJointMotorSpeed(jointId) { + getRevoluteJointMotorSpeed(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2158,9 +2296,9 @@ namespace gdjs { return gdjs.toDegrees(joint.GetMotorSpeed()); } - setRevoluteJointMotorSpeed(jointId, speed): void { + setRevoluteJointMotorSpeed(jointId: integer | string, speed): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2171,9 +2309,9 @@ namespace gdjs { joint.SetMotorSpeed(gdjs.toRad(speed)); } - getRevoluteJointMaxMotorTorque(jointId) { + getRevoluteJointMaxMotorTorque(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2184,14 +2322,14 @@ namespace gdjs { return joint.GetMaxMotorTorque(); } - setRevoluteJointMaxMotorTorque(jointId, maxTorque): void { + setRevoluteJointMaxMotorTorque(jointId: integer | string, maxTorque): void { // Invalid value if (maxTorque < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2202,9 +2340,9 @@ namespace gdjs { joint.SetMaxMotorTorque(maxTorque); } - getRevoluteJointMotorTorque(jointId) { + getRevoluteJointMotorTorque(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RevoluteJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_revoluteJoint) { @@ -2217,22 +2355,22 @@ namespace gdjs { // Prismatic joint addPrismaticJoint( - x1, - y1, - other, - x2, - y2, - axisAngle, - referenceAngle, - enableLimit, - lowerTranslation, - upperTranslation, - enableMotor, - motorSpeed, - maxMotorForce, - collideConnected, - variable - ) { + x1: float, + y1: float, + other: gdjs.RuntimeObject, + x2: float, + y2: float, + axisAngle: float, + referenceAngle: float, + enableLimit: boolean, + lowerTranslation: float, + upperTranslation: float, + enableMotor: boolean, + motorSpeed: float, + maxMotorForce: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; @@ -2244,18 +2382,21 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { return; } + const body = this._body!; // Set joint settings const jointDef = new Box2D.b2PrismaticJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_localAnchorA( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x1 * this._sharedData.invScaleX, y1 * this._sharedData.invScaleY @@ -2271,7 +2412,7 @@ namespace gdjs { ) ) ); - axisAngle = gdjs.toRad(axisAngle) - this._body.GetAngle(); + axisAngle = gdjs.toRad(axisAngle) - body.GetAngle(); jointDef.set_localAxisA( this.b2Vec2(Math.cos(axisAngle), Math.sin(axisAngle)) ); @@ -2309,9 +2450,11 @@ namespace gdjs { variable.setNumber(jointId); } - getPrismaticJointAxisAngle(jointId): float { + getPrismaticJointAxisAngle(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2327,9 +2470,11 @@ namespace gdjs { ); } - getPrismaticJointReferenceAngle(jointId): float { + getPrismaticJointReferenceAngle(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2340,9 +2485,11 @@ namespace gdjs { return gdjs.toDegrees(joint.GetReferenceAngle()); } - getPrismaticJointTranslation(jointId) { + getPrismaticJointTranslation(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2353,9 +2500,11 @@ namespace gdjs { return joint.GetJointTranslation() * this._sharedData.scaleX; } - getPrismaticJointSpeed(jointId) { + getPrismaticJointSpeed(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2366,9 +2515,11 @@ namespace gdjs { return joint.GetJointSpeed() * this._sharedData.scaleX; } - isPrismaticJointLimitsEnabled(jointId): boolean { + isPrismaticJointLimitsEnabled(jointId: integer | string): boolean { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2379,9 +2530,14 @@ namespace gdjs { return joint.IsLimitEnabled(); } - enablePrismaticJointLimits(jointId, enable): void { + enablePrismaticJointLimits( + jointId: integer | string, + enable: boolean + ): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2392,9 +2548,11 @@ namespace gdjs { joint.EnableLimit(enable); } - getPrismaticJointMinTranslation(jointId) { + getPrismaticJointMinTranslation(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2405,9 +2563,11 @@ namespace gdjs { return joint.GetLowerLimit() * this._sharedData.scaleX; } - getPrismaticJointMaxTranslation(jointId) { + getPrismaticJointMaxTranslation(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2418,9 +2578,15 @@ namespace gdjs { return joint.GetUpperLimit() * this._sharedData.scaleX; } - setPrismaticJointLimits(jointId, lowerTranslation, upperTranslation): void { + setPrismaticJointLimits( + jointId: integer | string, + lowerTranslation: float, + upperTranslation: float + ): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2445,9 +2611,11 @@ namespace gdjs { ); } - isPrismaticJointMotorEnabled(jointId): boolean { + isPrismaticJointMotorEnabled(jointId: integer | string): boolean { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2458,9 +2626,14 @@ namespace gdjs { return joint.IsMotorEnabled(); } - enablePrismaticJointMotor(jointId, enable): void { + enablePrismaticJointMotor( + jointId: integer | string, + enable: boolean + ): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2471,9 +2644,11 @@ namespace gdjs { joint.EnableMotor(enable); } - getPrismaticJointMotorSpeed(jointId) { + getPrismaticJointMotorSpeed(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2484,9 +2659,11 @@ namespace gdjs { return joint.GetMotorSpeed() * this._sharedData.scaleX; } - setPrismaticJointMotorSpeed(jointId, speed): void { + setPrismaticJointMotorSpeed(jointId: integer | string, speed): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2497,9 +2674,11 @@ namespace gdjs { joint.SetMotorSpeed(speed * this._sharedData.invScaleX); } - getPrismaticJointMaxMotorForce(jointId) { + getPrismaticJointMaxMotorForce(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2510,14 +2689,16 @@ namespace gdjs { return joint.GetMaxMotorForce(); } - setPrismaticJointMaxMotorForce(jointId, maxForce): void { + setPrismaticJointMaxMotorForce(jointId: integer | string, maxForce): void { // Invalid value if (maxForce < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2528,9 +2709,11 @@ namespace gdjs { joint.SetMaxMotorForce(maxForce); } - getPrismaticJointMotorForce(jointId) { + getPrismaticJointMotorForce(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint( + jointId + ) as Box2D.b2PrismaticJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_prismaticJoint) { @@ -2543,25 +2726,26 @@ namespace gdjs { // Pulley joint addPulleyJoint( - x1, - y1, - other, - x2, - y2, - groundX1, - groundY1, - groundX2, - groundY2, - lengthA, - lengthB, - ratio, - collideConnected, - variable - ) { + x1: float, + y1: float, + other: gdjs.RuntimeObject, + x2: float, + y2: float, + groundX1: float, + groundY1: float, + groundX2: float, + groundY2: float, + lengthA: float, + lengthB: float, + ratio: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // If there is no second object or it doesn't share the behavior, return if (other == null || !other.hasBehavior(this.name)) { @@ -2569,7 +2753,9 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { @@ -2578,9 +2764,9 @@ namespace gdjs { // Set joint settings const jointDef = new Box2D.b2PulleyJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_localAnchorA( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x1 * this._sharedData.invScaleX, y1 * this._sharedData.invScaleY @@ -2639,9 +2825,9 @@ namespace gdjs { variable.setNumber(jointId); } - getPulleyJointFirstGroundAnchorX(jointId): float { + getPulleyJointFirstGroundAnchorX(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2PulleyJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_pulleyJoint) { @@ -2652,9 +2838,9 @@ namespace gdjs { return joint.GetGroundAnchorA().get_x() * this._sharedData.scaleX; } - getPulleyJointFirstGroundAnchorY(jointId): float { + getPulleyJointFirstGroundAnchorY(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2PulleyJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_pulleyJoint) { @@ -2665,9 +2851,9 @@ namespace gdjs { return joint.GetGroundAnchorA().get_y() * this._sharedData.scaleY; } - getPulleyJointSecondGroundAnchorX(jointId): float { + getPulleyJointSecondGroundAnchorX(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2PulleyJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_pulleyJoint) { @@ -2678,9 +2864,9 @@ namespace gdjs { return joint.GetGroundAnchorB().get_x() * this._sharedData.scaleX; } - getPulleyJointSecondGroundAnchorY(jointId): float { + getPulleyJointSecondGroundAnchorY(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2PulleyJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_pulleyJoint) { @@ -2691,9 +2877,9 @@ namespace gdjs { return joint.GetGroundAnchorB().get_y() * this._sharedData.scaleY; } - getPulleyJointFirstLength(jointId) { + getPulleyJointFirstLength(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2PulleyJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_pulleyJoint) { @@ -2704,9 +2890,9 @@ namespace gdjs { return joint.GetCurrentLengthA() * this._sharedData.scaleX; } - getPulleyJointSecondLength(jointId) { + getPulleyJointSecondLength(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2PulleyJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_pulleyJoint) { @@ -2717,9 +2903,9 @@ namespace gdjs { return joint.GetCurrentLengthB() * this._sharedData.scaleX; } - getPulleyJointRatio(jointId) { + getPulleyJointRatio(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2PulleyJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_pulleyJoint) { @@ -2736,6 +2922,7 @@ namespace gdjs { if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Get the first joint const joint1 = this._sharedData.getJoint(jointId1); @@ -2770,7 +2957,7 @@ namespace gdjs { // Set gear joint bodies is not necessary at first, as the gear get the bodies from the two child joints // But we must pass two different bodies to bypass a test inherited from b2Joint jointDef.set_bodyA(this._sharedData.staticBody); - jointDef.set_bodyB(this._body); + jointDef.set_bodyB(body); jointDef.set_joint1(joint1); jointDef.set_joint2(joint2); jointDef.set_ratio(ratio); @@ -2788,9 +2975,9 @@ namespace gdjs { variable.setNumber(jointId); } - getGearJointFirstJoint(jointId) { + getGearJointFirstJoint(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2GearJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_gearJoint) { @@ -2801,9 +2988,9 @@ namespace gdjs { return this._sharedData.getJointId(joint.GetJoint1()); } - getGearJointSecondJoint(jointId) { + getGearJointSecondJoint(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2GearJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_gearJoint) { @@ -2814,9 +3001,9 @@ namespace gdjs { return this._sharedData.getJointId(joint.GetJoint2()); } - getGearJointRatio(jointId) { + getGearJointRatio(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2GearJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_gearJoint) { @@ -2827,9 +3014,9 @@ namespace gdjs { return joint.GetRatio(); } - setGearJointRatio(jointId, ratio): void { + setGearJointRatio(jointId: integer | string, ratio: float): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2GearJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_gearJoint) { @@ -2846,22 +3033,23 @@ namespace gdjs { // Mouse joint addMouseJoint( - targetX, - targetY, - maxForce, - frequency, - dampingRatio, - variable - ) { + targetX: float, + targetY: float, + maxForce: float, + frequency: float, + dampingRatio: float, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // Set joint settings const jointDef = new Box2D.b2MouseJointDef(); jointDef.set_bodyA(this._sharedData.staticBody); - jointDef.set_bodyB(this._body); + jointDef.set_bodyB(body); jointDef.set_target( this.b2Vec2( targetX * this._sharedData.invScaleX, @@ -2884,8 +3072,8 @@ namespace gdjs { variable.setNumber(jointId); } - getMouseJointTargetX(jointId): float { - const joint = this._sharedData.getJoint(jointId); + getMouseJointTargetX(jointId: integer | string): float { + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -2896,8 +3084,8 @@ namespace gdjs { return joint.GetTarget().get_x() * this._sharedData.scaleX; } - getMouseJointTargetY(jointId): float { - const joint = this._sharedData.getJoint(jointId); + getMouseJointTargetY(jointId: integer | string): float { + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -2908,8 +3096,12 @@ namespace gdjs { return joint.GetTarget().get_y() * this._sharedData.scaleY; } - setMouseJointTarget(jointId, targetX, targetY): void { - const joint = this._sharedData.getJoint(jointId); + setMouseJointTarget( + jointId: integer | string, + targetX: float, + targetY: float + ): void { + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -2928,8 +3120,8 @@ namespace gdjs { joint.GetBodyB().SetAwake(true); } - getMouseJointMaxForce(jointId) { - const joint = this._sharedData.getJoint(jointId); + getMouseJointMaxForce(jointId: integer | string): float { + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -2940,12 +3132,12 @@ namespace gdjs { return joint.GetMaxForce(); } - setMouseJointMaxForce(jointId, maxForce): void { + setMouseJointMaxForce(jointId: integer | string, maxForce: float): void { // Invalid value if (maxForce < 0) { return; } - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -2956,8 +3148,8 @@ namespace gdjs { joint.SetMaxForce(maxForce); } - getMouseJointFrequency(jointId) { - const joint = this._sharedData.getJoint(jointId); + getMouseJointFrequency(jointId: integer | string): float { + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -2968,12 +3160,12 @@ namespace gdjs { return joint.GetFrequency(); } - setMouseJointFrequency(jointId, frequency): void { + setMouseJointFrequency(jointId: integer | string, frequency: float): void { // Invalid value if (frequency <= 0) { return; } - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -2984,8 +3176,8 @@ namespace gdjs { joint.SetFrequency(frequency); } - getMouseJointDampingRatio(jointId) { - const joint = this._sharedData.getJoint(jointId); + getMouseJointDampingRatio(jointId: integer | string): float { + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -2996,12 +3188,15 @@ namespace gdjs { return joint.GetDampingRatio(); } - setMouseJointDampingRatio(jointId, dampingRatio): void { + setMouseJointDampingRatio( + jointId: integer | string, + dampingRatio: float + ): void { // Invalid value if (dampingRatio < 0) { return; } - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MouseJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_mouseJoint) { @@ -3014,24 +3209,25 @@ namespace gdjs { // Wheel joint addWheelJoint( - x1, - y1, - other, - x2, - y2, - axisAngle, - frequency, - dampingRatio, - enableMotor, - motorSpeed, - maxMotorTorque, - collideConnected, - variable - ) { + x1: float, + y1: float, + other: gdjs.RuntimeObject, + x2: float, + y2: float, + axisAngle: float, + frequency: float, + dampingRatio: float, + enableMotor: boolean, + motorSpeed: float, + maxMotorTorque: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // If there is no second object or it doesn't share the behavior, return if (other == null || !other.hasBehavior(this.name)) { @@ -3039,7 +3235,9 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { @@ -3048,9 +3246,9 @@ namespace gdjs { // Set joint settings const jointDef = new Box2D.b2WheelJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_localAnchorA( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x1 * this._sharedData.invScaleX, y1 * this._sharedData.invScaleY @@ -3066,7 +3264,7 @@ namespace gdjs { ) ) ); - axisAngle = gdjs.toRad(axisAngle) - this._body.GetAngle(); + axisAngle = gdjs.toRad(axisAngle) - body.GetAngle(); jointDef.set_localAxisA( this.b2Vec2(Math.cos(axisAngle), Math.sin(axisAngle)) ); @@ -3089,9 +3287,9 @@ namespace gdjs { variable.setNumber(jointId); } - getWheelJointAxisAngle(jointId): float { + getWheelJointAxisAngle(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3107,9 +3305,9 @@ namespace gdjs { ); } - getWheelJointTranslation(jointId) { + getWheelJointTranslation(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3120,9 +3318,9 @@ namespace gdjs { return joint.GetJointTranslation() * this._sharedData.scaleX; } - getWheelJointSpeed(jointId) { + getWheelJointSpeed(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3133,9 +3331,9 @@ namespace gdjs { return gdjs.toDegrees(joint.GetJointSpeed()); } - isWheelJointMotorEnabled(jointId): boolean { + isWheelJointMotorEnabled(jointId: integer | string): boolean { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3146,9 +3344,9 @@ namespace gdjs { return joint.IsMotorEnabled(); } - enableWheelJointMotor(jointId, enable): void { + enableWheelJointMotor(jointId: integer | string, enable): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3159,9 +3357,9 @@ namespace gdjs { joint.EnableMotor(enable); } - getWheelJointMotorSpeed(jointId) { + getWheelJointMotorSpeed(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3172,9 +3370,9 @@ namespace gdjs { return gdjs.toDegrees(joint.GetMotorSpeed()); } - setWheelJointMotorSpeed(jointId, speed): void { + setWheelJointMotorSpeed(jointId: integer | string, speed): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3185,9 +3383,9 @@ namespace gdjs { joint.SetMotorSpeed(gdjs.toRad(speed)); } - getWheelJointMaxMotorTorque(jointId) { + getWheelJointMaxMotorTorque(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3198,14 +3396,17 @@ namespace gdjs { return joint.GetMaxMotorTorque(); } - setWheelJointMaxMotorTorque(jointId, maxTorque): void { + setWheelJointMaxMotorTorque( + jointId: integer | string, + maxTorque: float + ): void { // Invalid value if (maxTorque < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3216,9 +3417,9 @@ namespace gdjs { joint.SetMaxMotorTorque(maxTorque); } - getWheelJointMotorTorque(jointId) { + getWheelJointMotorTorque(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3229,9 +3430,9 @@ namespace gdjs { return joint.GetMotorTorque(1 / this._sharedData.timeStep); } - getWheelJointFrequency(jointId) { + getWheelJointFrequency(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3242,14 +3443,14 @@ namespace gdjs { return joint.GetSpringFrequencyHz(); } - setWheelJointFrequency(jointId, frequency): void { + setWheelJointFrequency(jointId: integer | string, frequency): void { // Invalid value if (frequency < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3260,9 +3461,9 @@ namespace gdjs { joint.SetSpringFrequencyHz(frequency); } - getWheelJointDampingRatio(jointId) { + getWheelJointDampingRatio(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3273,14 +3474,14 @@ namespace gdjs { return joint.GetSpringDampingRatio(); } - setWheelJointDampingRatio(jointId, dampingRatio): void { + setWheelJointDampingRatio(jointId: integer | string, dampingRatio): void { // Invalid value if (dampingRatio < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WheelJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_wheelJoint) { @@ -3293,17 +3494,17 @@ namespace gdjs { // Weld joint addWeldJoint( - x1, - y1, - other, - x2, - y2, - referenceAngle, - frequency, - dampingRatio, - collideConnected, - variable - ) { + x1: float, + y1: float, + other: gdjs.RuntimeObject, + x2: float, + y2: float, + referenceAngle: float, + frequency: float, + dampingRatio: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; @@ -3315,18 +3516,21 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { return; } + const body = this._body!; // Set joint settings const jointDef = new Box2D.b2WeldJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_localAnchorA( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x1 * this._sharedData.invScaleX, y1 * this._sharedData.invScaleY @@ -3353,30 +3557,30 @@ namespace gdjs { Box2D.b2WeldJoint ); - // b2WeldJoint.GetReferenceAngle() is not binded, store it manually + // @ts-ignore b2WeldJoint.GetReferenceAngle() is not binded, store it manually joint.referenceAngle = jointDef.get_referenceAngle(); // Store the id in the variable variable.setNumber(this._sharedData.addJoint(joint)); } - getWeldJointReferenceAngle(jointId): float { + getWeldJointReferenceAngle(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WeldJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_weldJoint) { return 0; } - // b2WeldJoint.GetReferenceAngle() is not binded - // return gdjs.toDegrees(joint.GetReferenceAngle()); + // @ts-ignore b2WeldJoint.GetReferenceAngle() is not binded return gdjs.toDegrees(joint.referenceAngle); + // return gdjs.toDegrees(joint.GetReferenceAngle()); } - getWeldJointFrequency(jointId) { + getWeldJointFrequency(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WeldJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_weldJoint) { @@ -3387,14 +3591,14 @@ namespace gdjs { return joint.GetFrequency(); } - setWeldJointFrequency(jointId, frequency): void { + setWeldJointFrequency(jointId: integer | string, frequency: float): void { // Invalid value if (frequency < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WeldJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_weldJoint) { @@ -3405,9 +3609,9 @@ namespace gdjs { joint.SetFrequency(frequency); } - getWeldJointDampingRatio(jointId) { + getWeldJointDampingRatio(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WeldJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_weldJoint) { @@ -3418,14 +3622,17 @@ namespace gdjs { return joint.GetDampingRatio(); } - setWeldJointDampingRatio(jointId, dampingRatio): void { + setWeldJointDampingRatio( + jointId: integer | string, + dampingRatio: float + ): void { // Invalid value if (dampingRatio < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2WeldJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_weldJoint) { @@ -3437,11 +3644,21 @@ namespace gdjs { } // Rope joint - addRopeJoint(x1, y1, other, x2, y2, maxLength, collideConnected, variable) { + addRopeJoint( + x1: float, + y1: float, + other: gdjs.RuntimeObject, + x2: float, + y2: float, + maxLength: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // If there is no second object or it doesn't share the behavior, return if (other == null || !other.hasBehavior(this.name)) { @@ -3449,7 +3666,9 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { @@ -3458,9 +3677,9 @@ namespace gdjs { // Set joint settings const jointDef = new Box2D.b2RopeJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_localAnchorA( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x1 * this._sharedData.invScaleX, y1 * this._sharedData.invScaleY @@ -3498,9 +3717,9 @@ namespace gdjs { variable.setNumber(jointId); } - getRopeJointMaxLength(jointId) { + getRopeJointMaxLength(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RopeJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_ropeJoint) { @@ -3511,14 +3730,14 @@ namespace gdjs { return joint.GetMaxLength() * this._sharedData.scaleX; } - setRopeJointMaxLength(jointId, maxLength): void { + setRopeJointMaxLength(jointId: integer | string, maxLength: float): void { // Invalid value if (maxLength < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2RopeJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_ropeJoint) { @@ -3535,16 +3754,16 @@ namespace gdjs { // Friction joint addFrictionJoint( - x1, - y1, - other, - x2, - y2, - maxForce, - maxTorque, - collideConnected, - variable - ) { + x1: float, + y1: float, + other: gdjs.RuntimeObject, + x2: float, + y2: float, + maxForce: float, + maxTorque: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; @@ -3556,18 +3775,21 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { return; } + const body = this._body!; // Set joint settings const jointDef = new Box2D.b2FrictionJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_localAnchorA( - this._body.GetLocalPoint( + body.GetLocalPoint( this.b2Vec2( x1 * this._sharedData.invScaleX, y1 * this._sharedData.invScaleY @@ -3599,9 +3821,9 @@ namespace gdjs { variable.setNumber(jointId); } - getFrictionJointMaxForce(jointId) { + getFrictionJointMaxForce(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2FrictionJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_frictionJoint) { @@ -3612,14 +3834,14 @@ namespace gdjs { return joint.GetMaxForce(); } - setFrictionJointMaxForce(jointId, maxForce): void { + setFrictionJointMaxForce(jointId: integer | string, maxForce: float): void { // Invalid value if (maxForce < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2FrictionJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_frictionJoint) { @@ -3630,9 +3852,9 @@ namespace gdjs { joint.SetMaxForce(maxForce); } - getFrictionJointMaxTorque(jointId) { + getFrictionJointMaxTorque(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2FrictionJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_frictionJoint) { @@ -3643,14 +3865,17 @@ namespace gdjs { return joint.GetMaxTorque(); } - setFrictionJointMaxTorque(jointId, maxTorque): void { + setFrictionJointMaxTorque( + jointId: integer | string, + maxTorque: float + ): void { // Invalid value if (maxTorque < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2FrictionJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_frictionJoint) { @@ -3663,20 +3888,21 @@ namespace gdjs { // Motor joint addMotorJoint( - other, - offsetX, - offsetY, - offsetAngle, - maxForce, - maxTorque, - correctionFactor, - collideConnected, - variable - ) { + other: gdjs.RuntimeObject, + offsetX: float, + offsetY: float, + offsetAngle: float, + maxForce: float, + maxTorque: float, + correctionFactor: float, + collideConnected: boolean, + variable: gdjs.Variable + ): void { // If there is no body, set a new one if (this._body === null) { if (!this.createBody()) return; } + const body = this._body!; // If there is no second object or it doesn't share the behavior, return if (other == null || !other.hasBehavior(this.name)) { @@ -3684,7 +3910,9 @@ namespace gdjs { } // Get the second body - const otherBody = other.getBehavior(this.name).getBody(); + const otherBody = (other.getBehavior( + this.name + ) as gdjs.Physics2RuntimeBehavior).getBody(); // If the first and second objects/bodies are the same, return if (this._body === otherBody) { @@ -3693,7 +3921,7 @@ namespace gdjs { // Set joint settings const jointDef = new Box2D.b2MotorJointDef(); - jointDef.set_bodyA(this._body); + jointDef.set_bodyA(body); jointDef.set_bodyB(otherBody); jointDef.set_linearOffset( this.b2Vec2( @@ -3721,9 +3949,9 @@ namespace gdjs { variable.setNumber(jointId); } - getMotorJointOffsetX(jointId): float { + getMotorJointOffsetX(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3734,9 +3962,9 @@ namespace gdjs { return joint.GetLinearOffset().get_x() * this._sharedData.scaleX; } - getMotorJointOffsetY(jointId): float { + getMotorJointOffsetY(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3747,9 +3975,13 @@ namespace gdjs { return joint.GetLinearOffset().get_y() * this._sharedData.scaleY; } - setMotorJointOffset(jointId, offsetX, offsetY): void { + setMotorJointOffset( + jointId: integer | string, + offsetX: float, + offsetY: float + ): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3765,9 +3997,9 @@ namespace gdjs { ); } - getMotorJointAngularOffset(jointId) { + getMotorJointAngularOffset(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3778,9 +4010,12 @@ namespace gdjs { return gdjs.toDegrees(joint.GetAngularOffset()); } - setMotorJointAngularOffset(jointId, offsetAngle): void { + setMotorJointAngularOffset( + jointId: integer | string, + offsetAngle: float + ): void { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3791,9 +4026,9 @@ namespace gdjs { joint.SetAngularOffset(gdjs.toRad(offsetAngle)); } - getMotorJointMaxForce(jointId) { + getMotorJointMaxForce(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3804,14 +4039,14 @@ namespace gdjs { return joint.GetMaxForce(); } - setMotorJointMaxForce(jointId, maxForce): void { + setMotorJointMaxForce(jointId: integer | string, maxForce: float): void { // Invalid value if (maxForce < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3822,9 +4057,9 @@ namespace gdjs { joint.SetMaxForce(maxForce); } - getMotorJointMaxTorque(jointId) { + getMotorJointMaxTorque(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3835,14 +4070,14 @@ namespace gdjs { return joint.GetMaxTorque(); } - setMotorJointMaxTorque(jointId, maxTorque): void { + setMotorJointMaxTorque(jointId: integer | string, maxTorque: float): void { // Invalid value if (maxTorque < 0) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3857,9 +4092,9 @@ namespace gdjs { joint.GetBodyB().SetAwake(true); } - getMotorJointCorrectionFactor(jointId) { + getMotorJointCorrectionFactor(jointId: integer | string): float { // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3870,14 +4105,17 @@ namespace gdjs { return joint.GetCorrectionFactor(); } - setMotorJointCorrectionFactor(jointId, correctionFactor): void { + setMotorJointCorrectionFactor( + jointId: integer | string, + correctionFactor: float + ): void { // Invalid value if (correctionFactor < 0 || correctionFactor > 1) { return; } // Get the joint - const joint = this._sharedData.getJoint(jointId); + const joint = this._sharedData.getJoint(jointId) as Box2D.b2MotorJoint; // Joint not found or has wrong type if (joint === null || joint.GetType() !== Box2D.e_motorJoint) { @@ -3892,7 +4130,7 @@ namespace gdjs { joint.GetBodyB().SetAwake(true); } - onContactBegin(otherBehavior: Physics2RuntimeBehavior) { + onContactBegin(otherBehavior: Physics2RuntimeBehavior): void { this.currentContacts.push(otherBehavior); // There might be contacts that end during the frame and @@ -3906,7 +4144,7 @@ namespace gdjs { } } - onContactEnd(otherBehavior: Physics2RuntimeBehavior) { + onContactEnd(otherBehavior: Physics2RuntimeBehavior): void { this.contactsEndedThisFrame.push(otherBehavior); const index = this.currentContacts.indexOf(otherBehavior);