0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-27 09:50:52 -05:00

use browserify

This commit is contained in:
liabru 2015-06-04 20:54:50 +01:00
parent bc26469df2
commit 00251e5b04
34 changed files with 256 additions and 128 deletions

View file

@ -4,23 +4,11 @@ module.exports = function(grunt) {
buildName: 'matter',
buildVersion: 'edge-master',
docVersion: 'v<%= pkg.version %>',
concat: {
build: {
browserify: {
options: {
process: function(src, filepath) {
return '// Begin ' + filepath + '\n\n' + src + '\n\n; // End ' + filepath + '\n\n';
}
banner: '/**\n* <%= buildName %>.js <%= buildVersion %> <%= grunt.template.today("yyyy-mm-dd") %>\n* <%= pkg.homepage %>\n* License: <%= pkg.license %>\n*/\n\n',
},
src: ['src/**/*.js', '!src/module/*'],
dest: 'build/<%= buildName %>.js'
},
pack: {
options: {
banner: '/**\n* <%= buildName %>.js <%= buildVersion %> <%= grunt.template.today("yyyy-mm-dd") %>\n* <%= pkg.homepage %>\n* License: <%= pkg.license %>\n*/\n\n'
},
src: ['src/module/Intro.js', 'build/<%= buildName %>.js', 'src/module/Outro.js'],
dest: 'build/<%= buildName %>.js'
}
'build/<%= buildName %>.js': ['src/module/main.js']
},
uglify: {
min: {
@ -110,7 +98,7 @@ module.exports = function(grunt) {
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-browserify');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
@ -134,20 +122,20 @@ module.exports = function(grunt) {
if (isDev) {
grunt.config.set('buildName', 'matter-dev');
grunt.config.set('buildVersion', pkg.version + '-dev');
grunt.task.run('concat', 'uglify:dev', 'uglify:min', 'copy');
grunt.task.run('browserify', 'uglify:dev', 'uglify:min', 'copy');
}
// release build mode
if (isRelease) {
grunt.config.set('buildName', 'matter-' + pkg.version);
grunt.config.set('buildVersion', pkg.version + '-alpha');
grunt.task.run('concat', 'uglify:min', 'copy');
grunt.task.run('browserify', 'uglify:min', 'copy');
}
// edge build mode (default)
if (isEdge || (!isDev && !isRelease)) {
grunt.config.set('buildVersion', 'edge-master');
grunt.task.run('concat', 'preprocess', 'uglify:min');
grunt.task.run('browserify', 'preprocess', 'uglify:min');
}
});

View file

@ -21,7 +21,7 @@
],
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-concat": "~0.3.0",
"grunt-browserify": "~3.7.0",
"grunt-contrib-connect": "~0.6.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-jshint": "~0.6.3",

View file

@ -1,3 +1,11 @@
var Vertices = require('../geometry/Vertices');
var Vector = require('../geometry/Vector');
var Sleeping = require('../core/Sleeping');
var Render = require('../render/Render');
var Common = require('../core/Common');
var Bounds = require('../geometry/Bounds');
var Axes = require('../geometry/Axes');
/**
* The `Matter.Body` module contains methods for creating and manipulating body models.
* A `Matter.Body` is a rigid body that can be simulated by a `Matter.Engine`.
@ -11,6 +19,8 @@
var Body = {};
module.exports = Body;
(function() {
Body._inertiaScale = 4;

View file

@ -1,3 +1,7 @@
var Events = require('../core/Events');
var Common = require('../core/Common');
var Body = require('./Body');
/**
* The `Matter.Composite` module contains methods for creating and manipulating composite bodies.
* A composite body is a collection of `Matter.Body`, `Matter.Constraint` and other `Matter.Composite`, therefore composites form a tree structure.
@ -12,6 +16,8 @@
var Composite = {};
module.exports = Composite;
(function() {
/**

View file

@ -1,3 +1,7 @@
var Composite = require('./Composite');
var Constraint = require('../constraint/Constraint');
var Common = require('../core/Common');
/**
* The `Matter.World` module contains methods for creating and manipulating the world composite.
* A `Matter.World` is a `Matter.Composite` body, which is a collection of `Matter.Body`, `Matter.Constraint` and other `Matter.Composite`.
@ -14,6 +18,8 @@
var World = {};
module.exports = World;
(function() {
/**

View file

@ -6,6 +6,8 @@
var Contact = {};
module.exports = Contact;
(function() {
/**

View file

@ -1,3 +1,7 @@
var SAT = require('./SAT');
var Pair = require('./Pair');
var Bounds = require('../geometry/Bounds');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -8,6 +12,8 @@
var Detector = {};
module.exports = Detector;
(function() {
/**

View file

@ -1,3 +1,7 @@
var Pair = require('./Pair');
var Detector = require('./Detector');
var Common = require('../core/Common');
/**
* See [Demo.js](https://github.com/liabru/matter-js/blob/master/demo/js/Demo.js)
* and [DemoMobile.js](https://github.com/liabru/matter-js/blob/master/demo/js/DemoMobile.js) for usage examples.
@ -7,6 +11,8 @@
var Grid = {};
module.exports = Grid;
(function() {
/**

View file

@ -1,3 +1,5 @@
var Contact = require('./Contact');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -6,6 +8,8 @@
var Pair = {};
module.exports = Pair;
(function() {
/**

View file

@ -1,3 +1,6 @@
var Pair = require('./Pair');
var Common = require('../core/Common');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -6,6 +9,8 @@
var Pairs = {};
module.exports = Pairs;
(function() {
var _pairMaxIdleLife = 1000;

View file

@ -1,3 +1,9 @@
var Vector = require('../geometry/Vector');
var SAT = require('./SAT');
var Bounds = require('../geometry/Bounds');
var Bodies = require('../factory/Bodies');
var Vertices = require('../geometry/Vertices');
/**
* The `Matter.Query` module contains methods for performing collision queries.
*
@ -6,6 +12,8 @@
var Query = {};
module.exports = Query;
(function() {
/**

View file

@ -1,3 +1,8 @@
var Vertices = require('../geometry/Vertices');
var Vector = require('../geometry/Vector');
var Common = require('../core/Common');
var Bounds = require('../geometry/Bounds');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -6,6 +11,8 @@
var Resolver = {};
module.exports = Resolver;
(function() {
Resolver._restingThresh = 4;

View file

@ -1,3 +1,6 @@
var Vertices = require('../geometry/Vertices');
var Vector = require('../geometry/Vector');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -8,6 +11,8 @@
var SAT = {};
module.exports = SAT;
(function() {
/**

View file

@ -1,3 +1,10 @@
var Vertices = require('../geometry/Vertices');
var Vector = require('../geometry/Vector');
var Sleeping = require('../core/Sleeping');
var Bounds = require('../geometry/Bounds');
var Axes = require('../geometry/Axes');
var Common = require('../core/Common');
/**
* The `Matter.Constraint` module contains methods for creating and manipulating constraints.
* Constraints are used for specifying that a fixed distance must be maintained between two bodies (or a body and a fixed world-space position).
@ -19,6 +26,8 @@
var Constraint = {};
module.exports = Constraint;
(function() {
var _minLength = 0.000001,

View file

@ -1,3 +1,13 @@
var Vertices = require('../geometry/Vertices');
var Sleeping = require('../core/Sleeping');
var Mouse = require('../core/Mouse');
var Events = require('../core/Events');
var Detector = require('../collision/Detector');
var Constraint = require('./Constraint');
var Composite = require('../body/Composite');
var Common = require('../core/Common');
var Bounds = require('../geometry/Bounds');
/**
* The `Matter.MouseConstraint` module contains methods for creating mouse constraints.
* Mouse constraints are used for allowing user interaction, providing the ability to move bodies via the mouse or touch.
@ -10,6 +20,8 @@
var MouseConstraint = {};
module.exports = MouseConstraint;
(function() {
/**

View file

@ -6,6 +6,8 @@
var Common = {};
module.exports = Common;
(function() {
Common._nextId = 0;

View file

@ -1,3 +1,16 @@
var World = require('../body/World');
var Sleeping = require('./Sleeping');
var Resolver = require('../collision/Resolver');
var Render = require('../render/Render');
var Pairs = require('../collision/Pairs');
var Metrics = require('./Metrics');
var Grid = require('../collision/Grid');
var Events = require('./Events');
var Composite = require('../body/Composite');
var Constraint = require('../constraint/Constraint');
var Common = require('./Common');
var Body = require('../body/Body');
/**
* The `Matter.Engine` module contains methods for creating and manipulating engines.
* An engine is a controller that manages updating and rendering the simulation of the world.
@ -11,6 +24,8 @@
var Engine = {};
module.exports = Engine;
(function() {
var _fps = 60,

View file

@ -1,3 +1,5 @@
var Common = require('./Common');
/**
* See [Demo.js](https://github.com/liabru/matter-js/blob/master/demo/js/Demo.js)
* and [DemoMobile.js](https://github.com/liabru/matter-js/blob/master/demo/js/DemoMobile.js) for usage examples.
@ -7,6 +9,8 @@
var Events = {};
module.exports = Events;
(function() {
/**

View file

@ -1,4 +1,6 @@
// @if DEBUG
var Composite = require('../body/Composite');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -6,6 +8,8 @@
var Metrics = {};
module.exports = Metrics;
(function() {
/**

View file

@ -1,3 +1,5 @@
var Common = require('../core/Common');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -6,6 +8,8 @@
var Mouse = {};
module.exports = Mouse;
(function() {
/**

View file

@ -1,3 +1,7 @@
var Events = require('./Events');
var Engine = require('./Engine');
var Common = require('./Common');
/**
* The `Matter.Runner` module is an optional utility which provides a game loop,
* that handles updating and rendering a `Matter.Engine` for you within a browser.
@ -11,6 +15,8 @@
var Runner = {};
module.exports = Runner;
(function() {
var _fps = 60,

View file

@ -1,3 +1,5 @@
var Events = require('./Events');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -6,6 +8,8 @@
var Sleeping = {};
module.exports = Sleeping;
(function() {
Sleeping._motionWakeThreshold = 0.18;

View file

@ -1,3 +1,9 @@
var Vertices = require('../geometry/Vertices');
var Common = require('../core/Common');
var Body = require('../body/Body');
var Bounds = require('../geometry/Bounds');
var Vector = require('../geometry/Vector');
/**
* The `Matter.Bodies` module contains factory methods for creating rigid body models
* with commonly used body configurations (such as rectangles, circles and other polygons).
@ -12,6 +18,8 @@
var Bodies = {};
module.exports = Bodies;
(function() {
/**

View file

@ -1,3 +1,9 @@
var Composite = require('../body/Composite');
var Constraint = require('../constraint/Constraint');
var Common = require('../core/Common');
var Body = require('../body/Body');
var Bodies = require('./Bodies');
/**
* See [Demo.js](https://github.com/liabru/matter-js/blob/master/demo/js/Demo.js)
* and [DemoMobile.js](https://github.com/liabru/matter-js/blob/master/demo/js/DemoMobile.js) for usage examples.
@ -7,6 +13,8 @@
var Composites = {};
module.exports = Composites;
(function() {
/**

View file

@ -1,3 +1,6 @@
var Vector = require('../geometry/Vector');
var Common = require('../core/Common');
/**
* _Internal Class_, not generally used outside of the engine's internals.
*
@ -6,6 +9,8 @@
var Axes = {};
module.exports = Axes;
(function() {
/**

View file

@ -6,6 +6,8 @@
var Bounds = {};
module.exports = Bounds;
(function() {
/**

View file

@ -1,3 +1,5 @@
var Bounds = require('../geometry/Bounds');
/**
* The `Matter.Svg` module contains methods for converting SVG images into an array of vector points.
*
@ -9,6 +11,8 @@
var Svg = {};
module.exports = Svg;
(function() {
/**

View file

@ -13,6 +13,8 @@
var Vector = {};
module.exports = Vector;
(function() {
/**

View file

@ -1,3 +1,6 @@
var Vector = require('../geometry/Vector');
var Common = require('../core/Common');
/**
* The `Matter.Vertices` module contains methods for creating and manipulating sets of vertices.
* A set of vertices is an array of `Matter.Vector` with additional indexing properties inserted by `Vertices.create`.
@ -11,6 +14,8 @@
var Vertices = {};
module.exports = Vertices;
(function() {
/**

View file

@ -1,33 +0,0 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2014 Liam Brummitt
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
(function() {
var Matter = {};
// Begin Matter namespace closure
// All Matter modules are included below during build
// Outro.js then closes at the end of the file

View file

@ -1,69 +0,0 @@
// aliases
World.add = Composite.add;
World.remove = Composite.remove;
World.addComposite = Composite.addComposite;
World.addBody = Composite.addBody;
World.addConstraint = Composite.addConstraint;
World.clear = Composite.clear;
Engine.run = Runner.run;
// exports
Matter.Body = Body;
Matter.Composite = Composite;
Matter.World = World;
Matter.Contact = Contact;
Matter.Detector = Detector;
Matter.Grid = Grid;
Matter.Pairs = Pairs;
Matter.Pair = Pair;
Matter.Resolver = Resolver;
Matter.SAT = SAT;
Matter.Constraint = Constraint;
Matter.MouseConstraint = MouseConstraint;
Matter.Common = Common;
Matter.Engine = Engine;
Matter.Mouse = Mouse;
Matter.Sleeping = Sleeping;
Matter.Bodies = Bodies;
Matter.Composites = Composites;
Matter.Axes = Axes;
Matter.Bounds = Bounds;
Matter.Vector = Vector;
Matter.Vertices = Vertices;
Matter.Render = Render;
Matter.RenderPixi = RenderPixi;
Matter.Events = Events;
Matter.Query = Query;
Matter.Runner = Runner;
Matter.Svg = Svg;
// @if DEBUG
Matter.Metrics = Metrics;
// @endif
// CommonJS module
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = Matter;
}
exports.Matter = Matter;
}
// AMD module
if (typeof define === 'function' && define.amd) {
define('Matter', [], function () {
return Matter;
});
}
// browser
if (typeof window === 'object' && typeof window.document === 'object') {
window.Matter = Matter;
}
// End Matter namespace closure
})();

74
src/module/main.js Normal file
View file

@ -0,0 +1,74 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2014 Liam Brummitt
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
Matter = module.exports = {};
Matter.Body = require('../body/Body');
Matter.Composite = require('../body/Composite');
Matter.World = require('../body/World');
Matter.Contact = require('../collision/Contact');
Matter.Detector = require('../collision/Detector');
Matter.Grid = require('../collision/Grid');
Matter.Pairs = require('../collision/Pairs');
Matter.Pair = require('../collision/Pair');
Matter.Query = require('../collision/Query');
Matter.Resolver = require('../collision/Resolver');
Matter.SAT = require('../collision/SAT');
Matter.Constraint = require('../constraint/Constraint');
Matter.MouseConstraint = require('../constraint/MouseConstraint');
Matter.Common = require('../core/Common');
Matter.Engine = require('../core/Engine');
Matter.Events = require('../core/Events');
Matter.Mouse = require('../core/Mouse');
Matter.Runner = require('../core/Runner');
Matter.Sleeping = require('../core/Sleeping');
// @if DEBUG
Matter.Metrics = require('../core/Metrics');
// @endif
Matter.Bodies = require('../factory/Bodies');
Matter.Composites = require('../factory/Composites');
Matter.Axes = require('../geometry/Axes');
Matter.Bounds = require('../geometry/Bounds');
Matter.Svg = require('../geometry/Svg');
Matter.Vector = require('../geometry/Vector');
Matter.Vertices = require('../geometry/Vertices');
Matter.Render = require('../render/Render');
Matter.RenderPixi = require('../render/RenderPixi');
// aliases
Matter.World.add = Matter.Composite.add;
Matter.World.remove = Matter.Composite.remove;
Matter.World.addComposite = Matter.Composite.addComposite;
Matter.World.addBody = Matter.Composite.addBody;
Matter.World.addConstraint = Matter.Composite.addConstraint;
Matter.World.clear = Matter.Composite.clear;
Matter.Engine.run = Matter.Runner.run;

View file

@ -1,3 +1,8 @@
var Common = require('../core/Common');
var Composite = require('../body/Composite');
var Bounds = require('../geometry/Bounds');
var Grid = require('../collision/Grid');
/**
* The `Matter.Render` module is the default `render.controller` used by a `Matter.Engine`.
* This renderer is HTML5 canvas based and supports a number of drawing options including sprites and viewports.
@ -12,6 +17,8 @@
var Render = {};
module.exports = Render;
(function() {
/**

View file

@ -7,6 +7,8 @@
var RenderPixi = {};
module.exports = RenderPixi;
(function() {
/**