Refactor ball shape dispatch
This commit is contained in:
16
src/spawn.js
16
src/spawn.js
@@ -265,6 +265,12 @@
|
||||
return { bodies: [body], constraints: [], blobId: null };
|
||||
};
|
||||
|
||||
const ballShapeFactories = {
|
||||
gift: createGiftBall,
|
||||
rect: createRectBall,
|
||||
circle: createCircleBall,
|
||||
};
|
||||
|
||||
const createBallBodies = (x, y, color) => {
|
||||
const scene = getCurrentScene();
|
||||
const ballPhysics = scene?.config?.ballPhysics || {};
|
||||
@@ -287,13 +293,9 @@
|
||||
if (scene?.config?.blobBalls === "jagged") {
|
||||
return createJaggedBall(x, y, color, commonOpts);
|
||||
}
|
||||
if (scene?.config?.ballShape === "gift") {
|
||||
return createGiftBall(x, y, color, commonOpts, scene, debugSpawn);
|
||||
}
|
||||
if (scene?.config?.ballShape === "rect") {
|
||||
return createRectBall(x, y, color, commonOpts);
|
||||
}
|
||||
return createCircleBall(x, y, color, commonOpts);
|
||||
const shape = scene?.config?.ballShape || "circle";
|
||||
const factory = ballShapeFactories[shape] || createCircleBall;
|
||||
return factory(x, y, color, commonOpts, scene, debugSpawn);
|
||||
};
|
||||
|
||||
const spawnBall = () => {
|
||||
|
||||
Reference in New Issue
Block a user