Skip to content

Commit

Permalink
changed demo to auto populate examples with sourceLink and init
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Sep 15, 2019
1 parent 823bbc0 commit 5b0d34b
Show file tree
Hide file tree
Showing 44 changed files with 100 additions and 303 deletions.
317 changes: 57 additions & 260 deletions demo/js/Demo.js
Expand Up @@ -7,8 +7,64 @@
*/

(function() {
var examples = [
{ name: 'Air Friction', id: 'airFriction' },
{ name: 'Avalanche', id: 'avalanche' },
{ name: 'Ball Pool', id: 'ballPool' },
{ name: 'Bridge', id: 'bridge' },
{ name: 'Broadphase', id: 'broadphase' },
{ name: 'Car', id: 'car' },
{ name: 'Catapult', id: 'catapult' },
{ name: 'Chains', id: 'chains' },
{ name: 'Circle Stack', id: 'circleStack' },
{ name: 'Cloth', id: 'cloth' },
{ name: 'Collision Filtering', id: 'collisionFiltering' },
{ name: 'Composite Manipulation', id: 'compositeManipulation' },
{ name: 'Compound Bodies', id: 'compound' },
{ name: 'Compound Stack', id: 'compoundStack' },
{ name: 'Concave', id: 'concave' },
{ name: 'Constraints', id: 'constraints' },
{ name: 'Double Pendulum', id: 'doublePendulum' },
{ name: 'Events', id: 'events' },
{ name: 'Friction', id: 'friction' },
{ name: 'Reverse Gravity', id: 'gravity' },
{ name: 'Gyroscope', id: 'gyro' },
{ name: 'Manipulation', id: 'manipulation' },
{ name: 'Mixed Shapes', id: 'mixed' },
{ name: 'Newton\'s Cradle', id: 'newtonsCradle' },
{ name: 'Ragdoll', id: 'ragdoll' },
{ name: 'Pyramid', id: 'pyramid' },
{ name: 'Raycasting', id: 'raycasting' },
{ name: 'Restitution', id: 'restitution' },
{ name: 'Rounded Corners (Chamfering)', id: 'rounded' },
{ name: 'Sensors', id: 'sensors' },
{ name: 'Sleeping', id: 'sleeping' },
{ name: 'Slingshot', id: 'slingshot' },
{ name: 'Soft Body', id: 'softBody' },
{ name: 'Sprites', id: 'sprites' },
{ name: 'Stack', id: 'stack' },
{ name: 'Static Friction', id: 'staticFriction' },
{ name: 'Stress', id: 'stress' },
{ name: 'Stress 2', id: 'stress2' },
{ name: 'Concave SVG Paths', id: 'svg' },
{ name: 'Terrain', id: 'terrain' },
{ name: 'Time Scaling', id: 'timescale' },
{ name: 'Views', id: 'views' },
{ name: 'Wrecking Ball', id: 'wreckingBall' }
];

var sourceLinkRoot = 'https://github.com/liabru/matter-js/blob/master/examples';

for (var i = 0; i < examples.length; i += 1) {
var example = examples[i];
example.sourceLink = sourceLinkRoot + '/' + example.id + '.js';
example.init = window.Example[example.id];

if (!example.init) {
console.warn('Example not loaded:', example.id);
}
}

var demo = MatterTools.Demo.create({
toolbar: {
title: 'matter-js',
Expand All @@ -29,266 +85,7 @@
resetOnOrientation: true,
routing: true,
startExample: 'mixed',
examples: [
{
name: 'Air Friction',
id: 'airFriction',
init: Example.airFriction,
sourceLink: sourceLinkRoot + '/airFriction.js'
},
{
name: 'Avalanche',
id: 'avalanche',
init: Example.avalanche,
sourceLink: sourceLinkRoot + '/avalanche.js'
},
{
name: 'Ball Pool',
id: 'ballPool',
init: Example.ballPool,
sourceLink: sourceLinkRoot + '/ballPool.js'
},
{
name: 'Bridge',
id: 'bridge',
init: Example.bridge,
sourceLink: sourceLinkRoot + '/bridge.js'
},
{
name: 'Broadphase',
id: 'broadphase',
init: Example.broadphase,
sourceLink: sourceLinkRoot + '/broadphase.js'
},
{
name: 'Car',
id: 'car',
init: Example.car,
sourceLink: sourceLinkRoot + '/car.js'
},
{
name: 'Catapult',
id: 'catapult',
init: Example.catapult,
sourceLink: sourceLinkRoot + '/catapult.js'
},
{
name: 'Chains',
id: 'chains',
init: Example.chains,
sourceLink: sourceLinkRoot + '/chains.js'
},
{
name: 'Circle Stack',
id: 'circleStack',
init: Example.circleStack,
sourceLink: sourceLinkRoot + '/circleStack.js'
},
{
name: 'Cloth',
id: 'cloth',
init: Example.cloth,
sourceLink: sourceLinkRoot + '/cloth.js'
},
{
name: 'Collision Filtering',
id: 'collisionFiltering',
init: Example.collisionFiltering,
sourceLink: sourceLinkRoot + '/collisionFiltering.js'
},
{
name: 'Composite Manipulation',
id: 'compositeManipulation',
init: Example.compositeManipulation,
sourceLink: sourceLinkRoot + '/compositeManipulation.js'
},
{
name: 'Compound Bodies',
id: 'compound',
init: Example.compound,
sourceLink: sourceLinkRoot + '/compound.js'
},
{
name: 'Compound Stack',
id: 'compoundStack',
init: Example.compoundStack,
sourceLink: sourceLinkRoot + '/compoundStack.js'
},
{
name: 'Concave',
id: 'concave',
init: Example.concave,
sourceLink: sourceLinkRoot + '/concave.js'
},
{
name: 'Constraints',
id: 'constraints',
init: Example.constraints,
sourceLink: sourceLinkRoot + '/constraints.js'
},
{
name: 'Double Pendulum',
id: 'doublePendulum',
init: Example.doublePendulum,
sourceLink: sourceLinkRoot + '/doublePendulum.js'
},
{
name: 'Events',
id: 'events',
init: Example.events,
sourceLink: sourceLinkRoot + '/events.js'
},
{
name: 'Friction',
id: 'friction',
init: Example.friction,
sourceLink: sourceLinkRoot + '/friction.js'
},
{
name: 'Reverse Gravity',
id: 'gravity',
init: Example.gravity,
sourceLink: sourceLinkRoot + '/gravity.js'
},
{
name: 'Gyroscope',
id: 'gyro',
init: Example.gyro,
sourceLink: sourceLinkRoot + '/gyro.js'
},
{
name: 'Manipulation',
id: 'manipulation',
init: Example.manipulation,
sourceLink: sourceLinkRoot + '/manipulation.js'
},
{
name: 'Mixed Shapes',
id: 'mixed',
init: Example.mixed,
sourceLink: sourceLinkRoot + '/mixed.js'
},
{
name: 'Newton\'s Cradle',
id: 'newtonsCradle',
init: Example.newtonsCradle,
sourceLink: sourceLinkRoot + '/newtonsCradle.js'
},
{
name: 'Ragdoll',
id: 'ragdoll',
init: Example.ragdoll,
sourceLink: sourceLinkRoot + '/ragdoll.js'
},
{
name: 'Pyramid',
id: 'pyramid',
init: Example.pyramid,
sourceLink: sourceLinkRoot + '/pyramid.js'
},
{
name: 'Raycasting',
id: 'raycasting',
init: Example.raycasting,
sourceLink: sourceLinkRoot + '/raycasting.js'
},
{
name: 'Restitution',
id: 'restitution',
init: Example.restitution,
sourceLink: sourceLinkRoot + '/restitution.js'
},
{
name: 'Rounded Corners (Chamfering)',
id: 'rounded',
init: Example.rounded,
sourceLink: sourceLinkRoot + '/rounded.js'
},
{
name: 'Sensors',
id: 'sensors',
init: Example.sensors,
sourceLink: sourceLinkRoot + '/sensors.js'
},
{
name: 'Sleeping',
id: 'sleeping',
init: Example.sleeping,
sourceLink: sourceLinkRoot + '/sleeping.js'
},
{
name: 'Slingshot',
id: 'slingshot',
init: Example.slingshot,
sourceLink: sourceLinkRoot + '/slingshot.js'
},
{
name: 'Soft Body',
id: 'softBody',
init: Example.softBody,
sourceLink: sourceLinkRoot + '/softBody.js'
},
{
name: 'Sprites',
id: 'sprites',
init: Example.sprites,
sourceLink: sourceLinkRoot + '/sprites.js'
},
{
name: 'Stack',
id: 'stack',
init: Example.stack,
sourceLink: sourceLinkRoot + '/stack.js'
},
{
name: 'Static Friction',
id: 'staticFriction',
init: Example.staticFriction,
sourceLink: sourceLinkRoot + '/staticFriction.js'
},
{
name: 'Stress',
id: 'stress',
init: Example.stress,
sourceLink: sourceLinkRoot + '/stress.js'
},
{
name: 'Stress 2',
id: 'stress2',
init: Example.stress2,
sourceLink: sourceLinkRoot + '/stress2.js'
},
{
name: 'Concave SVG Paths',
id: 'svg',
init: Example.svg,
sourceLink: sourceLinkRoot + '/svg.js'
},
{
name: 'Terrain',
id: 'terrain',
init: Example.terrain,
sourceLink: sourceLinkRoot + '/terrain.js'
},
{
name: 'Time Scaling',
id: 'timescale',
init: Example.timescale,
sourceLink: sourceLinkRoot + '/timescale.js'
},
{
name: 'Views',
id: 'views',
init: Example.views,
sourceLink: sourceLinkRoot + '/views.js'
},
{
name: 'Wrecking Ball',
id: 'wreckingBall',
init: Example.wreckingBall,
sourceLink: sourceLinkRoot + '/wreckingBall.js'
}
]
examples: examples
});

document.body.appendChild(demo.dom.root);
Expand Down
2 changes: 1 addition & 1 deletion examples/airFriction.js
Expand Up @@ -80,6 +80,6 @@ Example.airFriction = function() {
};
};

if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
2 changes: 1 addition & 1 deletion examples/avalanche.js
Expand Up @@ -91,6 +91,6 @@ Example.avalanche = function() {
};
};

if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
2 changes: 1 addition & 1 deletion examples/ballPool.js
Expand Up @@ -99,6 +99,6 @@ Example.ballPool = function() {
};
};

if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
2 changes: 1 addition & 1 deletion examples/bridge.js
Expand Up @@ -124,6 +124,6 @@ Example.bridge = function() {
};
};

if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
2 changes: 1 addition & 1 deletion examples/broadphase.js
Expand Up @@ -95,6 +95,6 @@ Example.broadphase = function() {
};
};

if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
2 changes: 1 addition & 1 deletion examples/car.js
Expand Up @@ -89,6 +89,6 @@ Example.car = function() {
};
};

if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
2 changes: 1 addition & 1 deletion examples/catapult.js
Expand Up @@ -96,6 +96,6 @@ Example.catapult = function() {
};
};

if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

0 comments on commit 5b0d34b

Please sign in to comment.