0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-27 13:59:01 -05:00

changed demo to auto populate examples with sourceLink and init

This commit is contained in:
liabru 2019-09-15 18:36:26 +01:00
parent 823bbc0b5f
commit 5b0d34b9e0
44 changed files with 100 additions and 303 deletions

View file

@ -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',
@ -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);

View file

@ -80,6 +80,6 @@ Example.airFriction = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -91,6 +91,6 @@ Example.avalanche = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -99,6 +99,6 @@ Example.ballPool = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -124,6 +124,6 @@ Example.bridge = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -95,6 +95,6 @@ Example.broadphase = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -89,6 +89,6 @@ Example.car = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -96,6 +96,6 @@ Example.catapult = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -122,6 +122,6 @@ Example.chains = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -81,6 +81,6 @@ Example.circleStack = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -84,6 +84,6 @@ Example.cloth = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -155,6 +155,6 @@ Example.collisionFiltering = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -107,6 +107,6 @@ Example.compositeManipulation = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -106,6 +106,6 @@ Example.compound = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -89,6 +89,6 @@ Example.compoundStack = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -95,6 +95,6 @@ Example.concave = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -179,6 +179,6 @@ Example.constraints = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -152,6 +152,6 @@ Example.doublePendulum = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -178,6 +178,6 @@ Example.events = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -90,6 +90,6 @@ Example.friction = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -96,6 +96,6 @@ Example.gravity = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -130,6 +130,6 @@ Example.gyro = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -140,6 +140,6 @@ Example.manipulation = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -105,6 +105,6 @@ Example.mixed = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -76,6 +76,6 @@ Example.newtonsCradle = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -81,6 +81,6 @@ Example.pyramid = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -497,6 +497,6 @@ Example.ragdoll.ragdoll = function(x, y, scale, options) {
return person;
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -135,6 +135,6 @@ Example.raycasting = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -85,6 +85,6 @@ Example.restitution = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -109,6 +109,6 @@ Example.rounded = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -131,6 +131,6 @@ Example.sensors = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -104,6 +104,6 @@ Example.sleeping = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -100,6 +100,6 @@ Example.slingshot = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -85,6 +85,6 @@ Example.softBody = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -113,6 +113,6 @@ Example.sprites = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -81,6 +81,6 @@ Example.stack = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -106,6 +106,6 @@ Example.staticFriction = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -79,6 +79,6 @@ Example.stress = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -79,6 +79,6 @@ Example.stress2 = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -124,6 +124,6 @@ Example.svg = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -105,6 +105,6 @@ Example.terrain = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example;
}

View file

@ -151,6 +151,6 @@ Example.timescale = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -182,6 +182,6 @@ Example.views = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}

View file

@ -93,6 +93,6 @@ Example.wreckingBall = function() {
};
};
if (typeof module !== 'undefined' && module.exports) {
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}