mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-09-06 15:48:37 +08:00
* use getClassById instead of _getClassById * use getClassId instead of _getClassId * public cc.js.getClassId api * allow className already exists, new one will replace old classObject * create component use cid * allow className exist when registing * custom script className allow duplicated * revert some comments * preserve api and deprecate _getClassById and _getClassId * revert some comments * revert comment * Update cocos/core/utils/js-typed.ts Co-authored-by: PP <[email protected]> Co-authored-by: PP <[email protected]>
56 lines
1.6 KiB
JavaScript
56 lines
1.6 KiB
JavaScript
if (TestEditorExtends) {
|
|
|
|
largeModule('Serialize');
|
|
|
|
test('deserialize missing script', function () {
|
|
|
|
var MissingScript = cc.Class({
|
|
name: 'MissingScript',
|
|
properties: {
|
|
_$erialized: null
|
|
},
|
|
statics: {
|
|
safeFindClass: function (id) {
|
|
return cc.js.getClassById(id) || MissingScript;
|
|
}
|
|
}
|
|
});
|
|
|
|
var ToMiss = cc.Class({
|
|
name: 'ToMiss',
|
|
properties: {
|
|
ref: null
|
|
}
|
|
});
|
|
|
|
var obj = new ToMiss();
|
|
obj.ref = new cc.Object();
|
|
|
|
var lastData = EditorExtends.serialize(obj);
|
|
delete obj.__id__;
|
|
delete obj.ref.__id__;
|
|
cc.js.unregisterClass(ToMiss);
|
|
|
|
// deserialize
|
|
|
|
var missed = cc.deserialize(lastData, null, {classFinder: MissingScript.safeFindClass});
|
|
|
|
var expectBackup = {
|
|
"__type__": "ToMiss",
|
|
"ref": obj.ref,
|
|
};
|
|
deepEqual(missed._$erialized, expectBackup, 'can deserialize missing script');
|
|
|
|
// serialize
|
|
|
|
reSerialized = EditorExtends.serialize(missed, {stringify: false});
|
|
delete obj.ref.__id__;
|
|
deepEqual(reSerialized, JSON.parse(lastData), 'can serialize missing script as its original data');
|
|
|
|
//// re deserialize after fixed, no need to test ;)
|
|
//cc.setClassName('ToMiss', ToMiss);
|
|
//var recovered = cc.deserialize(reSerialized);
|
|
//deepEqual(recovered, obj, 'can deserialize correctly after script fixed');
|
|
//cc.unregisterClass(ToMiss);
|
|
});
|
|
} |