mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 15:52:40 +08:00
Merge pull request #604 from jareguo/master
support the live reloading of undo history
This commit is contained in:
@@ -29,8 +29,15 @@ require('../platform/deserialize');
|
||||
// temp deserialize info
|
||||
var _tdInfo = new cc.deserialize.Details();
|
||||
|
||||
var SCENE_ID = 'cc.Scene';
|
||||
var PREFAB_ID = 'cc.Prefab';
|
||||
function isSceneObj (json) {
|
||||
var SCENE_ID = 'cc.Scene';
|
||||
var PREFAB_ID = 'cc.Prefab';
|
||||
return json && (
|
||||
(json[0] && json[0].__type__ === SCENE_ID) ||
|
||||
(json[1] && json[1].__type__ === SCENE_ID) ||
|
||||
(json[0] && json[0].__type__ === PREFAB_ID)
|
||||
);
|
||||
}
|
||||
|
||||
function loadDepends (pipeline, item, asset, tdInfo, callback) {
|
||||
var uuid = item.id,
|
||||
@@ -127,12 +134,7 @@ function loadUuid (item, callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
var isInScene = json && (
|
||||
(json[0] && json[0].__type__ === SCENE_ID) ||
|
||||
(json[1] && json[1].__type__ === SCENE_ID) ||
|
||||
(json[0] && json[0].__type__ === PREFAB_ID)
|
||||
);
|
||||
var classFinder = isInScene ? cc._MissingScript.safeFindClass : function (id) {
|
||||
var classFinder = isSceneObj(json) ? cc._MissingScript.safeFindClass : function (id) {
|
||||
var cls = JS._getClassById(id);
|
||||
if (cls) {
|
||||
return cls;
|
||||
@@ -158,4 +160,5 @@ function loadUuid (item, callback) {
|
||||
loadDepends(this.pipeline, item, asset, tdInfo, callback);
|
||||
}
|
||||
|
||||
module.exports = loadUuid;
|
||||
module.exports = loadUuid;
|
||||
loadUuid.isSceneObj = isSceneObj;
|
||||
|
||||
@@ -88,7 +88,7 @@ var AssetLibrary = {
|
||||
|
||||
_queryAssetInfoInEditor: function (uuid, callback) {
|
||||
if (CC_EDITOR) {
|
||||
Editor.Ipc.sendToMain( 'scene:query-asset-info-by-uuid', uuid, function (err,info) {
|
||||
Editor.Ipc.sendToMain('scene:query-asset-info-by-uuid', uuid, function (err, info) {
|
||||
if (info) {
|
||||
Editor.UuidCache.cache(info.url, uuid);
|
||||
var ctor = Editor.assets[info.type];
|
||||
|
||||
@@ -3,14 +3,14 @@ var JS = require('./js');
|
||||
// definitions for CCObject.Flags
|
||||
|
||||
var Destroyed = 1 << 0;
|
||||
var ToDestroy = 1 << 1;
|
||||
var DontSave = 1 << 2;
|
||||
var EditorOnly = 1 << 3;
|
||||
var Dirty = 1 << 4;
|
||||
var DontDestroy = 1 << 5;
|
||||
var Destroying = 1 << 6;
|
||||
var Activating = 1 << 7;
|
||||
//var RegisteredInEditor = 1 << 8;
|
||||
var RealDestroyed = 1 << 1;
|
||||
var ToDestroy = 1 << 2;
|
||||
var DontSave = 1 << 3;
|
||||
var EditorOnly = 1 << 4;
|
||||
var Dirty = 1 << 5;
|
||||
var DontDestroy = 1 << 6;
|
||||
var Destroying = 1 << 7;
|
||||
var Activating = 1 << 8;
|
||||
var HideInGame = 1 << 9;
|
||||
var HideInEditor = 1 << 10;
|
||||
|
||||
@@ -227,6 +227,12 @@ JS.get(prototype, 'isValid', function () {
|
||||
return !(this._objFlags & Destroyed);
|
||||
});
|
||||
|
||||
if (CC_DEV) {
|
||||
JS.get(prototype, 'isRealValid', function () {
|
||||
return !(this._objFlags & RealDestroyed);
|
||||
});
|
||||
}
|
||||
|
||||
var deferredDestroyTimer = null;
|
||||
|
||||
/**
|
||||
@@ -264,33 +270,27 @@ prototype.destroy = function () {
|
||||
};
|
||||
|
||||
if (CC_DEV) {
|
||||
/**
|
||||
/*
|
||||
* !#en
|
||||
* In fact, Object's "destroy" will not trigger the destruct operation in Firebal Editor.
|
||||
* The destruct operation will be executed by Undo system later.
|
||||
* !#zh
|
||||
* 事实上,对象的 “destroy” 不会在编辑器中触发析构操作,
|
||||
* 析构操作将在 Undo 系统中延后执行。
|
||||
* 析构操作将在 Undo 系统中**延后**执行。
|
||||
* @method realDestroyInEditor
|
||||
* @example
|
||||
* cc.log(obj.realDestroyInEditor());
|
||||
* @private
|
||||
*/
|
||||
prototype.realDestroyInEditor = function () {
|
||||
if (this._objFlags & Destroyed) {
|
||||
if ( !(this._objFlags & Destroyed) ) {
|
||||
cc.warn('object not yet destroyed');
|
||||
return;
|
||||
}
|
||||
if (this._objFlags & RealDestroyed) {
|
||||
cc.warn('object already destroyed');
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
if (this._objFlags & ToDestroy) {
|
||||
return false;
|
||||
}
|
||||
this._objFlags |= ToDestroy;
|
||||
objectsToDestroy.push(this);
|
||||
|
||||
if (deferredDestroyTimer === null && cc.engine && ! cc.engine._isUpdating && CC_EDITOR) {
|
||||
// auto destroy immediate in edit mode
|
||||
deferredDestroyTimer = setImmediate(deferredDestroy);
|
||||
}
|
||||
return true;
|
||||
this._destruct();
|
||||
this._objFlags |= RealDestroyed;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -303,9 +303,6 @@ if (CC_DEV) {
|
||||
* @private
|
||||
*/
|
||||
prototype._destruct = function () {
|
||||
if (CC_EDITOR && !(this._objFlags & Destroyed)) {
|
||||
return cc.error('object not yet destroyed');
|
||||
}
|
||||
// 所有可枚举到的属性,都会被清空
|
||||
for (var key in this) {
|
||||
if (this.hasOwnProperty(key)) {
|
||||
@@ -340,11 +337,9 @@ prototype._destroyImmediate = function () {
|
||||
}
|
||||
|
||||
if (!CC_EDITOR || cc.engine._isPlaying) {
|
||||
// 这里 _destruct 将由编辑器进行调用
|
||||
this._destruct();
|
||||
}
|
||||
|
||||
// mark destroyed
|
||||
this._objFlags |= Destroyed;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
var JS = cc.js;
|
||||
var SceneGraphHelper = require('./scene-graph-helper');
|
||||
var SgHelper = require('./scene-graph-helper');
|
||||
var Destroying = require('../platform/CCObject').Flags.Destroying;
|
||||
var DirtyFlags = require('./misc').DirtyFlags;
|
||||
var IdGenerater = require('../platform/id-generater');
|
||||
@@ -1911,7 +1911,10 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
}
|
||||
},
|
||||
|
||||
// The deserializer for sgNode which will be called before components onLoad
|
||||
/*
|
||||
* The deserializer for sgNode which will be called before components onLoad
|
||||
* @param {Boolean} [skipChildrenInEditor=false]
|
||||
*/
|
||||
_onBatchCreated: function () {
|
||||
this._updateDummySgNode();
|
||||
|
||||
@@ -1931,7 +1934,30 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
}
|
||||
},
|
||||
|
||||
_removeSgNode: SceneGraphHelper.removeSgNode,
|
||||
onRestore: CC_EDITOR && function () {
|
||||
this._updateDummySgNode();
|
||||
|
||||
var sgParent = this._parent && this._parent._sgNode;
|
||||
if (this._sgNode._parent !== sgParent) {
|
||||
if (this._sgNode._parent) {
|
||||
this._sgNode.removeFromParent();
|
||||
}
|
||||
if (sgParent) {
|
||||
sgParent.addChild(this._sgNode);
|
||||
}
|
||||
}
|
||||
|
||||
if (this._activeInHierarchy) {
|
||||
cc.director.getActionManager().resumeTarget(this);
|
||||
cc.eventManager.resumeTarget(this);
|
||||
}
|
||||
else {
|
||||
cc.director.getActionManager().pauseTarget(this);
|
||||
cc.eventManager.pauseTarget(this);
|
||||
}
|
||||
},
|
||||
|
||||
_removeSgNode: SgHelper.removeSgNode,
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -61,9 +61,9 @@ var Color = (function () {
|
||||
a = r.a;
|
||||
r = r.r;
|
||||
}
|
||||
this.r = typeof r === 'number' ? r : 0;
|
||||
this.g = typeof g === 'number' ? g : 0;
|
||||
this.b = typeof b === 'number' ? b : 0;
|
||||
this.r = r || 0;
|
||||
this.g = g || 0;
|
||||
this.b = b || 0;
|
||||
this.a = typeof a === 'number' ? a : 255;
|
||||
}
|
||||
JS.extend(Color, ValueType);
|
||||
|
||||
@@ -53,10 +53,10 @@ function Rect (x, y, w, h) {
|
||||
h = x.height;
|
||||
x = x.x;
|
||||
}
|
||||
this.x = typeof x === 'number' ? x : 0.0;
|
||||
this.y = typeof y === 'number' ? y : 0.0;
|
||||
this.width = typeof w === 'number' ? w : 0.0;
|
||||
this.height = typeof h === 'number' ? h : 0.0;
|
||||
this.x = x || 0;
|
||||
this.y = y || 0;
|
||||
this.width = w || 0;
|
||||
this.height = h || 0;
|
||||
}
|
||||
JS.extend(Rect, ValueType);
|
||||
require('../platform/CCClass').fastDefine('cc.Rect', Rect, ['x', 'y', 'width', 'height']);
|
||||
|
||||
@@ -52,8 +52,8 @@ function Size (width, height) {
|
||||
height = width.height;
|
||||
width = width.width;
|
||||
}
|
||||
this.width = typeof width === 'number' ? width : 0;
|
||||
this.height = typeof height === 'number' ? height : 0;
|
||||
this.width = width || 0;
|
||||
this.height = height || 0;
|
||||
}
|
||||
JS.extend(Size, ValueType);
|
||||
require('../platform/CCClass').fastDefine('cc.Size', Size, ['width', 'height']);
|
||||
|
||||
@@ -52,8 +52,8 @@ function Vec2 (x, y) {
|
||||
y = x.y;
|
||||
x = x.x;
|
||||
}
|
||||
this.x = (typeof x === 'number' ? x : 0.0);
|
||||
this.y = (typeof y === 'number' ? y : 0.0);
|
||||
this.x = x || 0;
|
||||
this.y = y || 0;
|
||||
}
|
||||
JS.extend(Vec2, ValueType);
|
||||
FireClass.fastDefine('cc.Vec2', Vec2, ['x', 'y']);
|
||||
|
||||
@@ -4,7 +4,7 @@ if (typeof CustomEvent === 'undefined') {
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof Set == 'undefined') {
|
||||
if (typeof Set === 'undefined') {
|
||||
// very simple polyfill
|
||||
Set = function () {
|
||||
this.values = [];
|
||||
@@ -17,6 +17,17 @@ if (typeof Set == 'undefined') {
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof setImmediate === 'undefined') {
|
||||
window.setImmediate = function (func) {
|
||||
'use strict';
|
||||
console.assert(arguments.length <= 1, 'not support params');
|
||||
return setTimeout(func, 0);
|
||||
};
|
||||
window.clearImmediate = function (immediateID) {
|
||||
clearTimeout(immediateID);
|
||||
};
|
||||
}
|
||||
|
||||
// http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind.html
|
||||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function (oThis) {
|
||||
|
||||
@@ -79,6 +79,29 @@ test('deferred destroy', function () {
|
||||
strictEqual(obj2.isValid, false, 'deleted at the end of frame 2');
|
||||
});
|
||||
|
||||
test('realDestroyInEditor', function () {
|
||||
var isEditor = CC_EDITOR;
|
||||
var isUpdating = cc.engine._isUpdating;
|
||||
cc.engine._isUpdating = false;
|
||||
CC_EDITOR = true;
|
||||
|
||||
var obj = new CCObject();
|
||||
obj.name = 'wocou';
|
||||
obj.destroy();
|
||||
CCObject._deferredDestroy();
|
||||
|
||||
strictEqual(obj.name, 'wocou', 'should not destroyed really');
|
||||
strictEqual(obj.isRealValid, true, 'isRealValid should be true');
|
||||
|
||||
obj.realDestroyInEditor();
|
||||
|
||||
strictEqual(obj.name, '', 'should be destroyed really');
|
||||
strictEqual(obj.isRealValid, false, 'isRealValid should be false');
|
||||
|
||||
CC_EDITOR = isEditor;
|
||||
cc.engine._isUpdating = isUpdating;
|
||||
});
|
||||
|
||||
test('multiply deferred destroy', function () {
|
||||
var obj1 = new CCObject();
|
||||
var obj2 = new CCObject();
|
||||
|
||||
Reference in New Issue
Block a user