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 };
|
return { bodies: [body], constraints: [], blobId: null };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const ballShapeFactories = {
|
||||||
|
gift: createGiftBall,
|
||||||
|
rect: createRectBall,
|
||||||
|
circle: createCircleBall,
|
||||||
|
};
|
||||||
|
|
||||||
const createBallBodies = (x, y, color) => {
|
const createBallBodies = (x, y, color) => {
|
||||||
const scene = getCurrentScene();
|
const scene = getCurrentScene();
|
||||||
const ballPhysics = scene?.config?.ballPhysics || {};
|
const ballPhysics = scene?.config?.ballPhysics || {};
|
||||||
@@ -287,13 +293,9 @@
|
|||||||
if (scene?.config?.blobBalls === "jagged") {
|
if (scene?.config?.blobBalls === "jagged") {
|
||||||
return createJaggedBall(x, y, color, commonOpts);
|
return createJaggedBall(x, y, color, commonOpts);
|
||||||
}
|
}
|
||||||
if (scene?.config?.ballShape === "gift") {
|
const shape = scene?.config?.ballShape || "circle";
|
||||||
return createGiftBall(x, y, color, commonOpts, scene, debugSpawn);
|
const factory = ballShapeFactories[shape] || createCircleBall;
|
||||||
}
|
return factory(x, y, color, commonOpts, scene, debugSpawn);
|
||||||
if (scene?.config?.ballShape === "rect") {
|
|
||||||
return createRectBall(x, y, color, commonOpts);
|
|
||||||
}
|
|
||||||
return createCircleBall(x, y, color, commonOpts);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const spawnBall = () => {
|
const spawnBall = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user