mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
fix dragonBones parseDragonBonesData bug in jsb (#2892)
* fix dragonBones parseDragonBonesData bug in jsb * refine code
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user