From b778dde9c97e56cc888b166357a009cc6b9f0bab Mon Sep 17 00:00:00 2001 From: pandamicro Date: Thu, 8 Mar 2018 11:42:36 +0800 Subject: [PATCH] Fix wechat game HTMLVideoElement issue and deserialize issue --- cocos2d/core/platform/deserialize.js | 22 +++++++++++++++++----- index.js | 4 ++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/cocos2d/core/platform/deserialize.js b/cocos2d/core/platform/deserialize.js index cbc077f5db..4452c9447f 100644 --- a/cocos2d/core/platform/deserialize.js +++ b/cocos2d/core/platform/deserialize.js @@ -551,7 +551,7 @@ var _Deserializer = (function () { } else { var defaultType = typeof defaultValue; - isPrimitiveType = (defaultType === 'string' && !attrs[propName + SAVE_URL_AS_ASSET]) || + isPrimitiveType = (defaultType === 'string' && !stillUseUrl) || defaultType === 'number' || defaultType === 'boolean'; } @@ -580,6 +580,7 @@ var _Deserializer = (function () { } return Function('s', 'o', 'd', 'k', 't', sources.join('')); } : function (self, klass) { + var TYPE = Attr.DELIMETER + 'type'; var EDITOR_ONLY = Attr.DELIMETER + 'editorOnly'; var SERIALIZABLE = Attr.DELIMETER + 'serializable'; var DEFAULT = Attr.DELIMETER + 'default'; @@ -616,10 +617,21 @@ var _Deserializer = (function () { // function undefined object(null) string boolean number var defaultValue = CCClass.getDefault(attrs[propName + DEFAULT]); if (fastMode) { - var defaultType = typeof defaultValue; - var isPrimitiveType = (defaultType === 'string' && !stillUseUrl) || - defaultType === 'number' || - defaultType === 'boolean'; + var isPrimitiveType; + var userType = attrs[propName + TYPE]; + if (defaultValue === undefined && userType) { + isPrimitiveType = userType === cc.String || + userType === cc.Integer || + userType === cc.Float || + userType === cc.Boolean; + } + else { + var defaultType = typeof defaultValue; + isPrimitiveType = (defaultType === 'string' && !stillUseUrl) || + defaultType === 'number' || + defaultType === 'boolean'; + } + if (isPrimitiveType) { o[propName] = prop; } diff --git a/index.js b/index.js index 0920b95e2e..4190390626 100644 --- a/index.js +++ b/index.js @@ -164,6 +164,10 @@ require('./polyfill/array'); if (!(CC_EDITOR && Editor.isMainProcess)) { require('./polyfill/typescript'); } +// empty polyfill HTMLVideoElement +if (CC_WECHATGAME) { + _global.HTMLVideoElement = function () {}; +} require('./cocos2d/core/predefine');