Stubbed Net and Debug so they can be properly excluded during a custom build.

This commit is contained in:
Steven Rogers 2015-04-29 09:07:06 -04:00
parent 8290e8c371
commit 258b549a0d
8 changed files with 156 additions and 22 deletions

View file

@ -48,13 +48,13 @@ module.exports = function (grunt) {
'retrofont': { 'description': 'Retro Fonts Game Object', 'optional': true, 'stub': false },
'system': { 'description': 'System Classes', 'optional': false, 'stub': false },
'math': { 'description': 'Math, QuadTree and RND', 'optional': false, 'stub': false },
'net': { 'description': 'Network Class', 'optional': true, 'stub': false },
'net': { 'description': 'Network Class', 'optional': true, 'stub': true },
'tweens': { 'description': 'Tween Manager', 'optional': true, 'stub': true },
'time': { 'description': 'Time and Clock Manager', 'optional': false, 'stub': false },
'animation': { 'description': 'Animation and Frame Manager', 'optional': false, 'stub': false },
'loader': { 'description': 'Loader and Cache', 'optional': false, 'stub': false },
'sound': { 'description': 'Sound Support (Web Audio and HTML Audio)', 'optional': true, 'stub': true },
'debug': { 'description': 'Debug Class', 'optional': true, 'stub': false },
'debug': { 'description': 'Debug Class', 'optional': true, 'stub': true },
'utils': { 'description': 'Core Utilities', 'optional': false, 'stub': false },
'physics': { 'description': 'Physics Manager', 'optional': false, 'stub': false },
'arcade': { 'description': 'Arcade Physics', 'optional': true, 'stub': false },

View file

@ -7,7 +7,7 @@
/**
* This is where the magic happens. The Game object is the heart of your game,
* providing quick access to common functions and handling the boot process.
*
*
* "Hell, there are no rules here - we're trying to accomplish something."
* Thomas A. Edison
*
@ -211,7 +211,7 @@ Phaser.Game = function (width, height, renderer, parent, state, transparent, ant
* @property {Phaser.Physics} physics - Reference to the physics manager.
*/
this.physics = null;
/**
* @property {Phaser.PluginManager} plugins - Reference to the plugin manager.
*/
@ -544,6 +544,7 @@ Phaser.Game.prototype = {
this.particles = new Phaser.Particles(this);
this.plugins = new Phaser.PluginManager(this);
this.net = new Phaser.Net(this);
this.debug = new Phaser.Utils.Debug(this, this.config['enableDebug']);
this.time.boot();
this.stage.boot();
@ -552,16 +553,7 @@ Phaser.Game.prototype = {
this.input.boot();
this.sound.boot();
this.state.boot();
if (this.config['enableDebug'])
{
this.debug = new Phaser.Utils.Debug(this);
this.debug.boot();
}
else
{
this.debug = { preUpdate: function () {}, update: function () {}, reset: function () {} };
}
this.debug.boot();
this.showDebugHeader();
@ -732,7 +724,7 @@ Phaser.Game.prototype = {
if (this.renderType !== Phaser.HEADLESS)
{
this.stage.smoothed = this.antialias;
Phaser.Canvas.addToDOM(this.canvas, this.parent, false);
Phaser.Canvas.setTouchAction(this.canvas);
}
@ -754,7 +746,7 @@ Phaser.Game.prototype = {
{
this.updateLogic(1.0 / this.time.desiredFps);
// Sync the scene graph after _every_ logic update to account for moved game objects
// Sync the scene graph after _every_ logic update to account for moved game objects
this.stage.updateTransform();
// call the game render update exactly once every frame

48
src/stubs/Debug.js Normal file
View file

@ -0,0 +1,48 @@
/**
* @author Steven Rogers <soldoutactivist@gmail.com>
* @copyright 2015 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* This is a stub for the Phaser Debug Class.
* It allows you to exclude the default Debug from your build, without making Game crash.
*/
var debugNoop = function () {};
Phaser.Utils.Debug = debugNoop;
Phaser.Utils.Debug.prototype = {
isDisabled: true,
boot: debugNoop,
preUpdate: debugNoop,
reset: debugNoop,
start: debugNoop,
stop: debugNoop,
line: debugNoop,
soundInfo: debugNoop,
cameraInfo: debugNoop,
timer: debugNoop,
pointer: debugNoop,
spriteInputInfo: debugNoop,
key: debugNoop,
inputInfo: debugNoop,
spriteBounds: debugNoop,
ropeSegments: debugNoop,
spriteInfo: debugNoop,
spriteCoords: debugNoop,
lineInfo: debugNoop,
pixel: debugNoop,
geom: debugNoop,
rectangle: debugNoop,
text: debugNoop,
quadTree: debugNoop,
body: debugNoop,
bodyInfo: debugNoop,
box2dWorld: debugNoop,
box2dBody: debugNoop
};
Phaser.Utils.Debug.prototype.constructor = Phaser.Utils.Debug;

26
src/stubs/Net.js Normal file
View file

@ -0,0 +1,26 @@
/**
* @author Steven Rogers <soldoutactivist@gmail.com>
* @copyright 2015 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* This is a stub for the Phaser Net Class.
* It allows you to exclude the default Net from your build, without making Game crash.
*/
var netNoop = function () {};
Phaser.Net = netNoop;
Phaser.Net.prototype = {
isDisabled: true,
getHostName: netNoop,
checkDomainName: netNoop,
updateQueryString: netNoop,
getQueryString: netNoop,
decodeURI: netNoop
};
Phaser.Net.prototype.constructor = Phaser.Net;

View file

@ -15,7 +15,11 @@
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
*/
Phaser.Utils.Debug = function (game) {
Phaser.Utils.Debug = function (game, enabled) {
/**
* @property {boolean} enabled - Is debugging enabled?
*/
this.enabled = enabled || true;
/**
* @property {Phaser.Game} game - A reference to the currently running Game.
@ -111,7 +115,6 @@ Phaser.Utils.Debug.prototype = {
this.canvas = Phaser.Canvas.create(this.game.width, this.game.height, '', true);
this.context = this.canvas.getContext('2d');
}
},
/**
@ -121,6 +124,8 @@ Phaser.Utils.Debug.prototype = {
*/
preUpdate: function () {
if (!this.enabled) { return; }
if (this.dirty && this.sprite)
{
this.bmd.clear();
@ -163,6 +168,8 @@ Phaser.Utils.Debug.prototype = {
*/
start: function (x, y, color, columnWidth) {
if (!this.enabled) { return; }
if (typeof x !== 'number') { x = 0; }
if (typeof y !== 'number') { y = 0; }
color = color || 'rgb(255,255,255)';
@ -206,6 +213,8 @@ Phaser.Utils.Debug.prototype = {
*/
line: function () {
if (!this.enabled) { return; }
var x = this.currentX;
for (var i = 0; i < arguments.length; i++)
@ -237,6 +246,8 @@ Phaser.Utils.Debug.prototype = {
*/
soundInfo: function (sound, x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color);
this.line('Sound: ' + sound.key + ' Locked: ' + sound.game.sound.touchLocked);
this.line('Is Ready?: ' + this.game.cache.isSoundReady(sound.key) + ' Pending Playback: ' + sound.pendingPlayback);
@ -268,6 +279,8 @@ Phaser.Utils.Debug.prototype = {
*/
cameraInfo: function (camera, x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color);
this.line('Camera (' + camera.width + ' x ' + camera.height + ')');
this.line('X: ' + camera.x + ' Y: ' + camera.y);
@ -295,6 +308,8 @@ Phaser.Utils.Debug.prototype = {
*/
timer: function (timer, x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color);
this.line('Timer (running: ' + timer.running + ' expired: ' + timer.expired + ')');
this.line('Next Tick: ' + timer.next + ' Duration: ' + timer.duration);
@ -315,6 +330,8 @@ Phaser.Utils.Debug.prototype = {
*/
pointer: function (pointer, hideIfUp, downColor, upColor, color) {
if (!this.enabled) { return; }
if (pointer == null)
{
return;
@ -374,6 +391,8 @@ Phaser.Utils.Debug.prototype = {
*/
spriteInputInfo: function (sprite, x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color);
this.line('Sprite Input: (' + sprite.width + ' x ' + sprite.height + ')');
this.line('x: ' + sprite.input.pointerX().toFixed(1) + ' y: ' + sprite.input.pointerY().toFixed(1));
@ -395,6 +414,8 @@ Phaser.Utils.Debug.prototype = {
*/
key: function (key, x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color, 150);
this.line('Key:', key.keyCode, 'isDown:', key.isDown);
@ -415,6 +436,8 @@ Phaser.Utils.Debug.prototype = {
*/
inputInfo: function (x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color);
this.line('Input');
this.line('X: ' + this.game.input.x + ' Y: ' + this.game.input.y);
@ -435,6 +458,8 @@ Phaser.Utils.Debug.prototype = {
*/
spriteBounds: function (sprite, color, filled) {
if (!this.enabled) { return; }
var bounds = sprite.getBounds();
bounds.x += this.game.camera.x;
@ -452,6 +477,9 @@ Phaser.Utils.Debug.prototype = {
* @param {boolean} [filled=true] - Render the rectangle as a fillRect (default, true) or a strokeRect (false)
*/
ropeSegments: function(rope, color, filled) {
if (!this.enabled) { return; }
var segments = rope.segments;
segments.forEach(function(segment) {
this.rectangle(segment, color, filled);
@ -470,6 +498,8 @@ Phaser.Utils.Debug.prototype = {
*/
spriteInfo: function (sprite, x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color);
this.line('Sprite: ' + ' (' + sprite.width + ' x ' + sprite.height + ') anchor: ' + sprite.anchor.x + ' x ' + sprite.anchor.y);
@ -493,6 +523,8 @@ Phaser.Utils.Debug.prototype = {
*/
spriteCoords: function (sprite, x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color, 100);
if (sprite.name)
@ -519,6 +551,8 @@ Phaser.Utils.Debug.prototype = {
*/
lineInfo: function (line, x, y, color) {
if (!this.enabled) { return; }
this.start(x, y, color, 80);
this.line('start.x:', line.start.x.toFixed(2), 'start.y:', line.start.y.toFixed(2));
this.line('end.x:', line.end.x.toFixed(2), 'end.y:', line.end.y.toFixed(2));
@ -538,6 +572,8 @@ Phaser.Utils.Debug.prototype = {
*/
pixel: function (x, y, color, size) {
if (!this.enabled) { return; }
size = size || 2;
this.start();
@ -558,6 +594,8 @@ Phaser.Utils.Debug.prototype = {
*/
geom: function (object, color, filled, forceType) {
if (!this.enabled) { return; }
if (typeof filled === 'undefined') { filled = true; }
if (typeof forceType === 'undefined') { forceType = 0; }
@ -622,6 +660,8 @@ Phaser.Utils.Debug.prototype = {
*/
rectangle: function (object, color, filled) {
if (!this.enabled) { return; }
if (typeof filled === 'undefined') { filled = true; }
color = color || 'rgba(0, 255, 0, 0.4)';
@ -655,6 +695,8 @@ Phaser.Utils.Debug.prototype = {
*/
text: function (text, x, y, color, font) {
if (!this.enabled) { return; }
color = color || 'rgb(255,255,255)';
font = font || '16px Courier';
@ -683,6 +725,8 @@ Phaser.Utils.Debug.prototype = {
*/
quadTree: function (quadtree, color) {
if (!this.enabled) { return; }
color = color || 'rgba(255,0,0,0.3)';
this.start();
@ -726,6 +770,8 @@ Phaser.Utils.Debug.prototype = {
*/
body: function (sprite, color, filled) {
if (!this.enabled) { return; }
if (sprite.body)
{
this.start();
@ -759,6 +805,8 @@ Phaser.Utils.Debug.prototype = {
*/
bodyInfo: function (sprite, x, y, color) {
if (!this.enabled) { return; }
if (sprite.body)
{
this.start(x, y, color, 210);
@ -785,12 +833,14 @@ Phaser.Utils.Debug.prototype = {
* @method Phaser.Utils.Debug#box2dWorld
*/
box2dWorld: function () {
if (!this.enabled) { return; }
this.start();
this.context.translate(-this.game.camera.view.x, -this.game.camera.view.y, 0);
this.game.physics.box2d.renderDebugDraw(this.context);
this.stop();
},
@ -804,7 +854,9 @@ Phaser.Utils.Debug.prototype = {
* @param {string} [color='rgb(0,255,0)'] - color of the debug info to be rendered. (format is css color string).
*/
box2dBody: function (body, color) {
if (!this.enabled) { return; }
this.start();
Phaser.Physics.Box2D.renderBody(this.context, body, color);
this.stop();

View file

@ -0,0 +1,3 @@
[
"src/stubs/Debug.js"
]

View file

@ -0,0 +1,3 @@
[
"src/stubs/Net.js"
]

View file

@ -95,6 +95,11 @@ module.exports = {
dest: '<%= modules_dir %>/net.js'
},
netStub: {
src: require('../manifests/net.stub'),
dest: '<%= modules_dir %>/net.js'
},
tweens: {
src: require('../manifests/tweens'),
dest: '<%= modules_dir %>/tweens.js'
@ -135,6 +140,11 @@ module.exports = {
dest: '<%= modules_dir %>/debug.js'
},
debugStub: {
src: require('../manifests/debug.stub'),
dest: '<%= modules_dir %>/debug.js'
},
utils: {
src: require('../manifests/utils'),
dest: '<%= modules_dir %>/utils.js'