Merge pull request #841 from VisualSJ/master-modular

预防部分模块不存在的时候js异常中断
This commit is contained in:
Jare Guo
2016-06-28 17:22:05 +08:00
committed by GitHub
6 changed files with 79 additions and 54 deletions
+3 -1
View File
@@ -209,7 +209,9 @@ cc.Director = Class.extend(/** @lends cc.Director# */{
}
// WidgetManager
cc._widgetManager.init(this);
if (cc._widgetManager) {
cc._widgetManager.init(this);
}
},
/**
+9 -3
View File
@@ -134,9 +134,15 @@ cc.profiler = (function () {
};
var afterProjection = function(){
_FPSLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
_SPFLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
_drawsLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
if (_FPSLabel) {
_FPSLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
}
if (_SPFLabel) {
_SPFLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
}
if (_drawsLabel) {
_drawsLabel._renderCmd.setDirtyFlag(_ccsg.Node._dirtyFlags.transformDirty);
}
};
var profiler = {
+16 -8
View File
@@ -1,7 +1,9 @@
var js = cc.js;
// Label
js.obsolete(cc.Label.prototype, 'cc.Label.file', 'font', true);
if (cc.Label) {
js.obsolete(cc.Label.prototype, 'cc.Label.file', 'font', true);
}
if (CC_DEV) {
@@ -259,10 +261,14 @@ if (CC_DEV) {
deprecateEnum(cc, 'cc.TEXT_ALIGNMENT', 'cc.TextAlignment');
deprecateEnum(cc, 'cc.VERTICAL_TEXT_ALIGNMENT', 'cc.VerticalTextAlignment');
deprecateEnum(_ccsg.ParticleSystem, '_ccsg.ParticleSystem.TYPE', '_ccsg.ParticleSystem.Type');
deprecateEnum(_ccsg.ParticleSystem, '_ccsg.ParticleSystem.MODE', '_ccsg.ParticleSystem.Mode');
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.TYPE', 'cc.ParticleSystem.PositionType');
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.MODE', 'cc.ParticleSystem.EmitterMode');
if (_ccsg.ParticleSystem) {
deprecateEnum(_ccsg.ParticleSystem, '_ccsg.ParticleSystem.TYPE', '_ccsg.ParticleSystem.Type');
deprecateEnum(_ccsg.ParticleSystem, '_ccsg.ParticleSystem.MODE', '_ccsg.ParticleSystem.Mode');
}
if (cc.ParticleSystem) {
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.TYPE', 'cc.ParticleSystem.PositionType');
deprecateEnum(cc.ParticleSystem, 'cc.ParticleSystem.MODE', 'cc.ParticleSystem.EmitterMode');
}
// deprecateEnum(cc.ProgressTimer, 'cc.ProgressTimer.TYPE', 'cc.ProgressTimer.Type');
deprecateEnum(cc.game, 'cc.game.DEBUG_MODE', 'cc.DebugMode');
deprecateEnum(cc, 'cc', 'cc.Texture2D.WrapMode', false);
@@ -566,9 +572,11 @@ if (CC_DEV) {
});
//ui
js.obsolete(cc.Layout.prototype, 'cc.Layout.layoutType', 'type');
js.obsolete(cc.Layout.prototype, 'cc.Layout.ResizeType', 'ResizeMode');
js.obsolete(cc.Layout.prototype, 'cc.Layout.resize', 'resizeMode');
if (cc.Layout) {
js.obsolete(cc.Layout.prototype, 'cc.Layout.layoutType', 'type');
js.obsolete(cc.Layout.prototype, 'cc.Layout.ResizeType', 'ResizeMode');
js.obsolete(cc.Layout.prototype, 'cc.Layout.resize', 'resizeMode');
}
markAsRemoved(cc.Scale9Sprite, [
'init',
+35 -33
View File
@@ -44,7 +44,7 @@ exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) {
var bundler = Utils.createBundler(sourceFile);
excludes && excludes.forEach(function (file) {
bundler.exclude(file);
bundler.ignore(file);
});
var uglifyOption = Utils.uglifyOptions(false, {
@@ -54,27 +54,27 @@ exports.buildCocosJs = function (sourceFile, outputFile, excludes, callback) {
CC_JSB: false
});
bundler.bundle()
.pipe(Source(outFile))
.pipe(Buffer())
.pipe(Sourcemaps.init({loadMaps: true}))
.pipe(Uglify(uglifyOption))
.pipe(Sourcemaps.write('./', {
sourceRoot: './',
includeContent: true,
addComment: true
}))
.pipe(Gulp.dest(outDir))
.on('end', callback);
bundler = bundler.bundle();
bundler = bundler.pipe(Source(outFile));
bundler = bundler.pipe(Buffer());
bundler = bundler.pipe(Sourcemaps.init({loadMaps: true}));
bundler = bundler.pipe(Uglify(uglifyOption));
bundler = bundler.pipe(Sourcemaps.write('./', {
sourceRoot: './',
includeContent: true,
addComment: true
}));
bundler = bundler.pipe(Gulp.dest(outDir));
return bundler.on('end', callback);
};
exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, callback) {
exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, callback, createMap) {
var outDir = Path.dirname(outputFile);
var outFile = Path.basename(outputFile);
var bundler = Utils.createBundler(sourceFile);
excludes && excludes.forEach(function (file) {
bundler.exclude(file);
bundler.ignore(file);
});
var uglifyOption = Utils.uglifyOptions(true, {
@@ -87,27 +87,29 @@ exports.buildCocosJsMin = function (sourceFile, outputFile, excludes, callback)
var rawSize = Size({ gzip: false, pretty: false, showTotal: false, showFiles: false });
var zippedSize = Size({ gzip: true, pretty: false, showTotal: false, showFiles: false });
bundler.bundle()
.pipe(Source(outFile))
.pipe(Buffer())
.pipe(Sourcemaps.init({loadMaps: true}))
.pipe(Uglify(uglifyOption))
.pipe(rawSize)
.pipe(zippedSize)
.pipe(EventStream.through(null, function () {
var raw = rawSize.size;
var zipped = zippedSize.size;
var percent = ((zipped / raw) * 100).toFixed(2);
console.log(`Size of ${outputFile}: minimized: ${Chalk.cyan(raw + 'B')} zipped: ${Chalk.cyan(zipped + 'B')}, compression ratio: ${percent}%`);
this.emit('end');
}))
.pipe(Sourcemaps.write('./', {
bundler = bundler.bundle();
bundler = bundler.pipe(Source(outFile));
bundler = bundler.pipe(Buffer());
if (createMap !== false)
bundler = bundler.pipe(Sourcemaps.init({loadMaps: true}));
bundler = bundler.pipe(Uglify(uglifyOption));
bundler = bundler.pipe(rawSize);
bundler = bundler.pipe(zippedSize);
bundler = bundler.pipe(EventStream.through(null, function () {
var raw = rawSize.size;
var zipped = zippedSize.size;
var percent = ((zipped / raw) * 100).toFixed(2);
console.log(`Size of ${outputFile}: minimized: ${Chalk.cyan(raw + 'B')} zipped: ${Chalk.cyan(zipped + 'B')}, compression ratio: ${percent}%`);
this.emit('end');
}));
if (createMap !== false)
bundler = bundler.pipe(Sourcemaps.write('./', {
sourceRoot: './',
includeContent: true,
addComment: true
}))
.pipe(Gulp.dest(outDir))
.on('end', callback);
}));
bundler = bundler.pipe(Gulp.dest(outDir));
return bundler.on('end', callback);
};
exports.buildPreview = function (sourceFile, outputFile, callback) {
+2 -9
View File
@@ -48,15 +48,8 @@ require('./predefine');
var isMainProcess = CC_EDITOR && Editor.isMainProcess;
if (!isMainProcess) {
// LOAD ORIGIN COCOS2D COMPILED BY CLOSURE
try {
require('./bin/modular-cocos2d');
} catch (error) {
if (error.code === 'MODULE_NOT_FOUND') {
require('./bin/modular-cocos2d-cut');
} else {
throw error;
}
}
require('./bin/modular-cocos2d');
require('./bin/modular-cocos2d-cut');
}
else {
// load modules for editor's core-level which included in modular-cocos2d.js
+14
View File
@@ -132,5 +132,19 @@
"entries": [
"./cocos2d/core/collider/index.js"
]
},
{
"name": "Action",
"entries": [
"./cocos2d/actions/index.js"
]
},
{
"name": "Audio",
"entries": [
"./cocos2d/audio/CCAudio.js"
]
}
]