mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
Merge pull request #344 from jareguo/master
Updating api about engine-extends
This commit is contained in:
@@ -155,7 +155,7 @@ var _callLateUpdate = CC_EDITOR ? function (event) {
|
||||
// Yes, the id might have a conflict problem once every 365 days
|
||||
// if the game runs at 60 FPS and each frame 4760273 counts of new HashObject's id are requested.
|
||||
var CompId = 0;
|
||||
var IdPrefix = CC_DEV && ('Comp' + Editor.NonUuidMark);
|
||||
var IdPrefix = CC_DEV && ('Comp' + Editor.UuidUtils.NonUuidMark);
|
||||
var getNewId = CC_DEV && function () {
|
||||
return IdPrefix + (++CompId);
|
||||
};
|
||||
@@ -175,8 +175,8 @@ var Component = cc.Class({
|
||||
extends: cc.Object,
|
||||
|
||||
ctor: function () {
|
||||
if (CC_EDITOR) {
|
||||
Editor._AssetsWatcher.initComponent(this);
|
||||
if (CC_EDITOR && !CC_TEST) {
|
||||
_Scene.AssetsWatcher.initComponent(this);
|
||||
}
|
||||
|
||||
// dont reset _id when destroyed
|
||||
@@ -247,8 +247,8 @@ var Component = cc.Class({
|
||||
get: function () {},
|
||||
set: function (value) {
|
||||
if (this.__scriptUuid !== value) {
|
||||
if (value && Editor.isUuid(value._uuid)) {
|
||||
var classId = Editor.compressUuid(value._uuid);
|
||||
if (value && Editor.UuidUtils.isUuid(value._uuid)) {
|
||||
var classId = Editor.UuidUtils.compressUuid(value._uuid);
|
||||
var NewComp = cc.js._getClassById(classId);
|
||||
if (cc.isChildClassOf(NewComp, cc.Component)) {
|
||||
cc.warn('Sorry, replacing component script is not yet implemented.');
|
||||
@@ -564,7 +564,7 @@ var Component = cc.Class({
|
||||
callOnLostFocusInTryCatch(this);
|
||||
}
|
||||
}
|
||||
Editor._AssetsWatcher.start(this);
|
||||
_Scene.AssetsWatcher.start(this);
|
||||
}
|
||||
|
||||
if (this._enabled) {
|
||||
@@ -604,7 +604,7 @@ var Component = cc.Class({
|
||||
|
||||
// onDestroy
|
||||
if (CC_EDITOR) {
|
||||
Editor._AssetsWatcher.stop(this);
|
||||
_Scene.AssetsWatcher.stop(this);
|
||||
if (cc.engine._isPlaying || this.constructor._executeInEditMode) {
|
||||
if (this.onDestroy) {
|
||||
callOnDestroyInTryCatch(this);
|
||||
|
||||
@@ -120,7 +120,7 @@ var AssetLibrary = {
|
||||
if (CC_EDITOR) {
|
||||
Editor.sendRequestToCore( 'scene:query-asset-info-by-uuid', uuid, function (info) {
|
||||
if (info) {
|
||||
Editor.onRawAssetUsed(info.url, uuid);
|
||||
Editor.UuidCache.cache(info.url, uuid);
|
||||
var ctor = Editor.assets[info.type];
|
||||
if (ctor) {
|
||||
var isRawAsset = !cc.isChildClassOf(ctor, Asset);
|
||||
|
||||
@@ -417,7 +417,7 @@ function define (className, baseClasses, mixins, constructor, options) {
|
||||
JS._setClassId(uuid, cls);
|
||||
if (CC_EDITOR) {
|
||||
cc.Component._addMenuItem(cls, 'i18n:MAIN_MENU.component.scripts/' + className, -1);
|
||||
cls.prototype.__scriptUuid = Editor.decompressUuid(uuid);
|
||||
cls.prototype.__scriptUuid = Editor.UuidUtils.decompressUuid(uuid);
|
||||
}
|
||||
}
|
||||
frame.beh = cls;
|
||||
|
||||
@@ -77,10 +77,13 @@ if (CC_DEV) {
|
||||
if (CC_TEST) {
|
||||
// editor mocks using in unit tests
|
||||
if (typeof Editor === 'undefined') {
|
||||
Editor = {};
|
||||
Editor = {
|
||||
UuidUtils: {
|
||||
NonUuidMark: '.',
|
||||
uuid: function () {
|
||||
return '' + ((new Date()).getTime() + Math.random());
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Editor.uuid = function () {
|
||||
return '' + ((new Date()).getTime() + Math.random());
|
||||
};
|
||||
Editor.NonUuidMark = '.';
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ cc.SpriteFrame = cc.Class(/** @lends cc.SpriteFrame# */{
|
||||
uuid = url._uuid;
|
||||
}
|
||||
else {
|
||||
uuid = Editor.urlToUuid(url);
|
||||
uuid = Editor.UuidCache.urlToUuid(url);
|
||||
}
|
||||
}
|
||||
var capInsets = undefined;
|
||||
|
||||
@@ -178,7 +178,7 @@ var BaseNode = cc.Class(/** @lends cc.Node# */{
|
||||
*/
|
||||
uuid: {
|
||||
get: function () {
|
||||
return this._id || (this._id = window.Editor ? Editor.uuid() : '');
|
||||
return this._id || (this._id = window.Editor ? Editor.UuidUtils.uuid() : '');
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ paths = {
|
||||
test: {
|
||||
src: 'test/qunit/unit/**/*.js',
|
||||
runner: 'test/qunit/lib/qunit-runner.html',
|
||||
jsEntryEditorExtends: '../editor/share/engine-extends/index.js', // only available in editor
|
||||
jsEntryEditorExtends: '../editor/test-utils/engine-extends-entry.js', // only available in editor
|
||||
dest: 'bin/cocos2d-js-for-test.js',
|
||||
destEditorExtends: 'bin/cocos2d-js-extends-for-test.js'
|
||||
},
|
||||
|
||||
@@ -61,4 +61,40 @@ if (isPhantomJS) {
|
||||
// polyfill
|
||||
var video = document.createElement("video");
|
||||
video.constructor.prototype.canPlayType = function () { return ''; };
|
||||
|
||||
(function () {
|
||||
var log = console.log;
|
||||
console.log = function () {
|
||||
var str = arguments[0];
|
||||
str = '' + str;
|
||||
if (str && str.length > 110) {
|
||||
log.call(console, "(Can not output this too long log)");
|
||||
}
|
||||
else {
|
||||
log.apply(console, arguments);
|
||||
}
|
||||
}
|
||||
var warn = console.warn;
|
||||
console.warn = function () {
|
||||
var str = arguments[0];
|
||||
str = '' + str;
|
||||
if (str && str.length > 110) {
|
||||
warn.call(console, "(Can not output this too long warn)");
|
||||
}
|
||||
else {
|
||||
warn.apply(console, arguments);
|
||||
}
|
||||
}
|
||||
var error = console.error;
|
||||
console.error = function () {
|
||||
var str = arguments[0];
|
||||
str = '' + str;
|
||||
if (str && str.length > 110) {
|
||||
error.call(console, "(Can not output this too long error)");
|
||||
}
|
||||
else {
|
||||
error.apply(console, arguments);
|
||||
}
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ Editor.log = cc.log;
|
||||
Editor.warn = cc.warn;
|
||||
Editor.error = cc.error;
|
||||
Editor.info = cc.info;
|
||||
Editor.UuidCache = {};
|
||||
|
||||
var assetDir = '../test/qunit/assets';
|
||||
|
||||
|
||||
@@ -385,8 +385,8 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
var restore = Editor.urlToUuid;
|
||||
Editor.urlToUuid = function (url) {
|
||||
var restore = Editor.UuidCache.urlToUuid;
|
||||
Editor.UuidCache.urlToUuid = function (url) {
|
||||
return {
|
||||
foo: '01',
|
||||
bar: '02'
|
||||
@@ -412,7 +412,7 @@
|
||||
};
|
||||
deepEqual(actual, expected, 'could be serialized');
|
||||
|
||||
Editor.urlToUuid = restore;
|
||||
Editor.UuidCache.urlToUuid = restore;
|
||||
cc.js.unregisterClass(Data);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user