From 995a18eeb20370e5dad16738cd4efa5c26ff6bcf Mon Sep 17 00:00:00 2001 From: Jare Guo Date: Mon, 22 Feb 2016 13:56:33 +0800 Subject: [PATCH] disallow to modify scene hierarchy when editing animation --- cocos2d/core/utils/base-node.js | 5 +++++ test/qunit/unit/_init.js | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cocos2d/core/utils/base-node.js b/cocos2d/core/utils/base-node.js index 55777ae36b..006bf8fcad 100644 --- a/cocos2d/core/utils/base-node.js +++ b/cocos2d/core/utils/base-node.js @@ -124,6 +124,11 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{ if (this._parent === value) { return; } + if (CC_EDITOR && !cc.engine.isPlaying) { + if (_Scene.DetectConflict.beforeAddChild(this)) { + return; + } + } var node = this._sgNode; if (node.parent) { node.parent.removeChild(node, false); diff --git a/test/qunit/unit/_init.js b/test/qunit/unit/_init.js index f616ac39ae..8ef440b5ca 100644 --- a/test/qunit/unit/_init.js +++ b/test/qunit/unit/_init.js @@ -107,7 +107,7 @@ var TestScript = cc.Class({ } }); -// polyfills to test engine extends +// mocks to test engine extends cc.engine = new (cc.Class({ extends: cc.EventTarget, @@ -121,6 +121,20 @@ cc.engine = new (cc.Class({ } }))(); +(function () { + function beFalse () { + return false; + } + + window._Scene = window._Scene || {}; + _Scene.DetectConflict = { + beforeAddChild: beFalse, + afterAddChild: beFalse, + checkConflict_Layout: beFalse, + checkConflict_Widget: beFalse, + }; +})(); + Editor.log = cc.log; Editor.warn = cc.warn; Editor.error = cc.error;