From a4eb3ba8111004f3bf9d42e6f2d93a3eebb3b82a Mon Sep 17 00:00:00 2001 From: Knox Date: Tue, 26 Jun 2018 16:42:39 +0800 Subject: [PATCH 1/8] fix dragonBones parseDragonBonesData bug in jsb (#2892) * fix dragonBones parseDragonBonesData bug in jsb * refine code --- extensions/dragonbones/DragonBonesAsset.js | 41 +++++++--------- jsb/index.js | 1 + jsb/jsb-dragonbones-asset.js | 54 ++++++++++++++++++++++ 3 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 jsb/jsb-dragonbones-asset.js diff --git a/extensions/dragonbones/DragonBonesAsset.js b/extensions/dragonbones/DragonBonesAsset.js index dcde2b24cd..7b4b49dd8e 100644 --- a/extensions/dragonbones/DragonBonesAsset.js +++ b/extensions/dragonbones/DragonBonesAsset.js @@ -102,32 +102,25 @@ var DragonBonesAsset = cc.Class({ } } else { - if (CC_JSB) { - // The 'factory' create a new one every time in JSB, they can't use getDragonBonesData - // to get cached data, and don't need to merge armatures. - this._dragonBonesData = factory.parseDragonBonesData(this._dragonBonesJson); + let _dragonBonesJson = JSON.parse(this.dragonBonesJson); + let sameNamedDragonBonesData = factory.getDragonBonesData(_dragonBonesJson.name); + if (sameNamedDragonBonesData) { + // already added asset, see #2002 + let dragonBonesData; + for (let i = 0; i < _dragonBonesJson.armature.length; i++) { + let armatureName = _dragonBonesJson.armature[i].name; + if (!sameNamedDragonBonesData.armatures[armatureName]) { + // add new armature + if (!dragonBonesData) { + dragonBonesData = factory._dataParser.parseDragonBonesData(_dragonBonesJson); + } + sameNamedDragonBonesData.addArmature(dragonBonesData.armatures[armatureName]); + } + } + this._dragonBonesData = sameNamedDragonBonesData; } else { - let jsonObj = JSON.parse(this._dragonBonesJson); - let sameNamedDragonBonesData = factory.getDragonBonesData(jsonObj.name); - if (sameNamedDragonBonesData) { - // already added asset, see #2002 - let dragonBonesData; - for (let i = 0; i < jsonObj.armature.length; i++) { - let armatureName = jsonObj.armature[i].name; - if (!sameNamedDragonBonesData.armatures[armatureName]) { - // add new armature - if (!dragonBonesData) { - dragonBonesData = factory._dataParser.parseDragonBonesData(jsonObj); - } - sameNamedDragonBonesData.addArmature(dragonBonesData.armatures[armatureName]); - } - } - this._dragonBonesData = sameNamedDragonBonesData; - } - else { - this._dragonBonesData = factory.parseDragonBonesData(jsonObj); - } + this._dragonBonesData = factory.parseDragonBonesData(_dragonBonesJson); } } }, diff --git a/jsb/index.js b/jsb/index.js index 2269feb143..d8dddb1a40 100644 --- a/jsb/index.js +++ b/jsb/index.js @@ -74,6 +74,7 @@ require('./jsb-etc'); require('./jsb-audio'); require('./jsb-tiledmap'); require('./jsb-box2d'); +require('./jsb-dragonbones-asset'); require('./jsb-dragonbones'); require('../extends'); diff --git a/jsb/jsb-dragonbones-asset.js b/jsb/jsb-dragonbones-asset.js new file mode 100644 index 0000000000..f1e1227fd6 --- /dev/null +++ b/jsb/jsb-dragonbones-asset.js @@ -0,0 +1,54 @@ +/**************************************************************************** + Copyright (c) 2013-2016 Chukong Technologies Inc. + Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd. + + http://www.cocos.com + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated engine source code (the "Software"), a limited, + worldwide, royalty-free, non-assignable, revocable and non-exclusive license + to use Cocos Creator solely to develop games on your target platforms. You shall + not use Cocos Creator software for developing other software or tools that's + used for developing games. You are not granted to publish, distribute, + sublicense, and/or sell copies of Cocos Creator. + + The software or tools in this License Agreement are licensed, not sold. + Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + ****************************************************************************/ + +'use strict'; + +var WebDragonBonesAsset = require('../extensions/dragonbones/DragonBonesAsset.js'); + +var prototype = WebDragonBonesAsset.prototype; + +prototype.init = function (factory) { + if (CC_EDITOR) { + factory = factory || new dragonBones.CCFactory(); + } + + if (this._dragonBonesData) { + let sameNamedDragonBonesData = factory.getDragonBonesData(this._dragonBonesData.name); + if (!sameNamedDragonBonesData) { + factory.addDragonBonesData(this._dragonBonesData); + } + } + else { + let _dragonBonesJson = JSON.parse(this.dragonBonesJson); + let sameNamedDragonBonesData = factory.getDragonBonesData(_dragonBonesJson.name); + if (sameNamedDragonBonesData) { + this._dragonBonesData = sameNamedDragonBonesData; + } + else { + this._dragonBonesData = factory.parseDragonBonesData(this._dragonBonesJson); + } + } +}; \ No newline at end of file From f38ed3675fb64bc769fd5f47a9f7d183c3162fae Mon Sep 17 00:00:00 2001 From: Knox Date: Tue, 26 Jun 2018 18:34:20 +0800 Subject: [PATCH 2/8] fixed editorbox stayOnTop exTxt value error (#2905) --- cocos2d/core/editbox/CCSGEditBox.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cocos2d/core/editbox/CCSGEditBox.js b/cocos2d/core/editbox/CCSGEditBox.js index 221aa07e9a..902eaea376 100644 --- a/cocos2d/core/editbox/CCSGEditBox.js +++ b/cocos2d/core/editbox/CCSGEditBox.js @@ -1049,6 +1049,9 @@ _ccsg.EditBox.KeyboardReturnType = KeyboardReturnType; else if (inputFlag === InputFlag.INITIAL_CAPS_SENTENCE) { this._editBox._text = capitalizeFirstLetter(this._editBox._text); } + if (this._edTxt) { + this._edTxt.value = this._editBox._text; + } }; proto._updateLabelStringStyle = function() { From c632073018cf7909d0081296355f412bd89215cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=AE=B6=E8=BE=89?= <35832931+ColinCollins@users.noreply.github.com> Date: Wed, 27 Jun 2018 12:55:21 +0800 Subject: [PATCH 3/8] modfity the creator.t.ds (#2912) --- cocos2d/core/platform/CCMacro.js | 1 + cocos2d/core/value-types/CCVec2.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cocos2d/core/platform/CCMacro.js b/cocos2d/core/platform/CCMacro.js index 3c0884f136..94377a9bfe 100644 --- a/cocos2d/core/platform/CCMacro.js +++ b/cocos2d/core/platform/CCMacro.js @@ -2003,6 +2003,7 @@ cc.defineGetterSetter(cc.macro, "BLEND_SRC", function (){ * @param {Number} a number A * @param {Number} b number B * @param {Number} r ratio between 0 and 1 + * @return {Number} * @example {@link cocos2d/core/platform/CCMacro/lerp.js} */ cc.lerp = function (a, b, r) { diff --git a/cocos2d/core/value-types/CCVec2.js b/cocos2d/core/value-types/CCVec2.js index 481ea025b1..6dacb7fc2f 100644 --- a/cocos2d/core/value-types/CCVec2.js +++ b/cocos2d/core/value-types/CCVec2.js @@ -285,7 +285,7 @@ proto.scale = function (vector, out) { * !#en Divides by a number. If you want to save result to another vector, use div() instead. * !#zh 向量除法。如果你想结果保存到另一个向量,可使用 div() 代替。 * @method divSelf - * @param {Vec2} vector + * @param {Number} divisor * @return {Vec2} returns this * @chainable * @example @@ -302,7 +302,7 @@ proto.divSelf = function (num) { * !#en Divides by a number, and returns the new result. * !#zh 向量除法,并返回新的结果。 * @method div - * @param {Vec2} vector + * @param {Number} divisor * @param {Vec2} [out] - optional, the receiving vector * @return {Vec2} the result * @example From 93804c9f005b4001183abd68017639fe9d0bace0 Mon Sep 17 00:00:00 2001 From: Knox Date: Thu, 28 Jun 2018 15:58:43 +0800 Subject: [PATCH 4/8] fix _unregisterAccelerometerEvent err (#2918) --- cocos2d/core/platform/CCInputExtension.js | 5 ++++- cocos2d/core/platform/CCInputManager.js | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cocos2d/core/platform/CCInputExtension.js b/cocos2d/core/platform/CCInputExtension.js index f9f2590999..49c4994f24 100644 --- a/cocos2d/core/platform/CCInputExtension.js +++ b/cocos2d/core/platform/CCInputExtension.js @@ -32,6 +32,8 @@ var inputManager = require("./CCInputManager"); inputManager.__instanceId = cc.ClassManager.getNewInstanceId(); +var _didAccelerateFun; + /** * whether enable accelerometer event * @method setAccelerometerEnabled @@ -92,7 +94,8 @@ inputManager._registerAccelerometerEvent = function(){ _t._minus = -1; } - w.addEventListener(_deviceEventType, _t.didAccelerate.bind(_t), false); + _didAccelerateFun = _t.didAccelerate.bind(_t); + w.addEventListener(_deviceEventType, _didAccelerateFun, false); }; inputManager._unregisterAccelerometerEvent = function () { diff --git a/cocos2d/core/platform/CCInputManager.js b/cocos2d/core/platform/CCInputManager.js index 63a34acbdc..7cd689928f 100644 --- a/cocos2d/core/platform/CCInputManager.js +++ b/cocos2d/core/platform/CCInputManager.js @@ -610,6 +610,5 @@ js.get(cc, 'inputManager', function () { cc.warnID(1405, 'cc.inputManager', 'cc.systemEvent'); return inputManager; }); -_cc.inputManager = inputManager; -module.exports = inputManager; +module.exports = _cc.inputManager = inputManager; From 13f46cd3ce943a890dc5fdd9c9b19a858ad282d6 Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Thu, 28 Jun 2018 16:46:46 +0800 Subject: [PATCH 5/8] add loadSubpackage api (#2914) * add loadSubpackage api * refine code * refine code --- cocos2d/core/load-pipeline/downloader.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/cocos2d/core/load-pipeline/downloader.js b/cocos2d/core/load-pipeline/downloader.js index 9a129f42ae..85c8ba2090 100644 --- a/cocos2d/core/load-pipeline/downloader.js +++ b/cocos2d/core/load-pipeline/downloader.js @@ -282,6 +282,8 @@ var Downloader = function (extMap) { this._curConcurrent = 0; this._loadQueue = []; + this._subpackages = {}; + this.extMap = JS.mixin(extMap, defaultMap); }; Downloader.ID = ID; @@ -345,4 +347,24 @@ Downloader.prototype.handle = function (item, callback) { } }; +/** + * !#en + * Load subpackage with name. + * !#zh + * 通过子包名加载子包代码。 + * @method loadSubpackage + * @param {String} name - Subpackage name + * @param {Function} [completeCallback] - Callback invoked when subpackage loaded + * @param {Error} completeCallback.error - error information + */ +Downloader.prototype.loadSubpackage = function (name, completeCallback) { + let pac = this._subpackages[name]; + if (pac) { + downloadScript({url: pac.path}, completeCallback); + } + else if (completeCallback) { + completeCallback(new Error(`Can't find subpackage ${name}`)); + } +}; + Pipeline.Downloader = module.exports = Downloader; From 85d5ad06830e9d571ad7be6c67a75919decbe35a Mon Sep 17 00:00:00 2001 From: knox Date: Thu, 28 Jun 2018 18:13:42 +0800 Subject: [PATCH 6/8] fix fullScreen and videoplay bug for wxgame --- cocos2d/core/platform/CCScreen.js | 4 ++-- cocos2d/core/videoplayer/CCSGVideoPlayer.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos2d/core/platform/CCScreen.js b/cocos2d/core/platform/CCScreen.js index 8af9cc3a92..0f769ae14a 100644 --- a/cocos2d/core/platform/CCScreen.js +++ b/cocos2d/core/platform/CCScreen.js @@ -83,7 +83,7 @@ cc.screen = /** @lends cc.screen# */{ var i, l, val, map = this._fnMap, valL; for (i = 0, l = map.length; i < l; i++) { val = map[i]; - if (val && val[1] in document) { + if (val && (typeof document[val[1]] !== 'undefined')) { for (i = 0, valL = val.length; i < valL; i++) { this._fn[map[0][i]] = val[i]; } @@ -101,7 +101,7 @@ cc.screen = /** @lends cc.screen# */{ * @returns {Boolean} */ fullScreen: function () { - if(!this._supportsFullScreen) return false; + if(!this._supportsFullScreen) return false; else if( document[this._fn.fullscreenElement] === undefined || document[this._fn.fullscreenElement] === null ) return false; else diff --git a/cocos2d/core/videoplayer/CCSGVideoPlayer.js b/cocos2d/core/videoplayer/CCSGVideoPlayer.js index 7c5156b1ad..a302909719 100644 --- a/cocos2d/core/videoplayer/CCSGVideoPlayer.js +++ b/cocos2d/core/videoplayer/CCSGVideoPlayer.js @@ -78,11 +78,11 @@ _ccsg.VideoPlayer = _ccsg.Node.extend(/** @lends _ccsg.VideoPlayer# */{ }, duration: function () { - return this._renderCmd.duration(); + return this._renderCmd.duration() || -1; }, currentTime: function() { - return this._renderCmd.currentTime(); + return this._renderCmd.currentTime() || -1; }, createDomElementIfNeeded: function () { @@ -314,7 +314,7 @@ _ccsg.VideoPlayer.EventType = { var node = this._node; - if (this._url == path) { + if (this._url === path) { return; } @@ -331,7 +331,7 @@ _ccsg.VideoPlayer.EventType = { video = this._video; var cb = function(){ - if(this._loaded == true) + if(this._loaded) return; this._loaded = true; node.setContentSize(node._contentSize.width, node._contentSize.height); From 1d30cf8736a8ab56dbff1a048989b0eb0a80c1af Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Fri, 29 Jun 2018 10:21:07 +0800 Subject: [PATCH 7/8] fix merge issue (#2923) --- cocos2d/core/label/CCSGLabel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos2d/core/label/CCSGLabel.js b/cocos2d/core/label/CCSGLabel.js index 2546e92e79..c1a65637ae 100644 --- a/cocos2d/core/label/CCSGLabel.js +++ b/cocos2d/core/label/CCSGLabel.js @@ -146,7 +146,7 @@ _ccsg.Label = _ccsg.Node.extend({ onExit: function () { this._super(); - this._renderCmd._texture.releaseTexture(); + this._renderCmd._texture._releaseTexture(); this._notifyLabelSkinDirty(); }, From 48496e6975aff74b37aae4f7e1330932139692dc Mon Sep 17 00:00:00 2001 From: yinkaile <501251991@qq.com> Date: Fri, 29 Jun 2018 12:34:47 +0800 Subject: [PATCH 8/8] refine loadSubpackage (#2924) --- cocos2d/core/load-pipeline/downloader.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/load-pipeline/downloader.js b/cocos2d/core/load-pipeline/downloader.js index 85c8ba2090..05ee5188c4 100644 --- a/cocos2d/core/load-pipeline/downloader.js +++ b/cocos2d/core/load-pipeline/downloader.js @@ -360,7 +360,17 @@ Downloader.prototype.handle = function (item, callback) { Downloader.prototype.loadSubpackage = function (name, completeCallback) { let pac = this._subpackages[name]; if (pac) { - downloadScript({url: pac.path}, completeCallback); + if (pac.loaded) { + if (completeCallback) completeCallback(); + } + else { + downloadScript({url: pac.path}, function (err) { + if (!err) { + pac.loaded = true; + } + if (completeCallback) completeCallback(err); + }); + } } else if (completeCallback) { completeCallback(new Error(`Can't find subpackage ${name}`));