Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cocos/core/data/class-decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export { property } from './decorators/property';
export { requireComponent, executionOrder, disallowMultiple } from './decorators/component';
export { executeInEditMode, menu, playOnFocus, inspector, icon, help } from './decorators/editable';
export { type, integer, float, boolean, string } from './decorators/type';
export { OneOf } from './decorators/one-of';
export type {
OneOfOptions,
OneOfVariant,
OneOfTypedVariant,
OneOfKeyVariant,
OneOfDiscriminator,
OneOfKey,
OneOfPropertyType,
} from './decorators/one-of';

// engine internal exports
export { editable, tooltip, visible, displayName, displayOrder, range, rangeStep, slide, disallowAnimation } from './decorators/editable';
Expand Down
19 changes: 13 additions & 6 deletions cocos/core/data/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
import { legacyCC } from '../global-exports';
import { PropertyStash, PropertyStashInternalFlag } from './class-stash';
import { setPropertyEnumTypeOnAttrs } from './utils/attribute-internal';
import {
applyOneOfPropertyAttributes,
isOneOfPropertyType,
} from './decorators/one-of';

const DELIMETER = attributeUtils.DELIMETER;
const CCCLASS_TAG = '__ctors__'; // Still use this historical name to avoid unsynchronized version issue
Expand Down Expand Up @@ -78,7 +82,7 @@
if (CCClass.getInheritanceChain(cls)
// eslint-disable-next-line no-prototype-builtins
.some((x) => x.prototype.hasOwnProperty(propName))) {
errorID(3637, className, propName, className);

Check failure on line 85 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `StringSubstitution`

Check failure on line 85 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `StringSubstitution`

Check failure on line 85 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `StringSubstitution`
return;
}
}
Expand All @@ -86,10 +90,10 @@
appendProp(cls, propName);

// apply attributes
parseAttributes(cls, val, className, propName, false);

Check failure on line 93 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 93 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 93 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `PropertyStash`

Check failure on line 93 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Function`
if ((EDITOR && !window.Build) || TEST) {
for (let i = 0; i < onAfterProps_ET.length; i++) {
onAfterProps_ET[i](cls, propName);

Check failure on line 96 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `string`

Check failure on line 96 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Function`
}
onAfterProps_ET.length = 0;
}
Expand All @@ -100,7 +104,7 @@
const setter = val.set;

if (getter) {
parseAttributes(cls, val, name, propName, true);

Check failure on line 107 in cocos/core/data/class.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe argument of type `any` assigned to a parameter of type `Function`
if ((EDITOR && !window.Build) || TEST) {
onAfterProps_ET.length = 0;
}
Expand Down Expand Up @@ -408,15 +412,10 @@
enumList?: readonly any[];
bitmaskList?: any[];
}

type OnAfterProp = (constructor: Function, mainPropertyName: string) => void;
const onAfterProps_ET: OnAfterProp[] = [];

interface AttributesRecord {
get?: unknown;
set?: unknown;
default?: unknown;
}

function parseAttributes (constructor: Function, attributes: PropertyStash, className: string, propertyName: string, usedInGetter): void {
const ERR_Type = DEV ? 'The %s of %s must be type %s' : '';

Expand All @@ -436,6 +435,7 @@
}

let warnOnNoDefault = true;
let oneOfType: unknown;

const type = attributes.type;
if (type) {
Expand Down Expand Up @@ -464,6 +464,9 @@
} else if (BitMask.isBitMask(type)) {
(attrs || initAttrs())[`${propertyNamePrefix}type`] = BITMASK_TAG;
attrs![`${propertyNamePrefix}bitmaskList`] = BitMask.getList(type);
} else if (isOneOfPropertyType(type)) {
warnOnNoDefault = false;
oneOfType = type;
} else if (DEV) {
errorID(3645, className, propertyName, type);
}
Expand Down Expand Up @@ -606,6 +609,10 @@
}
parseSimpleAttribute('step', 'number');
parseSimpleAttribute('userData', 'object');

if (oneOfType) {
applyOneOfPropertyAttributes(attrs || initAttrs(), constructor, propertyName, propertyNamePrefix, oneOfType);
}
}

CCClass.isArray = function (defaultVal): boolean {
Expand Down
10 changes: 10 additions & 0 deletions cocos/core/data/decorators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,14 @@ export {
} from './serializable';
export * from './editable';
export * from './type';
export { OneOf } from './one-of';
export type {
OneOfOptions,
OneOfVariant,
OneOfTypedVariant,
OneOfKeyVariant,
OneOfDiscriminator,
OneOfKey,
OneOfPropertyType,
} from './one-of';
export { override } from './override';
Loading
Loading