From 8a244d64b2daae5f9d8644a13786952b71d2e69a Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Wed, 24 Aug 2016 20:47:19 +0800 Subject: [PATCH] minor tweaks --- cocos2d/core/CCNode.js | 7 +- .../core/load-pipeline/auto-release-utils.js | 2 +- cocos2d/core/platform/instantiate.js | 2 +- cocos2d/core/platform/utils.js | 17 ++-- cocos2d/deprecated.js | 1 - test/qunit/unit/test-prefab-sync.js | 89 ------------------- 6 files changed, 17 insertions(+), 101 deletions(-) diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index cd892d31ec..a98cf4d96f 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -792,13 +792,14 @@ var Node = cc.Class({ return; } } - if (ctor._requireComponent) { + var ReqComp = ctor._requireComponent; + if (ReqComp && !this.getComponent(ReqComp)) { if (index === this._components.length) { // If comp should be last component, increase the index because required component added ++index; } - var depend = this.addComponent(ctor._requireComponent); - if (!depend) { + var depended = this.addComponent(ReqComp); + if (!depended) { // depend conflicts return null; } diff --git a/cocos2d/core/load-pipeline/auto-release-utils.js b/cocos2d/core/load-pipeline/auto-release-utils.js index 3a8164aad3..5e6eb4f685 100644 --- a/cocos2d/core/load-pipeline/auto-release-utils.js +++ b/cocos2d/core/load-pipeline/auto-release-utils.js @@ -20,7 +20,7 @@ function release (loader, key, nextSceneAssets) { var item = loader.getItem(key); if (item) { var removed = loader.removeItem(key); - console.log('auto release: ' + key); + //console.log('auto release: ' + key); // TODO: Audio var asset = item.content; if (asset instanceof cc.Texture2D) { diff --git a/cocos2d/core/platform/instantiate.js b/cocos2d/core/platform/instantiate.js index 90cda88410..9feb76de04 100644 --- a/cocos2d/core/platform/instantiate.js +++ b/cocos2d/core/platform/instantiate.js @@ -111,7 +111,7 @@ function doInstantiate (obj, parent) { cc.error('Can not instantiate array'); return null; } - if (_isDomNode && _isDomNode(obj)) { + if (!CC_JSB && _isDomNode && _isDomNode(obj)) { cc.error('Can not instantiate DOM element'); return null; } diff --git a/cocos2d/core/platform/utils.js b/cocos2d/core/platform/utils.js index a1ff8bda00..b38154bf89 100644 --- a/cocos2d/core/platform/utils.js +++ b/cocos2d/core/platform/utils.js @@ -24,12 +24,17 @@ ****************************************************************************/ module.exports = { - isDomNode: typeof window === 'object' && function (obj) { - return ( - typeof Node === "object" ? obj instanceof Node : - obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string" - ); - }, + isDomNode: typeof window === 'object' && (typeof Node === 'function' ? + function (obj) { + return obj instanceof Node; + } : + function (obj) { + return obj && + typeof obj === 'object' && + typeof obj.nodeType === 'number' && + typeof obj.nodeName === 'string'; + } + ), callInNextTick: CC_EDITOR ? function (callback, p1, p2) { diff --git a/cocos2d/deprecated.js b/cocos2d/deprecated.js index c36d786f4f..1bfb323bae 100644 --- a/cocos2d/deprecated.js +++ b/cocos2d/deprecated.js @@ -378,7 +378,6 @@ if (CC_DEV && typeof eruda === 'undefined') { 'onEnterTransitionDidFinish', 'onExitTransitionDidStart', 'onExit', - 'getNumberOfRunningActions', 'scheduleUpdate', 'scheduleUpdateWithPriority', 'unscheduleUpdate', diff --git a/test/qunit/unit/test-prefab-sync.js b/test/qunit/unit/test-prefab-sync.js index c1b2eeeb96..ae2d8722fe 100644 --- a/test/qunit/unit/test-prefab-sync.js +++ b/test/qunit/unit/test-prefab-sync.js @@ -98,12 +98,6 @@ ok(prefabInfo.asset, 'asset should be saved'); strictEqual(prefabInfo.sync, true, 'sync should be saved'); strictEqual(prefabInfo.fileId, parent.uuid, 'fileId should be saved'); - - //ok(reloadedParent.children.length > 0, 'children should be saved'); - //var reloadedChild = reloadedParent.children[0]; - //strictEqual(reloadedChild.y, 0, 'child position should not saved'); - //notEqual(reloadedChild.name, child.name, 'child name should not saved'); - //strictEqual(reloadedChild.active, true, 'child active should not saved'); }); test('prefab info in exported scene if syncable', function () { @@ -173,87 +167,4 @@ strictEqual(syncedChild._sgNode.parent === reloadedParent._sgNode, true, 'parent of child _sgNode should be synced'); }); - // - //test('re-instantiate an instantiated node', function () { - // var first = cc.instantiate(prefab); - // var second = cc.instantiate(first); - // var secondInfo = second._prefab; - // - // ok(second, "new node should be created"); - // ok(secondInfo, "new node should preserve the prefab info"); - // ok(secondInfo !== first._prefab, "prefab info should not the same"); - // ok(secondInfo.asset === prefab, "should reference to origin prefab asset in prefab info"); - // ok(secondInfo.root === second, "check root"); - // ok(secondInfo.fileId === first._prefab.fileId, "check fileId"); - // - // notEqual(first.uuid, second.uuid, 'The id of instances should be different'); - //}); - // - //test('apply node', function () { - // var newNode = cc.instantiate(prefab); - // var newPrefab = _Scene.PrefabUtils.createAppliedPrefab(newNode); - // strictEqual(newPrefab.data._prefab.fileId, prefab.data._prefab.fileId, "fileId should not changed during apply"); - //}); - // - //asyncTest('revert prefab', function () { - // // stub - // cc.loader.insertPipe({ - // id : 'Prefab_Provider', - // async : false, - // handle : function (item) { - // var url = item.id; - // if (url === UUID) { - // item.states['Downloader'] = cc.Pipeline.ItemState.COMPLETE; - // return JSON.stringify(prefabJson); - // } - // else { - // return; - // } - // } - // }, 0); - // - // var testNode = cc.instantiate(prefab); - // var testChild = testNode.children[0]; - // - // testNode.scale = 0; - // testNode.removeComponent(TestScript); - // testNode.children[1].parent = null; - // testChild.scale = cc.Vec2.ZERO; - // testChild.addComponent(TestScript); - // - // var newNode = new cc.Node(); - // newNode.parent = testChild; - // - // var newNode2 = new cc.Node(); - // newNode2.parent = testNode; - // newNode2.setSiblingIndex(0); - // - // _Scene.PrefabUtils.revertPrefab(testNode, function () { - // ok(testNode.getScaleX() === 123 && testNode.getScaleY() === 432, 'Revert property of the parent node'); - // ok(testNode.getComponent(TestScript).constructor === TestScript, 'Restore removed component'); - // var c = testNode.children[0]; - // ok(c.getScaleX() === 22 && c.getScaleY() === 11, 'Revert child node'); - // ok(testChild.getComponent(TestScript) == null, 'Remove added component'); - // - // ok(testNode.getComponent(TestScript).target === testChild, 'Should redirect reference to scene node'); - // - // strictEqual(testChild.children.length, 0, 'Should remove new node'); - // - // strictEqual(testNode.childrenCount, 2, 'Should create removed node'); - // var created = testNode.children[1]; - // ok(created._sgNode, 'Checking created node'); - // - // var comp = created.getComponent(MyComponent); - // comp.resetExpect(CallbackTester.OnLoad, 'call onLoad while attaching to node'); - // comp.pushExpect(CallbackTester.OnEnable, 'then call onEnable if node active'); - // - // cc.director.getScene().addChild(testNode); - // - // comp.stopTest(); - // - // strictEqual(newNode2.isValid, false, 'should remove new node which is not the last sibling'); - // - // start(); - // }); - //}); })();