From e8f5b221f5e8dca42fd86abce632b4eff897b000 Mon Sep 17 00:00:00 2001 From: liabru Date: Fri, 25 Apr 2014 17:22:25 +0100 Subject: [PATCH] better default labels --- src/body/Body.js | 2 +- src/body/Composite.js | 2 +- src/constraint/Constraint.js | 2 +- src/factory/Bodies.js | 4 ++++ src/factory/Composites.js | 12 +++++++++--- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/body/Body.js b/src/body/Body.js index 9f1f7c6..2a24b0f 100644 --- a/src/body/Body.js +++ b/src/body/Body.js @@ -22,7 +22,7 @@ var Body = {}; var defaults = { id: Body.nextId(), type: 'body', - label: null, + label: 'Body', angle: 0, position: { x: 0, y: 0 }, force: { x: 0, y: 0 }, diff --git a/src/body/Composite.js b/src/body/Composite.js index b2a8bb7..441ecb2 100644 --- a/src/body/Composite.js +++ b/src/body/Composite.js @@ -28,7 +28,7 @@ var Composite = {}; bodies: [], constraints: [], composites: [], - label: null + label: 'Composite' }, options); }; diff --git a/src/constraint/Constraint.js b/src/constraint/Constraint.js index d76f2b1..1d71f38 100644 --- a/src/constraint/Constraint.js +++ b/src/constraint/Constraint.js @@ -54,7 +54,7 @@ var Constraint = {}; // option defaults constraint.id = constraint.id || Constraint.nextId(); - constraint.label = constraint.label; + constraint.label = constraint.label || 'Constraint'; constraint.type = 'constraint'; constraint.stiffness = constraint.stiffness || 1; constraint.angularStiffness = constraint.angularStiffness || 0; diff --git a/src/factory/Bodies.js b/src/factory/Bodies.js index 46bbd61..1ecb271 100644 --- a/src/factory/Bodies.js +++ b/src/factory/Bodies.js @@ -25,6 +25,7 @@ var Bodies = {}; options = options || {}; var rectangle = { + label: 'Rectangle Body', position: { x: x, y: y }, render: { path: 'L 0 0 L ' + width + ' 0 L ' + width + ' ' + height + ' L 0 ' + height @@ -56,6 +57,7 @@ var Bodies = {}; x3 = x2 + x1; var trapezoid = { + label: 'Trapezoid Body', position: { x: x, y: y }, render: { path: 'L 0 0 L ' + x1 + ' ' + (-height) + ' L ' + x2 + ' ' + (-height) + ' L ' + x3 + ' 0' @@ -77,6 +79,7 @@ var Bodies = {}; */ Bodies.circle = function(x, y, radius, options, maxSides) { options = options || {}; + options.label = 'Circle Body'; // approximate circles with polygons until true circles implemented in SAT @@ -122,6 +125,7 @@ var Bodies = {}; } var polygon = { + label: 'Polygon Body', position: { x: x, y: y }, render: { path: path diff --git a/src/factory/Composites.js b/src/factory/Composites.js index dc63e58..4ca199d 100644 --- a/src/factory/Composites.js +++ b/src/factory/Composites.js @@ -22,7 +22,7 @@ var Composites = {}; * @return {composite} A new composite containing objects created in the callback */ Composites.stack = function(xx, yy, columns, rows, columnGap, rowGap, callback) { - var stack = Composite.create(), + var stack = Composite.create({ label: 'Stack' }), x = xx, y = yy, lastBody, @@ -92,6 +92,8 @@ var Composites = {}; Composite.addConstraint(composite, Constraint.create(constraint)); } + + composite.label += ' Chain'; return composite; }; @@ -141,6 +143,8 @@ var Composites = {}; } } } + + composite.label += ' Mesh'; return composite; }; @@ -196,7 +200,7 @@ var Composites = {}; * @return {composite} A new composite newtonsCradle body */ Composites.newtonsCradle = function(xx, yy, number, size, length) { - var newtonsCradle = Composite.create(); + var newtonsCradle = Composite.create({ label: 'Newtons Cradle' }); for (var i = 0; i < number; i++) { var separation = 1.9, @@ -228,7 +232,7 @@ var Composites = {}; wheelBOffset = width * 0.5 - wheelBase, wheelYOffset = 0; - var car = Composite.create(), + var car = Composite.create({ label: 'Car' }), body = Bodies.trapezoid(xx, yy, width, height, 0.3, { groupId: groupId, friction: 0.01 }); var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, { @@ -293,6 +297,8 @@ var Composites = {}; Composites.mesh(softBody, columns, rows, crossBrace, constraintOptions); + softBody.label = 'Soft Body'; + return softBody; };