Skip to content

Commit c4183d2

Browse files
committed
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, phaserjs#531)
1 parent 051526b commit c4183d2

6 files changed

Lines changed: 37 additions & 9 deletions

File tree

Gruntfile.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = function (grunt) {
55
grunt.loadNpmTasks('grunt-contrib-connect');
66
grunt.loadNpmTasks('grunt-contrib-copy');
77
grunt.loadNpmTasks('grunt-contrib-uglify');
8+
grunt.loadNpmTasks('grunt-text-replace');
89
grunt.loadTasks('./tasks');
910

1011
grunt.initConfig({
@@ -197,25 +198,48 @@ module.exports = function (grunt) {
197198
],
198199

199200
p2: [
200-
'src/physics/p2/p2.js'
201+
'src/physics/p2/p2.js',
201202
'src/physics/p2/World.js',
202203
'src/physics/p2/PointProxy.js',
203204
'src/physics/p2/InversePointProxy.js',
204205
'src/physics/p2/Body.js',
205206
'src/physics/p2/Spring.js',
206207
'src/physics/p2/Material.js',
207208
'src/physics/p2/ContactMaterial.js',
208-
'src/physics/p2/CollisionGroup.js',
209+
'src/physics/p2/CollisionGroup.js'
209210
],
210211

211212
ninja: [
212213
'src/physics/ninja/World.js',
213214
'src/physics/ninja/Body.js',
214215
'src/physics/ninja/AABB.js',
215216
'src/physics/ninja/Tile.js',
216-
'src/physics/ninja/Circle.js',
217+
'src/physics/ninja/Circle.js'
217218
],
218219

220+
// If we've updated pixi or p2 then their UMD wrappers will be wrong, this will fix it:
221+
replace: {
222+
223+
pixi: {
224+
src: ['src/pixi/Outro.js'],
225+
dest: 'src/pixi/Outro.js',
226+
replacements: [{
227+
from: "define(PIXI);",
228+
to: "define('PIXI', (function() { return root.PIXI = PIXI; })() );"
229+
}]
230+
},
231+
232+
p2: {
233+
src: ['src/physics/p2/p2.js'],
234+
dest: 'src/physics/p2/p2.js',
235+
replacements: [{
236+
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){',
237+
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){'
238+
}]
239+
}
240+
241+
},
242+
219243
clean: ['<%= compile_dir %>'],
220244

221245
concat: {
@@ -316,7 +340,7 @@ module.exports = function (grunt) {
316340
{ src: ['dist/phaser-no-libs.js'], dest: 'build/custom/phaser-no-libs.js' },
317341
{ src: ['dist/phaser-no-libs.min.js'], dest: 'build/custom/phaser-no-libs.min.js' },
318342
{ src: ['dist/pixi.js'], dest: 'build/custom/pixi.js' },
319-
{ src: ['dist/pixi.min.js'], dest: 'build/custom/pixi.min.js' }
343+
{ src: ['dist/pixi.min.js'], dest: 'build/custom/pixi.min.js' },
320344
{ src: ['dist/ninja.js'], dest: 'build/custom/ninja.js' },
321345
{ src: ['dist/ninja.min.js'], dest: 'build/custom/ninja.min.js' }
322346
]

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Bug Fixes:
223223
* Circle.circumferencePoint using the asDegrees parameter would apply degToRad instead of radToDeg (thanks Ziriax, fixes #509)
224224
* InputHandler.enableSnap now correctly assigns the snap offset parameters (fixes #515)
225225
* Objects that are 'fixedToCamera' are now still correctly placed even if the camera is scaled (#512)
226+
* 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)
226227

227228

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

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

244-
Run `grunt` in the phaser folder for a list of command-line options.
245+
Run `grunt` to perform a default build to the `dist` folder and update the examples.
246+
247+
If you replace Pixi or p2 then run `grunt replace` to patch their UMD strings so they work properly with Phaser and requireJS.
245248

246249

247250
Koding

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"grunt-contrib-copy": "~0.5.0",
3333
"grunt-contrib-clean": "~0.5.0",
3434
"grunt-contrib-uglify": "~0.3.3",
35-
"lodash": "~2.2.1"
35+
"lodash": "~2.2.1",
36+
"grunt-text-replace": "~0.3.11"
3637
}
3738
}

src/Outro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
}
1111
exports.Phaser = Phaser;
1212
} else if (typeof define !== 'undefined' && define.amd) {
13-
define(Phaser);
13+
define('phaser', Phaser);
1414
} else {
1515
root.Phaser = Phaser;
1616
}

src/physics/p2/p2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2222
* THE SOFTWARE.
2323
*/
24-
!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){
24+
!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){
2525
/* Copyright (c) 2012, Brandon Jones, Colin MacKenzie IV. All rights reserved.
2626
2727
Redistribution and use in source and binary forms, with or without modification,

src/pixi/Outro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}
99
exports.PIXI = PIXI;
1010
} else if (typeof define !== 'undefined' && define.amd) {
11-
define(PIXI);
11+
define('PIXI', (function() { return root.PIXI = PIXI; })() );
1212
} else {
1313
root.PIXI = PIXI;
1414
}

0 commit comments

Comments
 (0)