From 9804d1a72299e0af578ad7fd7174b393764cd3f4 Mon Sep 17 00:00:00 2001
From: Jare Guo
Date: Thu, 14 Jan 2016 00:05:51 +0800
Subject: [PATCH 1/8] fix uglify pipeline
---
gulp/tasks/build.js | 46 +++++++++++++++++++++------------------------
1 file changed, 21 insertions(+), 25 deletions(-)
diff --git a/gulp/tasks/build.js b/gulp/tasks/build.js
index 62a89dfbae..c54b438ac8 100644
--- a/gulp/tasks/build.js
+++ b/gulp/tasks/build.js
@@ -17,18 +17,18 @@ var handleErrors = require('../util/handleErrors');
require('./build-cocos2d');
-function getUglifyOptions (minify, global_defs, preserveComments) {
- preserveComments = preserveComments || false;
+function getUglifyOptions (minify, global_defs) {
if (minify) {
return {
compress: {
- global_defs: global_defs
+ global_defs: global_defs,
+ conditionals: false, // 如果为 true, 会把 if 压缩成 bool 表达式, 但 sourcemap 的行号就会乱掉
}
};
}
else {
- // http://lisperator.net/uglifyjs/compress
var compress = {
+ // http://lisperator.net/uglifyjs/compress
global_defs: global_defs,
sequences: false, // join consecutive statements with the “comma operator”
properties: false, // optimize property access: a["foo"] → a.foo
@@ -49,11 +49,11 @@ function getUglifyOptions (minify, global_defs, preserveComments) {
side_effects: false // drop side-effect-free statements
//warnings: true // warn about potentially dangerous optimizations/code
};
- // http://lisperator.net/uglifyjs/codegen
return {
mangle: false,
- preserveComments: preserveComments,
+ //preserveComments: 'all',
output: {
+ // http://lisperator.net/uglifyjs/codegen
beautify: true,
bracketize: true
},
@@ -63,32 +63,28 @@ function getUglifyOptions (minify, global_defs, preserveComments) {
}
function rebundle(bundler) {
- var bundle = bundler.bundle()
- .on('error', handleErrors.handler)
- .pipe(handleErrors())
- .pipe(source(paths.outFile))
- .pipe(buffer());
-
- var dev = sourcemaps.init({loadMaps: true})
- .pipe(uglify(getUglifyOptions(false, {
- CC_EDITOR: false,
- CC_DEV: true,
- CC_TEST: false
- })))
- .pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true}))
- .pipe(gulp.dest(paths.outDir));
+ var dev = uglify(getUglifyOptions(false, {
+ CC_EDITOR: false,
+ CC_DEV: false,
+ CC_TEST: false
+ }));
var min = rename({ suffix: '-min' });
- min.pipe(sourcemaps.init({loadMaps: true}))
- .pipe(uglify(getUglifyOptions(true, {
+ min.pipe(uglify(getUglifyOptions(true, {
CC_EDITOR: false,
CC_DEV: false,
CC_TEST: false
- })))
+ })));
+
+ return bundler.bundle()
+ .on('error', handleErrors.handler)
+ .pipe(handleErrors())
+ .pipe(source(paths.outFile))
+ .pipe(buffer())
+ .pipe(sourcemaps.init({loadMaps: true}))
+ .pipe(mirror(dev, min))
.pipe(sourcemaps.write('./', {sourceRoot: './', addComment: true}))
.pipe(gulp.dest(paths.outDir));
-
- return bundle.pipe(mirror(dev, min));
}
function rebundle_test(bundler, suffix) {
From 9b12b53ee7a4c2c0fb0a476f74aa9f741a390e5e Mon Sep 17 00:00:00 2001
From: pandamicro
Date: Thu, 14 Jan 2016 19:01:19 +0800
Subject: [PATCH 2/8] Fixed indexOf issue on Baidu browser, damn you baidu
browser guys !
---
cocos2d/core/platform/callbacks-invoker.js | 4 ++--
cocos2d/core/platform/js.js | 4 +++-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/cocos2d/core/platform/callbacks-invoker.js b/cocos2d/core/platform/callbacks-invoker.js
index 17e62e82ee..ae304688cc 100644
--- a/cocos2d/core/platform/callbacks-invoker.js
+++ b/cocos2d/core/platform/callbacks-invoker.js
@@ -76,7 +76,7 @@ CallbacksHandler.prototype.has = function (key, callback, target) {
if (callbackTarget === target) {
return true;
}
- index = list.indexOf(callback, index + 1);
+ index = cc.js.array.indexOf.call(list, callback, index + 1);
}
// callback given but not found
return false;
@@ -131,7 +131,7 @@ CallbacksHandler.prototype.remove = function (key, callback, target) {
break;
}
- index = list.indexOf(callback, index + 1);
+ index = cc.js.array.indexOf.call(list, callback, index + 1);
}
return true;
}
diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js
index 1bb5289d85..25e6a43fd0 100644
--- a/cocos2d/core/platform/js.js
+++ b/cocos2d/core/platform/js.js
@@ -628,7 +628,9 @@ js.array = {
for (i = 0; i < len; i += 1)
arr_clone[i] = array[i];
return arr_clone;
- }
+ },
+
+ indexOf: Array.prototype.indexOf,
};
cc.js = js;
From 7932d986e8a8c6154a636b4fea588bdbf93a9077 Mon Sep 17 00:00:00 2001
From: pandamicro
Date: Thu, 14 Jan 2016 21:49:07 +0800
Subject: [PATCH 3/8] Add documentation to accuse Baidu developer
---
cocos2d/core/platform/js.js | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js
index 25e6a43fd0..b91df6bbfb 100644
--- a/cocos2d/core/platform/js.js
+++ b/cocos2d/core/platform/js.js
@@ -630,6 +630,22 @@ js.array = {
return arr_clone;
},
+ /**
+ * Exact same function as Array.prototype.indexOf.
+ * HACK: ugliy hack for Baidu mobile browser compatibility,
+ * stupid Baidu guys modify Array.prototype.indexOf for all pages loaded,
+ * their version changes strict comparison to non-strict comparison,
+ * it also ignores the second parameter of the original API,
+ * and this will cause event handler enter infinite loop.
+ * Baidu developers, if you ever see this documentation,
+ * here is the standard: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
+ * Seriously !
+ *
+ * @method indexOf
+ * @param {any} searchElement Element to locate in the array.
+ * @param {Number} [fromIndex=0] The index to start the search at
+ * @return {Number} returns the first index at which a given element can be found in the array, or -1 if it is not present.
+ */
indexOf: Array.prototype.indexOf,
};
From 5e5459af3bb4afccb1071f0b4b20728f0f449306 Mon Sep 17 00:00:00 2001
From: "Huabing.Xu"
Date: Fri, 15 Jan 2016 11:10:00 +0800
Subject: [PATCH 4/8] fix label does not work on sougou browser
---
.../core/label/CCSGLabelCanvasRenderCmd.js | 95 +++++++++----------
1 file changed, 45 insertions(+), 50 deletions(-)
diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
index 346bb295fc..bd0503e323 100644
--- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
+++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
@@ -29,12 +29,12 @@
http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
http://www.angelcode.com/products/bmfont/ (Free, Windows only)
****************************************************************************/
-(function() {
- _ccsg.Label.TTFLabelBaker = function() {
+(function () {
+ _ccsg.Label.TTFLabelBaker = function () {
};
var proto = _ccsg.Label.TTFLabelBaker.prototype = Object.create(Object.prototype);
- proto._getLineHeight = function() {
+ proto._getLineHeight = function () {
//todo refine it
var nodeSpacingY = this._node.getLineHeight();
if (nodeSpacingY === 0) {
@@ -45,7 +45,7 @@
return nodeSpacingY | 0;
};
- proto._prepareQuad = function() {
+ proto._prepareQuad = function () {
var quad = this._quad;
var white = cc.color(255, 255, 255, this._displayedOpacity);
var width = this._node._contentSize.width;
@@ -84,7 +84,7 @@
var wrappedWords = [];
var text = strArr;
var allWidth = ctx.measureText(text).width;
- while(allWidth > maxWidth && text.length > 1){
+ while (allWidth > maxWidth && text.length > 1) {
var fuzzyLen = text.length * ( maxWidth / allWidth ) | 0;
var tmpText = text.substr(fuzzyLen);
@@ -151,14 +151,14 @@
text = sLine || tmpText;
allWidth = ctx.measureText(text).width;
}
- if(text.length > 0) {
+ if (text.length > 0) {
wrappedWords.push(text);
}
-
+
return wrappedWords;
};
-
- proto._updateDisplayOpacity = function(parentOpacity) {
+
+ proto._updateDisplayOpacity = function (parentOpacity) {
_ccsg.Node.RenderCmd.prototype._updateDisplayOpacity.call(this, parentOpacity);
//specify opacity to quad
var color = cc.color(255, 255, 255, this._displayedOpacity);
@@ -169,14 +169,14 @@
quad._tr.colors = color;
this._quadDirty = true;
};
-
+
proto._updateDisplayColor = function (parentColor) {
_ccsg.Node.RenderCmd.prototype._updateDisplayColor.call(this, parentColor);
var node = this._node;
node._labelSkinDirty = true;
};
-
- proto._bakeLabel = function() {
+
+ proto._bakeLabel = function () {
var node = this._node;
this._drawFontsize = node._fontSize;
var ctx = this._labelContext;
@@ -220,7 +220,7 @@
canvasSizeY = this._splitedStrings.length * this._getLineHeight();
node.setContentSize(cc.size(canvasSizeX, canvasSizeY));
}
- } else if(_ccsg.Label.Overflow.SHRINK === node._overFlow) {
+ } else if (_ccsg.Label.Overflow.SHRINK === node._overFlow) {
this._splitedStrings = paragraphedStrings;
//shrink
if (node._isWrapText) {
@@ -315,14 +315,14 @@
this._labelTexture.handleLoadedTexture();
};
- proto._rebuildLabelSkin = function() {
+ proto._rebuildLabelSkin = function () {
var node = this._node;
if (node._labelSkinDirty) {
- if(node._labelType === _ccsg.Label.Type.TTF ||
- node._labelType === _ccsg.Label.Type.SystemFont){
+ if (node._labelType === _ccsg.Label.Type.TTF ||
+ node._labelType === _ccsg.Label.Type.SystemFont) {
this._bakeLabel();
this._prepareQuad();
- }else {
+ } else {
node._updateContent();
}
this._node._labelSkinDirty = false;
@@ -330,8 +330,8 @@
};
})();
-(function() {
- _ccsg.Label.CanvasRenderCmd = function(renderableObject) {
+(function () {
+ _ccsg.Label.CanvasRenderCmd = function (renderableObject) {
_ccsg.Node.CanvasRenderCmd.call(this, renderableObject);
this._needDraw = true;
this._labelTexture = new cc.Texture2D();
@@ -351,13 +351,13 @@
proto.constructor = _ccsg.Label.CanvasRenderCmd;
- proto.rendering = function(ctx, scaleX, scaleY) {
+ proto.rendering = function (ctx, scaleX, scaleY) {
this._rebuildLabelSkin();
var node = this._node;
if (node._labelType === _ccsg.Label.Type.TTF ||
- node._labelType === _ccsg.Label.Type.SystemFont) {
+ node._labelType === _ccsg.Label.Type.SystemFont) {
var locDisplayOpacity = this._displayedOpacity;
var alpha = locDisplayOpacity / 255;
//var locTexture = this._labelTexture;
@@ -371,41 +371,36 @@
wrapper.setGlobalAlpha(alpha);
if (this._labelTexture) {
+ var sx, sy, sw, sh;
+ var x, y, w, h;
- var quad = this._quad; {
- var sx, sy, sw, sh;
- var x, y, w, h;
+ x = 0;
+ y = 0;
+ w = this._node._contentSize.width;
+ h = this._node._contentSize.height;
- x = quad._bl.vertices.x;
- y = quad._bl.vertices.y;
- w = quad._tr.vertices.x - quad._bl.vertices.x;
- h = quad._tr.vertices.y - quad._bl.vertices.y;
- y = -y - h;
+ var textureWidth = this._labelTexture.getPixelWidth();
+ var textureHeight = this._labelTexture.getPixelHeight();
- var textureWidth = this._labelTexture.getPixelWidth();
- var textureHeight = this._labelTexture.getPixelHeight();
+ sx = 0;
+ sy = 0;
+ sw = textureWidth;
+ sh = textureHeight;
- sx = quad._bl.texCoords.u * textureWidth;
- sy = quad._bl.texCoords.v * textureHeight;
- sw = (quad._tr.texCoords.u - quad._bl.texCoords.u) * textureWidth;
- sh = (quad._tr.texCoords.v - quad._bl.texCoords.v) * textureHeight;
+ x = x * scaleX;
+ y = y * scaleY;
+ w = w * scaleX;
+ h = h * scaleY;
- x = x * scaleX;
- y = y * scaleY;
- w = w * scaleX;
- h = h * scaleY;
-
- var image = this._labelTexture._htmlElementObj;
- if (this._labelTexture._pattern !== "") {
- wrapper.setFillStyle(context.createPattern(image, this._labelTexture._pattern));
- context.fillRect(x, y, w, h);
- } else {
- context.drawImage(image,
- sx, sy, sw, sh,
- x, y, w, h);
- }
+ var image = this._labelTexture._htmlElementObj;
+ if (this._labelTexture._pattern !== "") {
+ wrapper.setFillStyle(context.createPattern(image, this._labelTexture._pattern));
+ context.fillRect(x, y, w, h);
+ } else {
+ context.drawImage(image,
+ sx, sy, sw, sh,
+ x, y, w, h);
}
-
}
cc.g_NumberOfDraws = cc.g_NumberOfDraws + 1;
}
From 0e389f2b5523bd0ef529b92cde3934b93412f146 Mon Sep 17 00:00:00 2001
From: "Huabing.Xu"
Date: Fri, 15 Jan 2016 12:40:46 +0800
Subject: [PATCH 5/8] fix label and sprite canvas rendering
---
cocos2d/core/label/CCSGLabelCanvasRenderCmd.js | 3 ++-
cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js | 8 ++++----
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
index bd0503e323..867a60ec23 100644
--- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
+++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
@@ -375,10 +375,11 @@
var x, y, w, h;
x = 0;
- y = 0;
+ y = -this._node._contentSize.height;
w = this._node._contentSize.width;
h = this._node._contentSize.height;
+
var textureWidth = this._labelTexture.getPixelWidth();
var textureHeight = this._labelTexture.getPixelHeight();
diff --git a/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js
index 65b0281fe7..5e13a0b466 100644
--- a/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js
+++ b/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js
@@ -71,7 +71,7 @@
var wrapper = ctx || cc._renderContext, context = wrapper.getContext();
wrapper.setTransform(this._worldTransform, scaleX, scaleY);
- wrapper.setCompositeOperation(node._blendFunc);
+ wrapper.setCompositeOperation(_ccsg.Node.CanvasRenderCmd._getCompositeOperationByBlendFunc(node._blendFunc));
wrapper.setGlobalAlpha(alpha);
if(this._textureToRender) {
@@ -94,10 +94,10 @@
var textureWidth = this._textureToRender.getPixelWidth();
var textureHeight = this._textureToRender.getPixelHeight();
- sx = quads[i]._bl.texCoords.u * textureWidth;
- sy = quads[i]._bl.texCoords.v * textureHeight;
+ sx = quads[i]._tl.texCoords.u * textureWidth;
+ sy = quads[i]._tl.texCoords.v * textureHeight;
sw = (quads[i]._tr.texCoords.u - quads[i]._bl.texCoords.u) * textureWidth;
- sh = (quads[i]._tr.texCoords.v - quads[i]._bl.texCoords.v) * textureHeight;
+ sh = (quads[i]._bl.texCoords.v - quads[i]._tr.texCoords.v) * textureHeight;
x = x * scaleX;
y = y * scaleY;
From b5dffdbed27dcbe63568d550bd2318d1c586ed55 Mon Sep 17 00:00:00 2001
From: "Huabing.Xu"
Date: Fri, 15 Jan 2016 15:39:05 +0800
Subject: [PATCH 6/8] ......
---
cocos2d/core/label/CCSGLabelCanvasRenderCmd.js | 8 +++++---
cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js | 8 +++++---
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
index 867a60ec23..0a29de15e5 100644
--- a/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
+++ b/cocos2d/core/label/CCSGLabelCanvasRenderCmd.js
@@ -398,9 +398,11 @@
wrapper.setFillStyle(context.createPattern(image, this._labelTexture._pattern));
context.fillRect(x, y, w, h);
} else {
- context.drawImage(image,
- sx, sy, sw, sh,
- x, y, w, h);
+ if(sw !== 0 && sh !== 0 && w !== 0 && h !== 0) {
+ context.drawImage(image,
+ sx, sy, sw, sh,
+ x, y, w, h);
+ }
}
}
cc.g_NumberOfDraws = cc.g_NumberOfDraws + 1;
diff --git a/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js b/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js
index 5e13a0b466..36844c4d72 100644
--- a/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js
+++ b/cocos2d/core/sprites/CCScale9SpriteCanvasRenderCmd.js
@@ -109,9 +109,11 @@
wrapper.setFillStyle(context.createPattern(image, this._textureToRender._pattern));
context.fillRect(x, y, w, h);
} else {
- context.drawImage(image,
- sx, sy, sw, sh,
- x, y, w, h);
+ if(sw !== 0 && sh !== 0 && w !== 0 && h !== 0) {
+ context.drawImage(image,
+ sx, sy, sw, sh,
+ x, y, w, h);
+ }
}
}
From 1dbf6d3f43720c1d6fe2c219a0465d29f445f89f Mon Sep 17 00:00:00 2001
From: pandamicro
Date: Fri, 15 Jan 2016 16:13:40 +0800
Subject: [PATCH 7/8] Improve doc and code hint
---
cocos2d/core/CCDirector.js | 2 +-
cocos2d/core/platform/CCEGLView.js | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js
index aadfe24eab..a398ab8e16 100644
--- a/cocos2d/core/CCDirector.js
+++ b/cocos2d/core/CCDirector.js
@@ -64,7 +64,7 @@ cc.g_NumberOfDraws = 0;
* - Scheduled timers & drawing are synchronizes with the refresh rate of the display
* - Only supports animation intervals of 1/60 1/30 & 1/15
*
- * @class Director
+ * @class director
*/
cc.Director = Class.extend(/** @lends cc.Director# */{
//Variables
diff --git a/cocos2d/core/platform/CCEGLView.js b/cocos2d/core/platform/CCEGLView.js
index aa7352d783..d633b53603 100644
--- a/cocos2d/core/platform/CCEGLView.js
+++ b/cocos2d/core/platform/CCEGLView.js
@@ -114,7 +114,7 @@ switch(cc.__BrowserGetter.adaptationType){
* the standard way to use it is by calling:
* - cc.view.methodName();
*
- * @class EGLView
+ * @class view
* @extends _Class
*/
cc.EGLView = cc._Class.extend(/** @lends cc.view# */{
From 9bb7bbdea0ac866a566826500e1613981b9a32b2 Mon Sep 17 00:00:00 2001
From: Jare Guo
Date: Fri, 15 Jan 2016 16:55:58 +0800
Subject: [PATCH 8/8] sprite should not display if disabled in scene
---
cocos2d/core/components/CCSprite.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/cocos2d/core/components/CCSprite.js b/cocos2d/core/components/CCSprite.js
index 686527795b..0dffcf95c3 100644
--- a/cocos2d/core/components/CCSprite.js
+++ b/cocos2d/core/components/CCSprite.js
@@ -372,6 +372,10 @@ var Sprite = cc.Class({
_createSgNode: function () {
var sgNode = new cc.Scale9Sprite();
+ if ( !this.enabledInHierarchy ) {
+ sgNode.setVisible(false);
+ }
+
this._applySpriteFrame(sgNode, null);
// should keep the size of the sg node the same as entity,