mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-19 14:52:40 +08:00
+27
-1
@@ -531,6 +531,11 @@ Node's zIndex value can't be smaller than cc.macro.MIN_ZINDEX, setting to the mi
|
||||
|
||||
Private node's zIndex can't be set, it will keep cc.macro.MIN_ZINDEX as its value
|
||||
|
||||
### 1639
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
cc.Action is deprecated, please use cc.Tween instead
|
||||
|
||||
### 1700
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
@@ -1508,6 +1513,7 @@ set %s (value) {
|
||||
|
||||
### 3656
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
The default value of %s.%s must be an empty string.
|
||||
|
||||
### 3657
|
||||
@@ -1715,6 +1721,7 @@ already-playing
|
||||
|
||||
### 4000
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Sorry, the cc.Font has been modified from Raw Asset to Asset. Please load the font asset before using.
|
||||
|
||||
### 4001
|
||||
@@ -1914,6 +1921,7 @@ cc.LabelBMFont._parseImageFileName() : file could not be found
|
||||
|
||||
### 4920
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Sorry, you shouldn't use id as item identity any more, please use url or uuid instead, the current id is being set as url: (%s)
|
||||
|
||||
### 4921
|
||||
@@ -1958,6 +1966,7 @@ Load image ( %s ) failed
|
||||
|
||||
### 4931
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Download Uuid: can not find type of raw asset[ %s ]: %s
|
||||
|
||||
### 4932
|
||||
@@ -2060,22 +2069,27 @@ Class should be extended before assigning any prototype members.
|
||||
|
||||
### 5502
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Invalid url of %s.%s
|
||||
|
||||
### 5503
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
The 'url' attribute of '%s.%s' is undefined when loading script.
|
||||
|
||||
### 5504
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
The 'url' type of '%s.%s' must be child class of cc.RawAsset.
|
||||
|
||||
### 5505
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
The 'url' type of '%s.%s' must not be child class of cc.Asset, otherwise you should use 'type: %s' instead.
|
||||
|
||||
### 5506
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Can not specify 'type' attribute for '%s.%s', because its 'url' is already defined.
|
||||
|
||||
### 5507
|
||||
@@ -2088,6 +2102,7 @@ Invalid type of %s.%s
|
||||
|
||||
### 5509
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
The 'type' attribute of '%s.%s' must be child class of cc.Asset, otherwise you should use 'url: %s' instead
|
||||
|
||||
### 5510
|
||||
@@ -2398,6 +2413,10 @@ Polygon's point must greater than 2
|
||||
|
||||
Argument must be non-nil
|
||||
|
||||
### 6706
|
||||
|
||||
Priority can't be set in Canvas node
|
||||
|
||||
### 6800
|
||||
|
||||
Callback of event must be non-nil
|
||||
@@ -2432,18 +2451,22 @@ Can not instantiate DOM element
|
||||
|
||||
### 7000
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Failed to init asset's raw path.
|
||||
|
||||
### 7001
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Should not load '%s' from script dynamically, unless it is placed in the 'resources' folder.
|
||||
|
||||
### 7002
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Sorry can not load '%s' because it is not placed in the 'resources' folder.
|
||||
|
||||
### 7003
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Failed to init builtin asset's raw path.
|
||||
|
||||
### 7100
|
||||
@@ -2691,6 +2714,7 @@ Can not render dynamic created SkeletonData
|
||||
|
||||
### 7505
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Invalid type of atlasFile, atlas should be registered as raw asset.
|
||||
|
||||
### 7506
|
||||
@@ -2892,6 +2916,7 @@ Wrong type arguments, 'filePath' must be a String.
|
||||
|
||||
### 8401
|
||||
|
||||
<!-- DEPRECATED -->
|
||||
Since 1.10, `%s` accept %s instance directly, not a URL string. Please directly reference the %s object in your script, or load %s by loader first. Don't use %s's URL anymore.
|
||||
|
||||
### 9000
|
||||
@@ -2908,7 +2933,8 @@ texture size exceeds current device limits %d/%d
|
||||
|
||||
### 9200
|
||||
|
||||
Priority can't be set in Canvas node
|
||||
<!-- DEPRECATED -->
|
||||
cc.view.enableAntiAlias is deprecated, please use cc.Texture2D.setFilters instead
|
||||
|
||||
### 9300
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import { ccclass, serializable } from 'cc.decorator';
|
||||
import { property } from '../data/decorators/property';
|
||||
import { getUrlWithUuid } from '../asset-manager/helper';
|
||||
import { Eventify } from '../event';
|
||||
import { RawAsset } from './raw-asset';
|
||||
import { CCObject } from '../data/object';
|
||||
import { Node } from '../scene-graph';
|
||||
import { legacyCC } from '../global-exports';
|
||||
import { extname } from '../utils/path';
|
||||
@@ -57,14 +57,14 @@ import { extname } from '../utils/path';
|
||||
* - `Object._deserialize`<br/>
|
||||
*
|
||||
* @class Asset
|
||||
* @extends RawAsset
|
||||
* @extends CCObject
|
||||
*/
|
||||
@ccclass('cc.Asset')
|
||||
export class Asset extends Eventify(RawAsset) {
|
||||
export class Asset extends Eventify(CCObject) {
|
||||
|
||||
/**
|
||||
* @en Indicates whether its dependent raw assets can support deferred load if the owner scene (or prefab) is marked as `asyncLoadAssets`.
|
||||
* @zh 当场景或 Prefab 被标记为 `asyncLoadAssets`,禁止延迟加载该资源所依赖的其它 RawAsset。
|
||||
* @en Indicates whether its dependent native assets can support deferred load if the owner scene (or prefab) is marked as `asyncLoadAssets`.
|
||||
* @zh 当场景或 Prefab 被标记为 `asyncLoadAssets`,禁止延迟加载该资源所依赖的其它原始资源。
|
||||
* @default false
|
||||
*/
|
||||
public static preventDeferredLoadDependents = false;
|
||||
@@ -94,6 +94,8 @@ export class Asset extends Eventify(RawAsset) {
|
||||
*/
|
||||
public loaded = true;
|
||||
|
||||
public declare _uuid: string;
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Serializable url for native asset. For internal usage.
|
||||
@@ -155,6 +157,16 @@ export class Asset extends Eventify(RawAsset) {
|
||||
this._file = obj;
|
||||
}
|
||||
|
||||
constructor (...args: ConstructorParameters<typeof CCObject>) {
|
||||
super(...args);
|
||||
|
||||
Object.defineProperty(this, '_uuid', {
|
||||
value: '',
|
||||
writable: true,
|
||||
// enumerable is false by default, to avoid uuid being assigned to empty string during destroy
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Returns the string representation of the object.<br>
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
* @hidden
|
||||
*/
|
||||
import { legacyCC } from '../global-exports';
|
||||
export { RawAsset } from './raw-asset';
|
||||
export { Asset } from './asset';
|
||||
export { BufferAsset } from './buffer-asset';
|
||||
export { default as Prefab } from './prefab';
|
||||
|
||||
@@ -109,7 +109,7 @@ export default class Prefab extends Asset {
|
||||
public optimizationPolicy = OptimizationPolicy.AUTO;
|
||||
|
||||
/**
|
||||
* @en Indicates the raw assets of this prefab can be load after prefab loaded.
|
||||
* @en Indicates the native assets of this prefab can be load after prefab loaded.
|
||||
* @zh 指示该 Prefab 依赖的资源可否在 Prefab 加载后再延迟加载。
|
||||
* @default false
|
||||
*/
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
||||
Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @packageDocumentation
|
||||
* @hidden
|
||||
*/
|
||||
|
||||
import { ccclass } from 'cc.decorator';
|
||||
import { CCObject } from '../data/object';
|
||||
import { isChildClassOf } from '../utils/js';
|
||||
import { legacyCC } from '../global-exports';
|
||||
|
||||
/**
|
||||
* 原生资源的基类。内部使用。
|
||||
* @private
|
||||
*/
|
||||
@ccclass('cc.RawAsset')
|
||||
export class RawAsset extends CCObject {
|
||||
/**
|
||||
* 内部使用。
|
||||
*/
|
||||
public static isRawAssetType (ctor: Function) {
|
||||
return isChildClassOf(ctor, legacyCC.RawAsset) && !isChildClassOf(ctor, legacyCC.Asset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 内部使用。
|
||||
*/
|
||||
// @ts-ignore
|
||||
public _uuid: string;
|
||||
|
||||
constructor (...args: ConstructorParameters<typeof CCObject>) {
|
||||
super(...args);
|
||||
|
||||
Object.defineProperty(this, '_uuid', {
|
||||
value: '',
|
||||
writable: true,
|
||||
// enumerable is false by default, to avoid uuid being assigned to empty string during destroy
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
legacyCC.RawAsset = RawAsset;
|
||||
@@ -50,7 +50,7 @@ export default class SceneAsset extends Asset {
|
||||
public scene: Scene | null = null;
|
||||
|
||||
/**
|
||||
* @en Indicates the raw assets of this scene can be load after scene launched.
|
||||
* @en Indicates the native assets of this scene can be load after scene launched.
|
||||
* @zh 指示该场景依赖的资源可否在场景切换后再延迟加载。
|
||||
* @default false
|
||||
*/
|
||||
|
||||
@@ -210,7 +210,7 @@ export class UITransform extends Component {
|
||||
}
|
||||
|
||||
if (this._canvas && this._canvas.node === this.node) {
|
||||
warnID(9200);
|
||||
warnID(6706);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -596,10 +596,6 @@ function parseAttributes (constructor: Function, attributes: IAcceptableAttribut
|
||||
parseSimpleAttribute('unit', 'string');
|
||||
}
|
||||
|
||||
if (attributes.url) {
|
||||
(attrs || initAttrs())[propertyNamePrefix + 'saveUrlAsAsset'] = true;
|
||||
}
|
||||
|
||||
if (attributes.__noImplicit) {
|
||||
(attrs || initAttrs())[propertyNamePrefix + 'serializable'] = attributes.serializable ?? false;
|
||||
} else {
|
||||
|
||||
@@ -124,8 +124,7 @@ function genProperty (
|
||||
let fullOptions;
|
||||
let isGetset = descriptor && (descriptor.get || descriptor.set);
|
||||
if (options) {
|
||||
fullOptions = DEV ? getFullFormOfProperty(options, isGetset, propertyKey, js.getClassName(ctor)) :
|
||||
getFullFormOfProperty(options, isGetset);
|
||||
fullOptions = getFullFormOfProperty(options, isGetset);
|
||||
}
|
||||
const existsPropertyRecord = properties[propertyKey];
|
||||
const propertyRecord = js.mixin(existsPropertyRecord || {}, fullOptions || options || {});
|
||||
|
||||
@@ -69,7 +69,7 @@ function _dereference (self) {
|
||||
}
|
||||
}
|
||||
|
||||
function compileObjectTypeJit (sources, defaultValue, accessorToSet, propNameLiteralToSet, assumeHavePropIfIsValue, stillUseUrl) {
|
||||
function compileObjectTypeJit (sources, defaultValue, accessorToSet, propNameLiteralToSet, assumeHavePropIfIsValue) {
|
||||
if (defaultValue instanceof legacyCC.ValueType) {
|
||||
// fast case
|
||||
if (!assumeHavePropIfIsValue) {
|
||||
@@ -83,10 +83,7 @@ function compileObjectTypeJit (sources, defaultValue, accessorToSet, propNameLit
|
||||
}
|
||||
else {
|
||||
sources.push('if(prop){');
|
||||
sources.push('s._deserializeObjField(o,prop,' +
|
||||
propNameLiteralToSet +
|
||||
!!stillUseUrl +
|
||||
');');
|
||||
sources.push('s._deserializeObjField(o,prop,' + propNameLiteralToSet + ');');
|
||||
sources.push('}else o' + accessorToSet + '=null;');
|
||||
}
|
||||
}
|
||||
@@ -95,7 +92,6 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
const TYPE = Attr.DELIMETER + 'type';
|
||||
const EDITOR_ONLY = Attr.DELIMETER + 'editorOnly';
|
||||
const DEFAULT = Attr.DELIMETER + 'default';
|
||||
const SAVE_URL_AS_ASSET = Attr.DELIMETER + 'saveUrlAsAsset';
|
||||
const FORMERLY_SERIALIZED_AS = Attr.DELIMETER + 'formerlySerializedAs';
|
||||
const attrs = Attr.getClassAttrs(klass);
|
||||
|
||||
@@ -138,7 +134,6 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
sources.push('prop=d' + accessorToGet + ';');
|
||||
sources.push(`if(typeof ${JSB ? '(prop)' : 'prop'}!=="undefined"){`);
|
||||
|
||||
const stillUseUrl = attrs[propName + SAVE_URL_AS_ASSET];
|
||||
// function undefined object(null) string boolean number
|
||||
const defaultValue = CCClass.getDefault(attrs[propName + DEFAULT]);
|
||||
if (fastMode) {
|
||||
@@ -149,7 +144,7 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
}
|
||||
else {
|
||||
const defaultType = typeof defaultValue;
|
||||
isPrimitiveType = (defaultType === 'string' && !stillUseUrl) ||
|
||||
isPrimitiveType = defaultType === 'string' ||
|
||||
defaultType === 'number' ||
|
||||
defaultType === 'boolean';
|
||||
}
|
||||
@@ -158,14 +153,14 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
sources.push(`o${accessorToSet}=prop;`);
|
||||
}
|
||||
else {
|
||||
compileObjectTypeJit(sources, defaultValue, accessorToSet, propNameLiteralToSet, true, stillUseUrl);
|
||||
compileObjectTypeJit(sources, defaultValue, accessorToSet, propNameLiteralToSet, true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
sources.push(`if(typeof ${JSB ? '(prop)' : 'prop'}!=="object"){` +
|
||||
'o' + accessorToSet + '=prop;' +
|
||||
'}else{');
|
||||
compileObjectTypeJit(sources, defaultValue, accessorToSet, propNameLiteralToSet, false, stillUseUrl);
|
||||
compileObjectTypeJit(sources, defaultValue, accessorToSet, propNameLiteralToSet, false);
|
||||
sources.push('}');
|
||||
}
|
||||
sources.push('}');
|
||||
@@ -197,7 +192,6 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
let simplePropsToRead = simpleProps;
|
||||
const advancedProps: any = [];
|
||||
let advancedPropsToRead = advancedProps;
|
||||
const advancedPropsUseUrl: any = [];
|
||||
const advancedPropsValueType: any = [];
|
||||
|
||||
(() => {
|
||||
@@ -207,7 +201,6 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
const attrs = Attr.getClassAttrs(klass);
|
||||
const TYPE = Attr.DELIMETER + 'type';
|
||||
const DEFAULT = Attr.DELIMETER + 'default';
|
||||
const SAVE_URL_AS_ASSET = Attr.DELIMETER + 'saveUrlAsAsset';
|
||||
const FORMERLY_SERIALIZED_AS = Attr.DELIMETER + 'formerlySerializedAs';
|
||||
|
||||
// tslint:disable-next-line: prefer-for-of
|
||||
@@ -217,7 +210,6 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
if (attrs[propName + FORMERLY_SERIALIZED_AS]) {
|
||||
propNameToRead = attrs[propName + FORMERLY_SERIALIZED_AS];
|
||||
}
|
||||
const stillUseUrl = attrs[propName + SAVE_URL_AS_ASSET];
|
||||
// function undefined object(null) string boolean number
|
||||
const defaultValue = CCClass.getDefault(attrs[propName + DEFAULT]);
|
||||
let isPrimitiveType = false;
|
||||
@@ -228,7 +220,7 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
}
|
||||
else {
|
||||
const defaultType = typeof defaultValue;
|
||||
isPrimitiveType = (defaultType === 'string' && !stillUseUrl) ||
|
||||
isPrimitiveType = defaultType === 'string' ||
|
||||
defaultType === 'number' ||
|
||||
defaultType === 'boolean';
|
||||
}
|
||||
@@ -250,7 +242,6 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
if (advancedPropsToRead !== advancedProps) {
|
||||
advancedPropsToRead.push(propNameToRead);
|
||||
}
|
||||
advancedPropsUseUrl.push(stillUseUrl);
|
||||
advancedPropsValueType.push((defaultValue instanceof legacyCC.ValueType) && defaultValue.constructor);
|
||||
}
|
||||
}
|
||||
@@ -285,7 +276,7 @@ const compileDeserialize = SUPPORT_JIT ? (self, klass) => {
|
||||
}
|
||||
else {
|
||||
if (prop) {
|
||||
s._deserializeObjField(o, prop, propName, advancedPropsUseUrl[i]);
|
||||
s._deserializeObjField(o, prop, propName);
|
||||
}
|
||||
else {
|
||||
o[propName] = null;
|
||||
@@ -405,10 +396,10 @@ class _Deserializer {
|
||||
for (let i = 0; i < refCount; i++) {
|
||||
if (jsonArray[i]) {
|
||||
if (EDITOR || TEST) {
|
||||
this.deserializedList[i] = this._deserializeObject(jsonArray[i], false, this.deserializedList, '' + i);
|
||||
this.deserializedList[i] = this._deserializeObject(jsonArray[i], this.deserializedList, '' + i);
|
||||
}
|
||||
else {
|
||||
this.deserializedList[i] = this._deserializeObject(jsonArray[i], false);
|
||||
this.deserializedList[i] = this._deserializeObject(jsonArray[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,10 +419,10 @@ class _Deserializer {
|
||||
let deserializedData;
|
||||
this.deserializedList.length = 1;
|
||||
if (EDITOR || TEST) {
|
||||
deserializedData = jsonObj ? this._deserializeObject(jsonObj, false, this.deserializedList, '0') : null;
|
||||
deserializedData = jsonObj ? this._deserializeObject(jsonObj, this.deserializedList, '0') : null;
|
||||
}
|
||||
else {
|
||||
deserializedData = jsonObj ? this._deserializeObject(jsonObj, false) : null;
|
||||
deserializedData = jsonObj ? this._deserializeObject(jsonObj) : null;
|
||||
}
|
||||
|
||||
// dereference
|
||||
@@ -452,11 +443,10 @@ class _Deserializer {
|
||||
|
||||
/**
|
||||
* @param {Object} serialized - The obj to deserialize, must be non-nil
|
||||
* @param {Boolean} _stillUseUrl
|
||||
* @param {Object} [owner] - debug only
|
||||
* @param {String} [propName] - debug only
|
||||
*/
|
||||
private _deserializeObject (serialized, _stillUseUrl: Boolean, owner?: Object, propName?: String) {
|
||||
private _deserializeObject (serialized, owner?: Object, propName?: String) {
|
||||
let prop;
|
||||
let obj: any = null; // the obj to return
|
||||
let klass: any = null;
|
||||
@@ -536,7 +526,7 @@ class _Deserializer {
|
||||
for (let i = 0; i < serialized.length; i++) {
|
||||
prop = serialized[i];
|
||||
if (typeof prop === 'object' && prop) {
|
||||
this._deserializeObjField(obj, prop, '' + i, _stillUseUrl);
|
||||
this._deserializeObjField(obj, prop, '' + i);
|
||||
}
|
||||
else {
|
||||
obj[i] = prop;
|
||||
@@ -547,19 +537,19 @@ class _Deserializer {
|
||||
}
|
||||
|
||||
// 和 _deserializeObject 不同的地方在于会判断 id 和 uuid
|
||||
private _deserializeObjField (obj, jsonObj, propName, _stillUseUrl?) {
|
||||
private _deserializeObjField (obj, jsonObj, propName) {
|
||||
const id = jsonObj.__id__;
|
||||
if (id === undefined) {
|
||||
const uuid = jsonObj.__uuid__;
|
||||
if (uuid) {
|
||||
this.result.push(obj, propName, uuid, _stillUseUrl);
|
||||
this.result.push(obj, propName, uuid);
|
||||
}
|
||||
else {
|
||||
if (EDITOR || TEST) {
|
||||
obj[propName] = this._deserializeObject(jsonObj, _stillUseUrl, obj, propName);
|
||||
obj[propName] = this._deserializeObject(jsonObj, obj, propName);
|
||||
}
|
||||
else {
|
||||
obj[propName] = this._deserializeObject(jsonObj, _stillUseUrl);
|
||||
obj[propName] = this._deserializeObject(jsonObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -676,7 +666,6 @@ _Deserializer.pool.get = function (result, classFinder, customEnv, ignoreEditorO
|
||||
export function deserializeDynamic (data, details: Details, options) {
|
||||
options = options || {};
|
||||
const classFinder = options.classFinder || js._getClassById;
|
||||
// 启用 createAssetRefs 后,如果有 url 属性则会被统一强制设置为 { uuid: 'xxx' },必须后面再特殊处理
|
||||
const createAssetRefs = options.createAssetRefs || legacyCC.sys.platform === legacyCC.sys.EDITOR_CORE;
|
||||
const customEnv = options.customEnv;
|
||||
const ignoreEditorOnly = options.ignoreEditorOnly;
|
||||
|
||||
@@ -5,11 +5,6 @@ export interface IExposedAttributes {
|
||||
*/
|
||||
type?: any;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
url?: string;
|
||||
|
||||
/**
|
||||
* 控制是否在编辑器中显示该属性。
|
||||
*/
|
||||
|
||||
@@ -201,18 +201,17 @@ export function getTypeChecker_ET (type: string, attributeName: string) {
|
||||
return function (constructor: Function, mainPropertyName: string) {
|
||||
const propInfo = '"' + getClassName(constructor) + '.' + mainPropertyName + '"';
|
||||
const mainPropAttrs = attr(constructor, mainPropertyName);
|
||||
if (!mainPropAttrs.saveUrlAsAsset) {
|
||||
let mainPropAttrsType = mainPropAttrs.type;
|
||||
if (mainPropAttrsType === CCInteger || mainPropAttrsType === CCFloat) {
|
||||
mainPropAttrsType = 'Number';
|
||||
} else if (mainPropAttrsType === CCString || mainPropAttrsType === CCBoolean) {
|
||||
mainPropAttrsType = '' + mainPropAttrsType;
|
||||
}
|
||||
if (mainPropAttrsType !== type) {
|
||||
warnID(3604, propInfo);
|
||||
return;
|
||||
}
|
||||
let mainPropAttrsType = mainPropAttrs.type;
|
||||
if (mainPropAttrsType === CCInteger || mainPropAttrsType === CCFloat) {
|
||||
mainPropAttrsType = 'Number';
|
||||
} else if (mainPropAttrsType === CCString || mainPropAttrsType === CCBoolean) {
|
||||
mainPropAttrsType = '' + mainPropAttrsType;
|
||||
}
|
||||
if (mainPropAttrsType !== type) {
|
||||
warnID(3604, propInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mainPropAttrs.hasOwnProperty('default')) {
|
||||
return;
|
||||
}
|
||||
@@ -227,22 +226,18 @@ export function getTypeChecker_ET (type: string, attributeName: string) {
|
||||
const defaultType = typeof defaultVal;
|
||||
const type_lowerCase = type.toLowerCase();
|
||||
if (defaultType === type_lowerCase) {
|
||||
if (!mainPropAttrs.saveUrlAsAsset) {
|
||||
if (type_lowerCase === 'object') {
|
||||
if (defaultVal && !(defaultVal instanceof mainPropAttrs.ctor)) {
|
||||
warnID(3605, propInfo, getClassName(mainPropAttrs.ctor));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (type !== 'Number') {
|
||||
warnID(3606, attributeName, propInfo, type);
|
||||
if (type_lowerCase === 'object') {
|
||||
if (defaultVal && !(defaultVal instanceof mainPropAttrs.ctor)) {
|
||||
warnID(3605, propInfo, getClassName(mainPropAttrs.ctor));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (type !== 'Number') {
|
||||
warnID(3606, attributeName, propInfo, type);
|
||||
}
|
||||
} else if (defaultType !== 'function') {
|
||||
if (type === CCString.default && defaultVal == null) {
|
||||
if (!isChildClassOf(mainPropAttrs.ctor, legacyCC.RawAsset)) {
|
||||
warnID(3607, propInfo);
|
||||
}
|
||||
warnID(3607, propInfo);
|
||||
} else {
|
||||
warnID(3611, attributeName, propInfo, defaultType);
|
||||
}
|
||||
|
||||
@@ -33,9 +33,6 @@ import { legacyCC } from '../../global-exports';
|
||||
// 增加预处理属性这个步骤的目的是降低 CCClass 的实现难度,将比较稳定的通用逻辑和一些需求比较灵活的属性需求分隔开。
|
||||
|
||||
const SerializableAttrs = {
|
||||
url: {
|
||||
canUsedInGet: true,
|
||||
},
|
||||
default: {},
|
||||
serializable: {},
|
||||
editorOnly: {},
|
||||
@@ -85,61 +82,6 @@ function parseNotify (val, propName, notify, properties) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查 url
|
||||
*/
|
||||
function checkUrl (val, className, propName, url) {
|
||||
if (Array.isArray(url)) {
|
||||
if (url.length > 0) {
|
||||
url = url[0];
|
||||
}
|
||||
else if (EDITOR) {
|
||||
return errorID(5502, className, propName);
|
||||
}
|
||||
}
|
||||
if (EDITOR) {
|
||||
if (url == null) {
|
||||
return warnID(5503, className, propName);
|
||||
}
|
||||
if (typeof url !== 'function' || !js.isChildClassOf(url, legacyCC.RawAsset)) {
|
||||
return errorID(5504, className, propName);
|
||||
}
|
||||
if (url === legacyCC.RawAsset) {
|
||||
warn('Please change the definition of property \'%s\' in class \'%s\'. Starting from v1.10,\n' +
|
||||
'the use of declaring a property in CCClass as a URL has been deprecated.\n' +
|
||||
'For example, if property is cc.RawAsset, the previous definition is:\n' +
|
||||
' %s: cc.RawAsset,\n' +
|
||||
' // or:\n' +
|
||||
' %s: {\n' +
|
||||
' url: cc.RawAsset,\n' +
|
||||
' default: ""\n' +
|
||||
' },\n' +
|
||||
' // and the original method to get url is:\n' +
|
||||
' `this.%s`\n' +
|
||||
'Now it should be changed to:\n' +
|
||||
' %s: {\n' +
|
||||
' type: cc.Asset, // use \'type:\' to define Asset object directly\n' +
|
||||
' default: null, // object\'s default value is null\n' +
|
||||
' },\n' +
|
||||
' // and you must get the url by using:\n' +
|
||||
' `this.%s.nativeUrl`\n' +
|
||||
'(This helps us to successfully refactor all RawAssets at v2.0, ' +
|
||||
'sorry for the inconvenience. \uD83D\uDE30 )',
|
||||
propName, className, propName, propName, propName, propName, propName);
|
||||
}
|
||||
else if (js.isChildClassOf(url, legacyCC.Asset)) {
|
||||
return errorID(5505, className, propName, legacyCC.js.getClassName(url));
|
||||
}
|
||||
if (val.type) {
|
||||
return warnID(5506, className, propName);
|
||||
}
|
||||
}
|
||||
val.type = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析类型
|
||||
*/
|
||||
function parseType (val, type, className, propName) {
|
||||
const STATIC_CHECK = (EDITOR && DEV) || TEST;
|
||||
|
||||
@@ -150,13 +92,7 @@ function parseType (val, type, className, propName) {
|
||||
}
|
||||
}
|
||||
if (type.length > 0) {
|
||||
if (legacyCC.RawAsset.isRawAssetType(type[0])) {
|
||||
val.url = type[0];
|
||||
delete val.type;
|
||||
return;
|
||||
} else {
|
||||
val.type = type = type[0];
|
||||
}
|
||||
val.type = type = type[0];
|
||||
} else {
|
||||
return errorID(5508, className, propName);
|
||||
}
|
||||
@@ -200,9 +136,7 @@ function parseType (val, type, className, propName) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function postCheckType (val, type, className, propName) {
|
||||
if (EDITOR && typeof type === 'function') {
|
||||
if (legacyCC.Class._isCCClass(type) && val.serializable !== false && !js._getClassId(type, false)) {
|
||||
warnID(5512, className, propName, className, propName);
|
||||
@@ -225,25 +159,19 @@ function getBaseClassWherePropertyDefined_DEV (propName, cls) {
|
||||
|
||||
// tslint:disable: no-shadowed-variable
|
||||
|
||||
function _wrapOptions (isGetset: boolean, _default, type?: Function | Function[], isUrlType?: boolean) {
|
||||
function _wrapOptions (isGetset: boolean, _default, type?: Function | Function[]) {
|
||||
let res: {
|
||||
default?: any,
|
||||
_short?: boolean,
|
||||
url?: any,
|
||||
type?: any,
|
||||
} = isGetset ? { _short: true } : { _short: true, default: _default };
|
||||
if (type) {
|
||||
if (isUrlType) {
|
||||
res.url = type;
|
||||
}
|
||||
else {
|
||||
res.type = type;
|
||||
}
|
||||
res.type = type;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
export function getFullFormOfProperty (options, isGetset, propname_dev?, classname_dev?) {
|
||||
export function getFullFormOfProperty (options, isGetset) {
|
||||
const isLiteral = options && options.constructor === Object;
|
||||
if ( !isLiteral ) {
|
||||
if (Array.isArray(options) && options.length > 0) {
|
||||
@@ -263,7 +191,7 @@ export function getFullFormOfProperty (options, isGetset, propname_dev?, classna
|
||||
export function preprocessAttrs (properties, className, cls) {
|
||||
for (const propName in properties) {
|
||||
let val = properties[propName];
|
||||
const fullForm = getFullFormOfProperty(val, false, propName, className);
|
||||
const fullForm = getFullFormOfProperty(val, false);
|
||||
if (fullForm) {
|
||||
val = properties[propName] = fullForm;
|
||||
}
|
||||
@@ -300,14 +228,6 @@ export function preprocessAttrs (properties, className, cls) {
|
||||
if ('type' in val) {
|
||||
parseType(val, val.type, className, propName);
|
||||
}
|
||||
|
||||
if ('url' in val) {
|
||||
checkUrl(val, className, propName, val.url);
|
||||
}
|
||||
|
||||
if ('type' in val) {
|
||||
postCheckType(val, val.type, className, propName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,10 +415,6 @@ export class Label extends UIRenderable {
|
||||
// if (value && this._isSystemFontUsed)
|
||||
// this._isSystemFontUsed = false;
|
||||
|
||||
if (typeof value === 'string') {
|
||||
warnID(4000);
|
||||
}
|
||||
|
||||
if (this._renderData) {
|
||||
this.destroyRenderData();
|
||||
this._renderData = null;
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
if (TestEditorExtends) {
|
||||
(function () {
|
||||
|
||||
module('Migrating Raw Assets');
|
||||
|
||||
test('serialization if declared in the OLD way', function () {
|
||||
// setup
|
||||
var sysWarn = cc.warn;
|
||||
cc.warn = Callback().enable();
|
||||
var MyAsset = cc.Class({
|
||||
name: 'MyAsset',
|
||||
properties: {
|
||||
ref_full: {
|
||||
url: cc.Texture2D,
|
||||
default: "",
|
||||
},
|
||||
ref_full_array: {
|
||||
url: cc.Texture2D,
|
||||
default: [],
|
||||
},
|
||||
ref_brief: cc.Texture2D,
|
||||
ref_brief_array: [cc.Texture2D],
|
||||
}
|
||||
});
|
||||
strictEqual(cc.warn.calledCount, 2, 'should trigger warnings if declared in deprecated way');
|
||||
cc.warn = sysWarn;
|
||||
|
||||
var asset = new MyAsset();
|
||||
asset.ref_full = 'foo';
|
||||
asset.ref_full_array = ['foo'];
|
||||
asset.ref_brief = 'foo';
|
||||
asset.ref_brief_array = ['foo'];
|
||||
|
||||
// serialize
|
||||
var sysUrlToUuid = Editor.Utils.UuidCache.urlToUuid;
|
||||
Editor.Utils.UuidCache.urlToUuid = function (url) {
|
||||
return {
|
||||
foo: '01',
|
||||
}[url];
|
||||
};
|
||||
var serializedAsset = EditorExtends.serialize(asset);
|
||||
Editor.Utils.UuidCache.urlToUuid = sysUrlToUuid;
|
||||
|
||||
// deserialize
|
||||
var details = new cc.deserialize.Details();
|
||||
var deserializedAsset = cc.deserialize(serializedAsset, details, {createAssetRefs: true});
|
||||
|
||||
// test
|
||||
ok(details._stillUseUrl[0] &&
|
||||
details._stillUseUrl[1] &&
|
||||
details._stillUseUrl[2] &&
|
||||
details._stillUseUrl[3], 'should deserialize them as url');
|
||||
|
||||
ok(deserializedAsset.ref_full._uuid === '01', 'should support serialization if declared in full form');
|
||||
ok(deserializedAsset.ref_full_array[0]._uuid === '01', 'should support serialization if array declared in full form');
|
||||
ok(deserializedAsset.ref_brief._uuid === '01', 'should still support serialization if declared in deprecated form');
|
||||
ok(deserializedAsset.ref_brief_array[0]._uuid === '01', 'should still support serialization if array declared in deprecated form');
|
||||
|
||||
//teardown
|
||||
cc.js.unregisterClass(MyAsset);
|
||||
});
|
||||
|
||||
test('serialization if declared in the NEW way', function () {
|
||||
// setup
|
||||
var MyAsset = cc.Class({
|
||||
name: 'MyAsset',
|
||||
properties: {
|
||||
ref_full: {
|
||||
type: cc.Texture2D,
|
||||
default: null,
|
||||
},
|
||||
ref_full_array: {
|
||||
type: cc.Texture2D,
|
||||
default: []
|
||||
},
|
||||
// TODO - uncomment in 2.0
|
||||
// ref_brief: cc.Texture2D,
|
||||
// ref_brief_array: [cc.Texture2D],
|
||||
}
|
||||
});
|
||||
var asset = new MyAsset();
|
||||
asset.ref_full = new cc.Texture2D();
|
||||
asset.ref_full._uuid = '01';
|
||||
asset.ref_full_array.push(asset.ref_full);
|
||||
// asset.ref_brief = asset.ref_full;
|
||||
// asset.ref_brief_array.push(asset.ref_full);
|
||||
|
||||
// serialize
|
||||
var restore = Editor.Utils.UuidCache.urlToUuid;
|
||||
Editor.Utils.UuidCache.urlToUuid = function (url) {
|
||||
return {
|
||||
foo: '01',
|
||||
}[url];
|
||||
};
|
||||
var serializedAsset = EditorExtends.serialize(asset);
|
||||
Editor.Utils.UuidCache.urlToUuid = restore;
|
||||
|
||||
// deserialize
|
||||
var deserializedAsset = cc.deserialize(serializedAsset, null, {createAssetRefs: true});
|
||||
|
||||
// test
|
||||
ok(deserializedAsset.ref_full._uuid === '01', 'should support serialization if declared in full form');
|
||||
ok(deserializedAsset.ref_full_array[0]._uuid === '01', 'should support serialization if array declared in full form');
|
||||
// ok(deserializedAsset.ref_brief._uuid === '01', 'should support serialization if declared in brief form');
|
||||
// ok(deserializedAsset.ref_brief_array[0]._uuid === '01', 'should support serialization if declared in brief form');
|
||||
|
||||
//teardown
|
||||
cc.js.unregisterClass(MyAsset);
|
||||
});
|
||||
})();
|
||||
}
|
||||
@@ -728,7 +728,6 @@ test('simplified properties define', function () {
|
||||
int: [cc.Integer],
|
||||
valueType: [cc.Vec2],
|
||||
node: [cc.Node],
|
||||
rawAsset: [cc.RawAsset],
|
||||
asset: {
|
||||
default: [],
|
||||
type: cc.Asset
|
||||
@@ -743,15 +742,12 @@ test('simplified properties define', function () {
|
||||
strictEqual(cc.Class.attr(ArrayType, 'valueType').ctor, cc.Vec2, 'checking array of vec2 ctor');
|
||||
strictEqual(cc.Class.attr(ArrayType, 'node').type, 'Object', 'checking array of node type');
|
||||
strictEqual(cc.Class.attr(ArrayType, 'node').ctor, cc.Node, 'checking array of node ctor');
|
||||
strictEqual(cc.Class.attr(ArrayType, 'rawAsset').type, 'Object', 'checking array of raw asset type');
|
||||
strictEqual(cc.Class.attr(ArrayType, 'rawAsset').ctor, cc.RawAsset, 'checking array of raw asset ctor');
|
||||
|
||||
deepEqual(arrayObj.empty, [], 'checking array of empty');
|
||||
deepEqual(arrayObj.bool, [], 'checking array of bool');
|
||||
deepEqual(arrayObj.string, [], 'checking array of string');
|
||||
deepEqual(arrayObj.valueType, [], 'checking array of valueType');
|
||||
deepEqual(arrayObj.node, [], 'checking array of node');
|
||||
deepEqual(arrayObj.rawAsset, [], 'checking array of rawAsset');
|
||||
deepEqual(arrayObj.asset, [], 'checking array of asset');
|
||||
});
|
||||
|
||||
|
||||
@@ -415,47 +415,6 @@
|
||||
deepEqual(data, expected, 'nicify success');
|
||||
});
|
||||
|
||||
test('url array', function () {
|
||||
var Data = cc.Class({
|
||||
name: 'data',
|
||||
properties: {
|
||||
textures: {
|
||||
default: [],
|
||||
url: [cc.Texture2D]
|
||||
}
|
||||
}
|
||||
});
|
||||
var restore = Editor.Utils.UuidCache.urlToUuid;
|
||||
Editor.Utils.UuidCache.urlToUuid = function (url) {
|
||||
return {
|
||||
foo: '01',
|
||||
bar: '02'
|
||||
}[url];
|
||||
};
|
||||
|
||||
var data = new Data();
|
||||
data.textures = ['foo', 'bar'];
|
||||
|
||||
var actual = JSON.parse(EditorExtends.serialize(data));
|
||||
strictEqual(actual.image, undefined, 'should not serialize variable which not defined by property');
|
||||
|
||||
var expected = {
|
||||
__type__: 'data',
|
||||
textures: [
|
||||
{
|
||||
__uuid__: '01'
|
||||
},
|
||||
{
|
||||
__uuid__: '02'
|
||||
}
|
||||
]
|
||||
};
|
||||
deepEqual(actual, expected, 'could be serialized');
|
||||
|
||||
Editor.Utils.UuidCache.urlToUuid = restore;
|
||||
cc.js.unregisterClass(Data);
|
||||
});
|
||||
|
||||
test('node array', function () {
|
||||
var Data = cc.Class({
|
||||
name: 'data',
|
||||
|
||||
@@ -154,7 +154,6 @@
|
||||
"cc.ProgressBarComponent",
|
||||
"cc.Quat",
|
||||
"cc.RatioSampler",
|
||||
"cc.RawAsset",
|
||||
"cc.Rect",
|
||||
"cc.RenderFlow",
|
||||
"cc.RenderPassStage",
|
||||
|
||||
Reference in New Issue
Block a user