bug fixes and sync remain codes

fuck
This commit is contained in:
Jare Guo
2020-09-14 21:44:31 +08:00
parent 6a2cdf7e66
commit 0b1fa249da
14 changed files with 145 additions and 152 deletions
+8
View File
@@ -1012,6 +1012,14 @@ Can not find script '%s'
Can not find class '%s'
### 5303
Failed to deserialize %s, missing _deserialize function.
### 5304
Unable to deserialize version %s data.
### 5400
'%s' is deprecated, use '%s' instead please.
+21 -19
View File
@@ -32,7 +32,7 @@ import {ccclass, override} from 'cc.decorator';
import { GFXDevice, GFXFeature } from '../gfx/device';
import { Asset } from './asset';
import { PixelFormat } from './asset-enum';
import { EDITOR, MINIGAME, ALIPAY, XIAOMI, BYTEDANCE, JSB } from 'internal:constants';
import { EDITOR, MINIGAME, ALIPAY, XIAOMI, BYTEDANCE, JSB, TEST } from 'internal:constants';
import { legacyCC } from '../global-exports';
import { warnID } from '../platform/debug';
@@ -245,26 +245,28 @@ export class ImageAsset extends Asset {
// SERIALIZATION
public _serialize () {
let targetExtensions = this._exportedExts;
if (!targetExtensions && this._native) {
targetExtensions = [this._native];
}
if (!targetExtensions) {
return '';
}
const extensionIndices: string[] = [];
for (const targetExtension of targetExtensions) {
const extensionFormat = targetExtension.split('@');
const i = ImageAsset.extnames.indexOf(extensionFormat[0]);
let exportedExtensionID = i < 0 ? targetExtension : `${i}`;
if (extensionFormat[1]) {
exportedExtensionID += '@' + extensionFormat[1];
if (EDITOR || TEST) {
let targetExtensions = this._exportedExts;
if (!targetExtensions && this._native) {
targetExtensions = [this._native];
}
extensionIndices.push(exportedExtensionID);
if (!targetExtensions) {
return '';
}
const extensionIndices: string[] = [];
for (const targetExtension of targetExtensions) {
const extensionFormat = targetExtension.split('@');
const i = ImageAsset.extnames.indexOf(extensionFormat[0]);
let exportedExtensionID = i < 0 ? targetExtension : `${i}`;
if (extensionFormat[1]) {
exportedExtensionID += '@' + extensionFormat[1];
}
extensionIndices.push(exportedExtensionID);
}
return { fmt: extensionIndices.join('_'), w: this.width, h: this.height };
}
return { fmt: extensionIndices.join('_'), w: this.width, h: this.height };
}
public _deserialize (data: any, handle: any) {
+16 -13
View File
@@ -28,6 +28,7 @@
* @category asset
*/
import { EDITOR, TEST } from "internal:constants";
import { ccclass, serializable, editable } from 'cc.decorator';
import * as js from '../utils/js';
import { Asset } from './asset';
@@ -106,21 +107,23 @@ export class SpriteAtlas extends Asset {
}
public _serialize (exporting?: any) {
const frames: string[] = [];
for (const key of Object.keys(this.spriteFrames)) {
const spriteFrame = this.spriteFrames[key];
let id = spriteFrame ? spriteFrame._uuid : '';
if (id && exporting) {
id = EditorExtends.UuidUtils.compressUuid(id, true);
if (EDITOR || TEST) {
const frames: string[] = [];
for (const key of Object.keys(this.spriteFrames)) {
const spriteFrame = this.spriteFrames[key];
let id = spriteFrame ? spriteFrame._uuid : '';
if (id && exporting) {
id = EditorExtends.UuidUtils.compressUuid(id, true);
}
frames.push(key);
frames.push(id);
}
frames.push(key);
frames.push(id);
}
return {
name: this._name,
spriteFrames: frames,
};
return {
name: this._name,
spriteFrames: frames,
};
}
}
public _deserialize (serializeData: any, handle: any){
+40 -38
View File
@@ -35,7 +35,7 @@ import { murmurhash2_32_gc } from '../utils/murmurhash2_gc';
import { Asset } from './asset';
import { RenderTexture } from './render-texture';
import { TextureBase } from './texture-base';
import { EDITOR } from 'internal:constants';
import { EDITOR, TEST } from 'internal:constants';
import { legacyCC } from '../global-exports';
import { ImageAsset, ImageSource } from './image-asset';
import { Texture2D } from './texture-2d';
@@ -861,47 +861,49 @@ export class SpriteFrame extends Asset {
// SERIALIZATION
public _serialize (exporting?: any): any {
const rect = this._rect;
const offset = this._offset;
const originalSize = this._originalSize;
let uuid = this._uuid;
let texture;
if (this._texture) {
texture = this._texture._uuid;
}
if (EDITOR || TEST) {
const rect = this._rect;
const offset = this._offset;
const originalSize = this._originalSize;
let uuid = this._uuid;
let texture;
if (this._texture) {
texture = this._texture._uuid;
}
if (uuid && exporting) {
uuid = EditorExtends.UuidUtils.compressUuid(uuid, true);
}
if (texture && exporting) {
texture = EditorExtends.UuidUtils.compressUuid(texture, true);
}
if (uuid && exporting) {
uuid = EditorExtends.UuidUtils.compressUuid(uuid, true);
}
if (texture && exporting) {
texture = EditorExtends.UuidUtils.compressUuid(texture, true);
}
let vertices;
if (this.vertices) {
vertices = {
triangles: this.vertices.triangles,
x: this.vertices.x,
y: this.vertices.y,
u: this.vertices.u,
v: this.vertices.v,
let vertices;
if (this.vertices) {
vertices = {
triangles: this.vertices.triangles,
x: this.vertices.x,
y: this.vertices.y,
u: this.vertices.u,
v: this.vertices.v,
};
}
const serialize = {
name: this._name,
atlas: exporting ? undefined : this._atlasUuid, // strip from json if exporting
rect,
offset,
originalSize,
rotated: this._rotated,
capInsets: this._capInsets,
vertices,
texture,
};
// 为 underfined 的数据则不在序列化文件里显示
return serialize;
}
const serialize = {
name: this._name,
atlas: exporting ? undefined : this._atlasUuid, // strip from json if exporting
rect,
offset,
originalSize,
rotated: this._rotated,
capInsets: this._capInsets,
vertices,
texture,
};
// 为 underfined 的数据则不在序列化文件里显示
return serialize;
}
public _deserialize (serializeData: any, handle: any) {
+15 -12
View File
@@ -28,6 +28,7 @@
* @category asset
*/
import { EDITOR, TEST } from "internal:constants";
import { ccclass, type } from 'cc.decorator';
import { GFXTextureType } from '../gfx/define';
import { PixelFormat } from './asset-enum';
@@ -225,18 +226,20 @@ export class Texture2D extends SimpleTexture {
}
public _serialize (exporting?: any): any {
return {
base: super._serialize(exporting),
mipmaps: this._mipmaps.map((mipmap) => {
if (!mipmap || !mipmap._uuid) {
return null;
}
if (exporting) {
return EditorExtends.UuidUtils.compressUuid(mipmap._uuid, true);
}
return mipmap._uuid;
}),
};
if (EDITOR || TEST) {
return {
base: super._serialize(exporting),
mipmaps: this._mipmaps.map((mipmap) => {
if (!mipmap || !mipmap._uuid) {
return null;
}
if (exporting) {
return EditorExtends.UuidUtils.compressUuid(mipmap._uuid, true);
}
return mipmap._uuid;
}),
};
}
}
public _deserialize (serializedData: any, handle: any) {
+6 -3
View File
@@ -29,6 +29,7 @@
*/
// @ts-check
import { EDITOR, TEST } from 'internal:constants';
import {ccclass, serializable} from 'cc.decorator';
import { GFXDevice } from '../gfx/device';
import { GFXTexture } from '../gfx/texture';
@@ -277,9 +278,11 @@ export class TextureBase extends Asset {
* @return
*/
public _serialize (exporting?: any): any {
return this._minFilter + ',' + this._magFilter + ',' +
this._wrapS + ',' + this._wrapT + ',' +
this._mipFilter + ',' + this._anisotropy;
if (EDITOR || TEST) {
return this._minFilter + ',' + this._magFilter + ',' +
this._wrapS + ',' + this._wrapT + ',' +
this._mipFilter + ',' + this._anisotropy;
}
}
/**
+21 -18
View File
@@ -27,6 +27,7 @@
* @category asset
*/
import { EDITOR, TEST } from "internal:constants";
import { ccclass, serializable } from 'cc.decorator';
import { GFXTextureFlagBit, GFXTextureType } from '../gfx/define';
import { ImageAsset } from './image-asset';
@@ -220,24 +221,26 @@ export class TextureCube extends SimpleTexture {
}
public _serialize (exporting?: any) {
return {
base: super._serialize(),
mipmaps: this._mipmaps.map((mipmap) => exporting ? {
front: EditorExtends.UuidUtils.compressUuid(mipmap.front._uuid, true),
back: EditorExtends.UuidUtils.compressUuid(mipmap.back._uuid, true),
left: EditorExtends.UuidUtils.compressUuid(mipmap.left._uuid, true),
right: EditorExtends.UuidUtils.compressUuid(mipmap.right._uuid, true),
top: EditorExtends.UuidUtils.compressUuid(mipmap.top._uuid, true),
bottom: EditorExtends.UuidUtils.compressUuid(mipmap.bottom._uuid, true),
} : {
front: mipmap.front._uuid,
back: mipmap.back._uuid,
left: mipmap.left._uuid,
right: mipmap.right._uuid,
top: mipmap.top._uuid,
bottom: mipmap.bottom._uuid,
}),
};
if (EDITOR || TEST) {
return {
base: super._serialize(),
mipmaps: this._mipmaps.map((mipmap) => exporting ? {
front: EditorExtends.UuidUtils.compressUuid(mipmap.front._uuid, true),
back: EditorExtends.UuidUtils.compressUuid(mipmap.back._uuid, true),
left: EditorExtends.UuidUtils.compressUuid(mipmap.left._uuid, true),
right: EditorExtends.UuidUtils.compressUuid(mipmap.right._uuid, true),
top: EditorExtends.UuidUtils.compressUuid(mipmap.top._uuid, true),
bottom: EditorExtends.UuidUtils.compressUuid(mipmap.bottom._uuid, true),
} : {
front: mipmap.front._uuid,
back: mipmap.back._uuid,
left: mipmap.left._uuid,
right: mipmap.right._uuid,
top: mipmap.top._uuid,
bottom: mipmap.bottom._uuid,
}),
};
}
}
public _deserialize (serializedData: ITextureCubeSerializeData, handle: any) {
+2 -29
View File
@@ -36,20 +36,6 @@ import { EDITOR } from 'internal:constants';
import { legacyCC } from '../global-exports';
import { warnID } from '../platform/debug';
/**
* @en
* A temp fallback to contain the original serialized data which can not be loaded.
* @zh
* 包含无法加载的原始序列化数据的临时回退。
*/
@ccclass('cc.MissingClass')
class MissingClass {
// the serialized data for original object
@serializable
@editorOnly
public _$erialized = null;
}
/**
* @en
* A temp fallback to contain the original component which can not be loaded.
@@ -74,25 +60,12 @@ export default class MissingScript extends Component {
* @param {string} id
* @return {function} constructor
*/
public static safeFindClass (id: string, data) {
public static safeFindClass (id: string) {
const cls = _getClassById(id);
if (cls) {
return cls;
}
if (id) {
legacyCC.deserialize.reportMissingClass(id);
return MissingScript.getMissingWrapper(id, data);
}
return null;
}
public static getMissingWrapper (id, data) {
if (data.node && (/^[0-9a-zA-Z+/]{23}$/.test(id) || BUILTIN_CLASSID_RE.test(id))) {
// is component
return MissingScript;
}
else {
return MissingClass;
}
legacyCC.deserialize.reportMissingClass(id);
}
@editable
+1 -1
View File
@@ -52,7 +52,7 @@ import { legacyCC } from '../global-exports';
const DELIMETER = attributeUtils.DELIMETER;
const BUILTIN_ENTRIES = ['name', 'extends', 'mixins', 'ctor', '__ctor__', 'properties', 'statics', 'editor', '__ES6__'];
const INVALID_STATICS_DEV = ['name', '__ctors__', '__props__', 'arguments', 'call', 'apply', 'caller', 'length', 'prototype'];
const INVALID_STATICS_DEV = ['name', '__ctors__', '__props__', '__values__', 'arguments', 'call', 'apply', 'caller', 'length', 'prototype'];
function pushUnique (array, item) {
if (array.indexOf(item) < 0) {
+4 -5
View File
@@ -28,7 +28,7 @@
* @hidden
*/
import { EDITOR, TEST, DEV, JSB, PREVIEW, SUPPORT_JIT } from 'internal:constants';
import { EDITOR, TEST, DEV, BUILD, JSB, PREVIEW, SUPPORT_JIT } from 'internal:constants';
import { legacyCC } from '../global-exports';
import { warnID } from '../platform/debug';
import * as js from '../utils/js';
@@ -402,7 +402,7 @@ class _Deserializer {
this.deserializedList = [];
this.deserializedData = null;
this._classFinder = classFinder;
if (DEV) {
if (!BUILD) {
this._target = target;
this._ignoreEditorOnly = ignoreEditorOnly;
}
@@ -461,7 +461,6 @@ class _Deserializer {
/*
* @param {Object} serialized - The obj to deserialize, must be non-nil
* @param {Boolean} _stillUseUrl
* @param {Object} [target=null] - editor only
* @param {Object} [owner] - debug only
* @param {String} [propName] - debug only
@@ -526,7 +525,7 @@ class _Deserializer {
}
catch (e) {
console.error('deserialize ' + klass.name + ' failed, ' + e.stack);
klass = MissingScript.getMissingWrapper(type, serialized);
klass = MissingScript;
legacyCC.deserialize.reportMissingClass(type);
deserializeByType();
}
@@ -715,7 +714,7 @@ _Deserializer.pool.get = function (result, target, classFinder, customEnv, ignor
cache.result = result;
cache.customEnv = customEnv;
cache._classFinder = classFinder;
if (DEV) {
if (!BUILD) {
cache._target = target;
cache._ignoreEditorOnly = ignoreEditorOnly;
}
+2 -4
View File
@@ -31,6 +31,7 @@
import { errorID } from "../platform/debug";
import { js } from "../utils/js";
import { Texture2D } from "../assets/texture-2d";
import { packCustomObjData } from '../data/deserialize';
export class JsonUnpacker {
public jsons = {};
@@ -76,10 +77,7 @@ export class TextureUnpacker {
retrieve (key) {
let content = this.contents[key];
if (content) {
return {
__type__: js._getClassId(Texture2D),
content: content
};
return packCustomObjData(js._getClassId(Texture2D), content);
}
else {
return null;
+1 -8
View File
@@ -53,7 +53,6 @@ function parseDepends (item, asset, tdInfo: Details, deferredLoadRawAssetsInRunt
let objList = tdInfo.uuidObjList;
let propList = tdInfo.uuidPropList;
// @ts-ignore
let stillUseUrl = tdInfo._stillUseUrl;
let depends;
let i, dependUuid;
// cache dependencies for auto release
@@ -81,7 +80,6 @@ function parseDepends (item, asset, tdInfo: Details, deferredLoadRawAssetsInRunt
deferredLoadRaw: true,
_owner: obj,
_ownerProp: prop,
_stillUseUrl: stillUseUrl[i]
});
}
}
@@ -97,7 +95,6 @@ function parseDepends (item, asset, tdInfo: Details, deferredLoadRawAssetsInRunt
uuid: dependUuid,
_owner: objList[i],
_ownerProp: propList[i],
_stillUseUrl: stillUseUrl[i]
};
}
@@ -143,10 +140,6 @@ function loadDepends (pipeline, item, asset, depends, callback) {
function loadCallback (item) {
let value = item.content;
// @ts-ignore
if (this._stillUseUrl) {
value = value ? value.nativeUrl : item.rawUrl;
}
// @ts-ignore
this._owner[this._ownerProp] = value;
if (item.uuid !== asset._uuid && dependKeys.indexOf(item.id) < 0) {
dependKeys.push(item.id);
@@ -265,7 +258,7 @@ export function loadUuid (item, callback) {
if (res) {
return res;
}
return legacyCC._MissingScript.getMissingWrapper(type, data);
return legacyCC._MissingScript;
};
classFinder.onDereferenced = MissingClass.classFinder.onDereferenced;
}
+2 -1
View File
@@ -269,7 +269,8 @@ export function formatStr (msg: string | any, ...subst: any[]) {
for (const arg of subst) {
const regExpToTest = typeof arg === 'number' ? REGEXP_NUM_OR_STR : REGEXP_STR;
if (regExpToTest.test(msg)) {
msg = msg.replace(regExpToTest, arg);
const notReplaceFunction = '' + arg;
msg = msg.replace(regExpToTest, notReplaceFunction);
}
else {
msg += ' ' + arg;
+6 -1
View File
@@ -320,8 +320,13 @@ async function _doBuild ({
if (doUglify) { // TODO: tree-shaking not clear!
rollupPlugins.push(rpTerser({
// see https://github.com/terser/terser#compress-options
compress: {
reduce_funcs: false // reduce_funcs not suitable for ammo.js
reduce_funcs: false, // reduce_funcs not suitable for ammo.js
keep_fargs: false,
unsafe_Function: true,
unsafe_math: true,
unsafe_methods: true,
},
mangle: doUglify,
keep_fnames: !doUglify,