From d936b9628b5d782ff96eeebc03e3346b563e13f9 Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 21 Jun 2017 16:22:27 +0800 Subject: [PATCH] fix CC_DEV in build worker --- cocos2d/core/platform/CCClass.js | 24 ++++++++---------------- cocos2d/core/platform/deserialize.js | 2 +- cocos2d/core/platform/js.js | 6 +++--- extensions/spine/Skeleton.js | 4 ++-- index.js | 2 +- jsb/index.js | 2 +- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/cocos2d/core/platform/CCClass.js b/cocos2d/core/platform/CCClass.js index cc9f56a00e..2c3bbeee2f 100644 --- a/cocos2d/core/platform/CCClass.js +++ b/cocos2d/core/platform/CCClass.js @@ -169,6 +169,7 @@ function defineGetSet (cls, name, propName, val, es6) { var setter = val.set; var proto = cls.prototype; var d = Object.getOwnPropertyDescriptor(proto, propName); + var setterUndefined = !d; if (getter) { if (CC_DEV && !es6 && d && d.get) { @@ -192,32 +193,23 @@ function defineGetSet (cls, name, propName, val, es6) { } if (!es6) { - var setterUndefined = !d; JS.get(proto, propName, getter, setterUndefined, setterUndefined); } - if (CC_DEV) { + if (CC_EDITOR || CC_DEV) { Attr.setClassAttr(cls, propName, 'hasGetter', true); // 方便 editor 做判断 } } if (setter) { - if (CC_DEV) { - if (!es6) { - if (d && d.set) { - return cc.errorID(3640, name, propName); - } - JS.set(proto, propName, setter, true, true); + if (!es6) { + if (CC_DEV && d && d.set) { + return cc.errorID(3640, name, propName); } - Attr.setClassAttr(cls, propName, 'hasSetter', true); // 方便 editor 做判断 + JS.set(proto, propName, setter, setterUndefined, setterUndefined); } - else if (!es6) { - if (d) { - JS.set(proto, propName, setter); - } - else { - JS.set(proto, propName, setter, true, true); - } + if (CC_EDITOR || CC_DEV) { + Attr.setClassAttr(cls, propName, 'hasSetter', true); // 方便 editor 做判断 } } } diff --git a/cocos2d/core/platform/deserialize.js b/cocos2d/core/platform/deserialize.js index 9b85492993..ad7abe7a70 100644 --- a/cocos2d/core/platform/deserialize.js +++ b/cocos2d/core/platform/deserialize.js @@ -76,7 +76,7 @@ Details.prototype.reset = function () { //this.rawObjList.length = 0; //this.rawPropList.length = 0; }; -if (CC_DEV) { +if (CC_EDITOR) { Details.prototype.assignAssetsBy = function (getter) { for (var i = 0, len = this.uuidList.length; i < len; i++) { var uuid = this.uuidList[i]; diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js index 92590d0804..c4d553e6da 100644 --- a/cocos2d/core/platform/js.js +++ b/cocos2d/core/platform/js.js @@ -376,7 +376,7 @@ js.getClassName = function (objOrCtor) { return ''; }; -function isTempClassId_DEV (id) { +function isTempClassId (id) { return typeof id !== 'string' || id.startsWith(tempCIDGenerater.prefix); } @@ -512,7 +512,7 @@ cc.js.unregisterClass to remove the id of unused class'; var res; if (typeof obj === 'function' && obj.prototype.hasOwnProperty('__cid__')) { res = obj.prototype.__cid__; - if (!allowTempId && CC_DEV && isTempClassId_DEV(res)) { + if (!allowTempId && (CC_DEV || CC_EDITOR) && isTempClassId(res)) { return ''; } return res; @@ -521,7 +521,7 @@ cc.js.unregisterClass to remove the id of unused class'; var prototype = obj.constructor.prototype; if (prototype && prototype.hasOwnProperty('__cid__')) { res = obj.__cid__; - if (!allowTempId && CC_DEV && isTempClassId_DEV(res)) { + if (!allowTempId && (CC_DEV || CC_EDITOR) && isTempClassId(res)) { return ''; } return res; diff --git a/extensions/spine/Skeleton.js b/extensions/spine/Skeleton.js index bb323579a5..220260cadb 100644 --- a/extensions/spine/Skeleton.js +++ b/extensions/spine/Skeleton.js @@ -390,12 +390,12 @@ sp.Skeleton = cc.Class({ // IMPLEMENT __preload: function () { - // sgNode 的尺寸不是很可靠 同时 Node 的框框也没办法和渲染匹配 只好强制尺寸为零 - if (CC_DEV) { + if (CC_EDITOR || CC_DEV) { var Flags = cc.Object.Flags; this._objFlags &= Flags.PersistentMask; // for v1.0 project this._objFlags |= (Flags.IsAnchorLocked | Flags.IsSizeLocked); } + // sgNode 的尺寸不是很可靠 同时 Node 的框框也没办法和渲染匹配 只好强制尺寸为零 this.node.setContentSize(0, 0); // this._refresh(); diff --git a/index.js b/index.js index d5e78e71be..6e8fca92fd 100644 --- a/index.js +++ b/index.js @@ -120,7 +120,7 @@ Function( defineMacro('CC_TEST', defined('tap') + '||' + defined('QUnit')) + defineMacro('CC_EDITOR', defined('Editor') + '&&' + defined('process') + '&&"electron" in process.versions') + defineMacro('CC_PREVIEW', '!CC_EDITOR') + - defineMacro('CC_DEV', true) + // CC_EDITOR || CC_PREVIEW || CC_TEST + defineMacro('CC_DEV', true) + // (CC_EDITOR && !CC_BUILD) || CC_PREVIEW || CC_TEST defineMacro('CC_DEBUG', true) + // CC_DEV || Debug Build defineMacro('CC_JSB', defined('jsb')) + defineMacro('CC_BUILD', false) diff --git a/jsb/index.js b/jsb/index.js index f7312ed508..b59a87f4e1 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -64,7 +64,7 @@ Function( defineMacro('CC_TEST', defined('tap') + '||' + defined('QUnit')) + defineMacro('CC_EDITOR', defined('Editor') + '&&' + defined('process') + '&&"electron" in process.versions') + defineMacro('CC_PREVIEW', '!CC_EDITOR') + - defineMacro('CC_DEV', true) + // CC_EDITOR || CC_PREVIEW || CC_TEST + defineMacro('CC_DEV', true) + // (CC_EDITOR && !CC_BUILD) || CC_PREVIEW || CC_TEST defineMacro('CC_DEBUG', true) + // CC_DEV || Debug Build defineMacro('CC_JSB', defined('jsb')) + defineMacro('CC_BUILD', false)