Skip to content

Commit

Permalink
refactor: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxudong committed Jan 6, 2025
1 parent bf1733e commit 3c2c29f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions packages/loader/src/SceneLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Scene,
TonemappingEffect
} from "@galacean/engine-core";
import { IClassObject, IScene, ReflectionParser, SceneParser, SpecularMode } from "./resource-deserialize";
import { IClass, IScene, ReflectionParser, SceneParser, SpecularMode } from "./resource-deserialize";

@resourceLoader(AssetType.Scene, ["scene"], true)
class SceneLoader extends Loader<Scene> {
Expand Down Expand Up @@ -146,7 +146,7 @@ class SceneLoader extends Loader<Scene> {

ReflectionParser.registerCustomParseComponent(

Check failure on line 147 in packages/loader/src/SceneLoader.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎··"TextRenderer",⏎·` with `"TextRenderer",`
"TextRenderer",
async (instance: any, item: Omit<IClassObject, "class">) => {
async (instance: any, item: Omit<IClass, "class">) => {
const { props } = item;

Check failure on line 150 in packages/loader/src/SceneLoader.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
if (!props.font) {

Check failure on line 151 in packages/loader/src/SceneLoader.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
// @ts-ignore

Check failure on line 152 in packages/loader/src/SceneLoader.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `······` with `····`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { EngineObject, Entity, Loader } from "@galacean/engine-core";
import type {
IAssetRef,
IBasicType,
ICanParseResultObject,
IClassObject,
IClassTypeObject,
IClass,
IClassType,
IComponentRef,
IEntity,
IEntityRef,
IHierarchyFile,
IMethod,
IMethodParams,
IRefEntity
} from "../schema";
Expand Down Expand Up @@ -37,15 +37,15 @@ export class ReflectionParser {
});
}

parseClassObject(item: IClassObject) {
parseClassObject(item: IClass) {
const Class = Loader.getClass(item.class);
const params = item.constructParams ?? [];
return Promise.all(params.map((param) => this.parseBasicType(param)))
.then((resultParams) => new Class(...resultParams))
.then((instance) => this.parsePropsAndMethods(instance, item));
}

parsePropsAndMethods(instance: any, item: Omit<IClassObject, "class">) {
parsePropsAndMethods(instance: any, item: Omit<IClass, "class">) {
const promises = [];
if (item.methods) {
for (let methodName in item.methods) {
Expand Down Expand Up @@ -74,12 +74,12 @@ export class ReflectionParser {
}

parseMethod(instance: any, methodName: string, methodParams: IMethodParams) {
const isCanParseResultObject = ReflectionParser._isCanParseResultObject(methodParams);
const params = isCanParseResultObject ? methodParams.params : methodParams;
const isMethodObject = ReflectionParser._isMethodObject(methodParams);
const params = isMethodObject ? methodParams.params : methodParams;

return Promise.all(params.map((param) => this.parseBasicType(param))).then((result) => {
const methodResult = instance[methodName](...result);
if (isCanParseResultObject && methodParams.result) {
if (isMethodObject && methodParams.result) {
return this.parsePropsAndMethods(methodResult, methodParams.result);
} else {
return methodResult;
Expand Down Expand Up @@ -167,11 +167,11 @@ export class ReflectionParser {
}
}

private static _isClass(value: any): value is IClassObject {
private static _isClass(value: any): value is IClass {
return value["class"] !== undefined;
}

private static _isClassType(value: any): value is IClassTypeObject {
private static _isClassType(value: any): value is IClassType {
return value["classType"] !== undefined;
}

Expand All @@ -187,7 +187,7 @@ export class ReflectionParser {
return value["ownerId"] !== undefined && value["componentId"] !== undefined;
}

private static _isCanParseResultObject(value: any): value is ICanParseResultObject {
private static _isMethodObject(value: any): value is IMethod {
return Array.isArray(value?.params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,12 @@ export interface IHierarchyFile {
entities: Array<IEntity>;
}

export type ICanParseResultObject = {
export type IMethod = {
params: Array<IBasicType>;
result?: {
methods?: { [methodName: string]: Array<IMethodParams> };
props?: { [key: string]: IBasicType | IMethodParams };
};
result?: IInstance;
};

export type IMethodParams = Array<IBasicType> | ICanParseResultObject;
export type IMethodParams = Array<IBasicType> | IMethod;

export interface IBasicEntity {
name?: string;
Expand All @@ -57,11 +54,9 @@ export interface IRefEntity extends IBasicEntity {
assetRefId: string;
key?: string;
isClone?: boolean;
modifications: {
modifications: (IInstance & {
target: IPrefabModifyTarget;
methods?: { [methodName: string]: Array<IMethodParams> };
props?: { [key: string]: IBasicType | IMethodParams };
}[];
})[];
removedEntities: IPrefabModifyTarget[];
removedComponents: IPrefabModifyTarget[];
}
Expand All @@ -77,16 +72,19 @@ export interface IStrippedEntity extends IBasicEntity {
prefabSource: { assetId: string; entityId: string };
}

export type IComponent = { id: string; refId?: string } & IClassObject;
export type IComponent = { id: string; refId?: string } & IClass;

export type IClassObject = {
export type IClass = {
class: string;
constructParams?: Array<IBasicType>;
} & IInstance;

export interface IInstance {
methods?: { [methodName: string]: Array<IMethodParams> };
props?: { [key: string]: IBasicType | IMethodParams };
};
}

export type IClassTypeObject = {
export type IClassType = {
classType: string;
};

Expand All @@ -97,8 +95,8 @@ export type IBasicType =
| null
| undefined
| IAssetRef
| IClassObject
| IClassTypeObject
| IClass
| IClassType
| IMethodParams
| IEntityRef;

Expand Down

0 comments on commit 3c2c29f

Please sign in to comment.