Skip to content

Commit

Permalink
Changed the define function calls to use named modules, allows pixi, …
Browse files Browse the repository at this point in the history
…phaser and p2 to reside in 1 file and still be located by requirejs (thanks brejep, phaserjs#531)
  • Loading branch information
photonstorm committed Mar 10, 2014
1 parent 051526b commit c4183d2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
32 changes: 28 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-text-replace');
grunt.loadTasks('./tasks');

grunt.initConfig({
Expand Down Expand Up @@ -197,25 +198,48 @@ module.exports = function (grunt) {
],

p2: [
'src/physics/p2/p2.js'
'src/physics/p2/p2.js',
'src/physics/p2/World.js',
'src/physics/p2/PointProxy.js',
'src/physics/p2/InversePointProxy.js',
'src/physics/p2/Body.js',
'src/physics/p2/Spring.js',
'src/physics/p2/Material.js',
'src/physics/p2/ContactMaterial.js',
'src/physics/p2/CollisionGroup.js',
'src/physics/p2/CollisionGroup.js'
],

ninja: [
'src/physics/ninja/World.js',
'src/physics/ninja/Body.js',
'src/physics/ninja/AABB.js',
'src/physics/ninja/Tile.js',
'src/physics/ninja/Circle.js',
'src/physics/ninja/Circle.js'
],

// If we've updated pixi or p2 then their UMD wrappers will be wrong, this will fix it:
replace: {

pixi: {
src: ['src/pixi/Outro.js'],
dest: 'src/pixi/Outro.js',
replacements: [{
from: "define(PIXI);",
to: "define('PIXI', (function() { return root.PIXI = PIXI; })() );"
}]
},

p2: {
src: ['src/physics/p2/p2.js'],
dest: 'src/physics/p2/p2.js',
replacements: [{
from: '!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.p2=e():"undefined"!=typeof global?self.p2=e():"undefined"!=typeof self&&(self.p2=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module \'"+o+"\'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){',
to: '!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(\'p2\', (function() { return this.p2 = e(); })()):"undefined"!=typeof window?window.p2=e():"undefined"!=typeof global?self.p2=e():"undefined"!=typeof self&&(self.p2=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module \'"+o+"\'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){'
}]
}

},

clean: ['<%= compile_dir %>'],

concat: {
Expand Down Expand Up @@ -316,7 +340,7 @@ module.exports = function (grunt) {
{ src: ['dist/phaser-no-libs.js'], dest: 'build/custom/phaser-no-libs.js' },
{ src: ['dist/phaser-no-libs.min.js'], dest: 'build/custom/phaser-no-libs.min.js' },
{ src: ['dist/pixi.js'], dest: 'build/custom/pixi.js' },
{ src: ['dist/pixi.min.js'], dest: 'build/custom/pixi.min.js' }
{ src: ['dist/pixi.min.js'], dest: 'build/custom/pixi.min.js' },
{ src: ['dist/ninja.js'], dest: 'build/custom/ninja.js' },
{ src: ['dist/ninja.min.js'], dest: 'build/custom/ninja.min.js' }
]
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Bug Fixes:
* Circle.circumferencePoint using the asDegrees parameter would apply degToRad instead of radToDeg (thanks Ziriax, fixes #509)
* InputHandler.enableSnap now correctly assigns the snap offset parameters (fixes #515)
* Objects that are 'fixedToCamera' are now still correctly placed even if the camera is scaled (#512)
* Changed the define function calls to use named modules, allows pixi, phaser and p2 to reside in 1 file and still be located by requirejs (thanks brejep, #531)


TO DO:
Expand All @@ -241,7 +242,9 @@ We provide a fully compiled version of Phaser in the `build` directory, in both

We also provide a Grunt script that will build Phaser from source along with all the examples.

Run `grunt` in the phaser folder for a list of command-line options.
Run `grunt` to perform a default build to the `dist` folder and update the examples.

If you replace Pixi or p2 then run `grunt replace` to patch their UMD strings so they work properly with Phaser and requireJS.


Koding
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-uglify": "~0.3.3",
"lodash": "~2.2.1"
"lodash": "~2.2.1",
"grunt-text-replace": "~0.3.11"
}
}
2 changes: 1 addition & 1 deletion src/Outro.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
exports.Phaser = Phaser;
} else if (typeof define !== 'undefined' && define.amd) {
define(Phaser);
define('phaser', Phaser);
} else {
root.Phaser = Phaser;
}
Expand Down
2 changes: 1 addition & 1 deletion src/physics/p2/p2.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.p2=e():"undefined"!=typeof global?self.p2=e():"undefined"!=typeof self&&(self.p2=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define('p2', (function() { return this.p2 = e(); })()):"undefined"!=typeof window?window.p2=e():"undefined"!=typeof global?self.p2=e():"undefined"!=typeof self&&(self.p2=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
Expand Down
2 changes: 1 addition & 1 deletion src/pixi/Outro.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
exports.PIXI = PIXI;
} else if (typeof define !== 'undefined' && define.amd) {
define(PIXI);
define('PIXI', (function() { return root.PIXI = PIXI; })() );
} else {
root.PIXI = PIXI;
}
Expand Down

0 comments on commit c4183d2

Please sign in to comment.