MCPcopy Create free account
hub / github.com/melonjs/melonJS / resolvePhysicSetting

Function resolvePhysicSetting

packages/melonjs/src/application/application.ts:88–106  ·  view source on GitHub ↗

* Resolve the user-supplied `physic` setting into the (optional) adapter * to pass into the World constructor plus the legacy "builtin" * / "none" string the rest of the engine still reads via `world.physic`. * * Accepted shapes: * - `"builtin"` / `undefined` → World constructs its own

(physic: ApplicationSettings["physic"])

Source from the content-addressed store, hash-verified

86 * @ignore
87 */
88function resolvePhysicSetting(physic: ApplicationSettings["physic"]): {
89 adapter: PhysicsAdapter | undefined;
90 physicLabel: string;
91} {
92 if (physic === "none") {
93 return { adapter: undefined, physicLabel: "none" };
94 }
95 if (physic === undefined || physic === "builtin") {
96 return { adapter: undefined, physicLabel: "builtin" };
97 }
98 // instance or { adapter } object — extract and pass through. The
99 // adapter's `physicLabel` becomes `world.physic` so user code can
100 // branch on `world.physic === "matter"` (etc.) without importing the
101 // concrete adapter class. Falls back to "builtin" for adapters
102 // predating the `physicLabel` field.
103 const adapter =
104 typeof physic === "object" && "adapter" in physic ? physic.adapter : physic;
105 return { adapter, physicLabel: adapter?.physicLabel ?? "builtin" };
106}
107
108/**
109 * The Application class is the main entry point for creating a melonJS game.

Callers 1

initMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected