diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index 6d9362cf86..c69217cdc9 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -209,7 +209,9 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ } // WidgetManager - cc._widgetManager.init(this); + if (cc._widgetManager) { + cc._widgetManager.init(this); + } }, /** diff --git a/cocos2d/core/utils/CCProfiler.js b/cocos2d/core/utils/CCProfiler.js index 7b7d9624cc..4f78ebab24 100644 --- a/cocos2d/core/utils/CCProfiler.js +++ b/cocos2d/core/utils/CCProfiler.js @@ -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 = { diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 06d94e6e9c..08a2953457 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -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', diff --git a/gulp/tasks/engine.js b/gulp/tasks/engine.js index ead260220e..afda865e9e 100644 --- a/gulp/tasks/engine.js +++ b/gulp/tasks/engine.js @@ -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) { diff --git a/index.js b/index.js index 0054173420..b53710bcbc 100644 --- a/index.js +++ b/index.js @@ -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 diff --git a/modules.json b/modules.json index be9205984d..e824878108 100644 --- a/modules.json +++ b/modules.json @@ -132,5 +132,19 @@ "entries": [ "./cocos2d/core/collider/index.js" ] + }, + + + { + "name": "Action", + "entries": [ + "./cocos2d/actions/index.js" + ] + }, + { + "name": "Audio", + "entries": [ + "./cocos2d/audio/CCAudio.js" + ] } ] \ No newline at end of file