diff --git a/cocos2d/core/components/CCLabel.js b/cocos2d/core/components/CCLabel.js index d642520256..5cd7abac48 100644 --- a/cocos2d/core/components/CCLabel.js +++ b/cocos2d/core/components/CCLabel.js @@ -229,29 +229,35 @@ var Label = cc.Class({ tooltip: 'i18n:COMPONENT.label.wrap', }, + // 这个保存了旧项目的 file 数据 + _N$file: null, + /** - * !#en The font URL of label. - * !#zh 文本字体的 url。 - * @property {cc.Font} file + * !#en The font of label. + * !#zh 文本字体。 + * @property {cc.Font} font */ - file: { - default: null, - type: cc.Font, - tooltip: 'i18n:COMPONENT.label.file', - notify: function () { + font: { + get: function () { + return this._N$file; + }, + set: function (value) { + this._N$file = value; if (this._sgNode) { - if ( typeof this.file === 'string' ) { + if ( typeof value === 'string' ) { cc.warn('Sorry, the cc.Font has been modified from Raw Asset to Asset.' + 'Please load the font asset before using.'); } - var isAsset = this.file instanceof cc.Font; - var fntRawUrl = isAsset ? this.file.rawUrl : ''; - var textureUrl = isAsset ? this.file.texture : ''; + var isAsset = value instanceof cc.Font; + var fntRawUrl = isAsset ? value.rawUrl : ''; + var textureUrl = isAsset ? value.texture : ''; this._sgNode.setFontFileOrFamily(fntRawUrl, textureUrl); } }, + type: cc.Font, + tooltip: 'i18n:COMPONENT.label.font', animatable: false }, @@ -272,7 +278,7 @@ var Label = cc.Class({ set: function(value){ this._isSystemFontUsed = value; if (value) { - this.file = null; + this.font = null; if (this._sgNode) { this._sgNode.setSystemFontUsed(value); } @@ -334,14 +340,14 @@ var Label = cc.Class({ _initSgNode: function () { - if ( typeof this.file === 'string' ) { + if ( typeof this.font === 'string' ) { cc.warn('Sorry, the cc.Font has been modified from Raw Asset to Asset.' + 'Please load the font asset before using.'); } - var isAsset = this.file instanceof cc.Font; - var fntRawUrl = isAsset ? this.file.rawUrl : ''; - var textureUrl = isAsset ? this.file.texture : ''; + var isAsset = this.font instanceof cc.Font; + var fntRawUrl = isAsset ? this.font.rawUrl : ''; + var textureUrl = isAsset ? this.font.texture : ''; this._sgNode = new _ccsg.Label(this.string, fntRawUrl, textureUrl); this._sgNode.retain(); diff --git a/cocos2d/core/platform/js.js b/cocos2d/core/platform/js.js index fcaf3cd1dd..c8148ad220 100644 --- a/cocos2d/core/platform/js.js +++ b/cocos2d/core/platform/js.js @@ -499,19 +499,25 @@ js.set = function (obj, prop, setter, enumerable) { */ js.obsolete = function (obj, obsoleted, newPropName, writable) { var oldName = obsoleted.split('.').slice(-1); - js.get(obj, oldName, function () { + function get () { if (CC_DEV) { cc.warn('"%s" is deprecated, use "%s" instead please.', obsoleted, newPropName); } - return obj[newPropName]; - }); + return this[newPropName]; + } if (writable) { - js.set(obj, oldName, function (value) { - if (CC_DEV) { - cc.warn('"%s" is deprecated, use "%s" instead please.', obsoleted, newPropName); + js.getset(obj, oldName, + get, + function (value) { + if (CC_DEV) { + cc.warn('"%s" is deprecated, use "%s" instead please.', obsoleted, newPropName); + } + this[newPropName] = value; } - obj[newPropName] = value; - }); + ); + } + else { + js.get(obj, oldName, get); } }; diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index 309d055660..114d9788a8 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -1,5 +1,9 @@ +var js = cc.js; + +// Label +js.obsolete(cc.Label.prototype, 'cc.Label.file', 'font', true); + if (CC_DEV) { - var js = cc.js; var INFO = cc._LogInfos.deprecated; @@ -546,9 +550,9 @@ if (CC_DEV) { }); //ui - cc.js.obsolete(cc.Layout.prototype, 'Layout.layoutType', 'type'); - cc.js.obsolete(cc.Layout.prototype, 'Layout.ResizeType', 'ResizeMode'); - cc.js.obsolete(cc.Layout.prototype, 'Layout.resize', 'resizeMode'); + 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', @@ -583,4 +587,3 @@ if (CC_DEV) { }); } } - diff --git a/index.js b/index.js index 3900c2e7b1..7a1f4d997a 100644 --- a/index.js +++ b/index.js @@ -72,7 +72,7 @@ if (CC_EDITOR) { if (isMainProcess) { Editor.versions['cocos2d'] = require('./package.json').version; } -else if (CC_DEV) { +else { require('./cocos2d/deprecated'); }