diff --git a/assets/core/gui/Gui.ts b/assets/core/gui/Gui.ts index 7fdc7c4..e1b97be 100644 --- a/assets/core/gui/Gui.ts +++ b/assets/core/gui/Gui.ts @@ -1,4 +1,3 @@ -import type { GameComponentCtor, UICtor } from '../../types/Module'; import type { UIConfigMap } from './layer/LayerEnum'; import type { UIConfig } from './layer/UIConfig'; @@ -6,8 +5,8 @@ const configs: UIConfigMap = {}; export namespace gui { /** 注册界面组件 */ - export function register(key: string, config: UIConfig): (ctor: GameComponentCtor) => void { - return function (ctor: GameComponentCtor): void { + export function register(key: string, config: UIConfig): (ctor: OopsFramework.GameComponentCtor) => void { + return function (ctor: OopsFramework.GameComponentCtor): void { (ctor as any)[gui.internal.GUI_KEY] = key; internal.setConfig(key, config); }; @@ -19,7 +18,7 @@ export namespace gui { export const GUI_KEY = 'OOPS_GUI_KEY'; /** 获取界面唯一关键字 */ - export function getKey(ctor: UICtor): string { + export function getKey(ctor: OopsFramework.UICtor): string { return (ctor as any)[GUI_KEY]; } diff --git a/assets/module/common/CCEntity.ts b/assets/module/common/CCEntity.ts index 2c6ffd2..73f32b9 100644 --- a/assets/module/common/CCEntity.ts +++ b/assets/module/common/CCEntity.ts @@ -7,7 +7,6 @@ import { ViewUtil } from '../../core/utils/ViewUtil'; import { ecs } from '../../libs/ecs/ECS'; import type { ECSEntity } from '../../libs/ecs/ECSEntity'; import type { CompType } from '../../libs/ecs/ECSModel'; -import type { BusinessCtor, EntityCtor, UICtor, View, ViewCtor } from '../../types/Module'; import type { CCBusiness } from './CCBusiness'; import { GameComponent } from './GameComponent'; @@ -16,13 +15,13 @@ export abstract class CCEntity extends ecs.Entity { //#region 子模块管理 /** 单例子实体集合(key: 实体类构造函数,value: 实体实例) */ - private singletons: Map = null!; + private singletons: Map = null!; /** * 批量添加单例子实体 * @param clss 单例子实体类数组 */ - addChildSingletons(...clss: EntityCtor[]): void { + addChildSingletons(...clss: OopsFramework.EntityCtor[]): void { for (const ctor of clss) { this.addChildSingleton(ctor); } @@ -33,7 +32,7 @@ export abstract class CCEntity extends ecs.Entity { * @param cls 单例子实体类 * @returns 单例子实体 */ - addChildSingleton(cls: EntityCtor): T { + addChildSingleton(cls: OopsFramework.EntityCtor): T { if (this.singletons == null) this.singletons = new Map(); if (this.singletons.has(cls)) { console.error(`${cls.name} 单例子实体已存在`); @@ -50,7 +49,7 @@ export abstract class CCEntity extends ecs.Entity { * @param cls 单例子实体类 * @returns 单例子实体,不存在则返回 null */ - getChildSingleton(cls: EntityCtor): T { + getChildSingleton(cls: OopsFramework.EntityCtor): T { if (!this.singletons) return null!; return (this.singletons.get(cls) as T) || null!; } @@ -59,7 +58,7 @@ export abstract class CCEntity extends ecs.Entity { * 移除单例子实体 * @param cls 单例子实体类 */ - removeChildSingleton(cls: EntityCtor): void { + removeChildSingleton(cls: OopsFramework.EntityCtor): void { if (!this.singletons) return; const entity = this.singletons.get(cls); @@ -84,8 +83,8 @@ export abstract class CCEntity extends ecs.Entity { * @returns 预制体节点,如果实体已销毁则返回 null */ async addPrefab( - ctor: ViewCtor, - parent: View, + ctor: OopsFramework.ViewCtor, + parent: OopsFramework.View, path?: string, bundleName?: string ): Promise { @@ -138,7 +137,7 @@ export abstract class CCEntity extends ecs.Entity { * 移除预制体组件及其节点 * @param node 要销毁的节点或组件(Node 或 GameComponent) */ - removePrefab(node: View): void { + removePrefab(node: OopsFramework.View): void { if (node instanceof GameComponent) { node.remove(); } @@ -153,7 +152,7 @@ export abstract class CCEntity extends ecs.Entity { * @param params 界面参数 * @returns 界面节点,如果实体已销毁则返回 null */ - async addUi(ctor: UICtor, params?: UIParam): Promise { + async addUi(ctor: OopsFramework.UICtor, params?: UIParam): Promise { const key = gui.internal.getKey(ctor); if (!key) { throw new Error(`${ctor.name} 界面组件未使用 gui.register 注册`); @@ -191,7 +190,7 @@ export abstract class CCEntity extends ecs.Entity { * 移除视图层组件 * @param ctor 界面逻辑组件(支持 CCView 或使用 gui.register 注册的 GameComponent 子类) */ - removeUi(ctor: UICtor) { + removeUi(ctor: OopsFramework.UICtor) { const key = gui.internal.getKey(ctor); if (key) { @@ -229,13 +228,13 @@ export abstract class CCEntity extends ecs.Entity { //#region 游戏业务层管理 /** 模块业务逻辑组件集合(key: 业务类构造函数,value: 业务实例) */ - private businesss: Map> = null!; + private businesss: Map> = null!; /** * 批量添加业务逻辑组件 * @param clss 业务逻辑组件类数组 */ - addBusinesss(...clss: BusinessCtor[]) { + addBusinesss(...clss: OopsFramework.BusinessCtor[]) { for (const ctor of clss) { this.addBusiness(ctor); } @@ -246,7 +245,7 @@ export abstract class CCEntity extends ecs.Entity { * @param cls 业务逻辑组件类 * @returns 业务逻辑组件实例 */ - addBusiness>(cls: BusinessCtor): T { + addBusiness>(cls: OopsFramework.BusinessCtor): T { if (this.businesss == null) this.businesss = new Map(); if (this.businesss.has(cls)) { console.error(`${cls.name} 业务逻辑组件已存在`); @@ -269,7 +268,7 @@ export abstract class CCEntity extends ecs.Entity { * @param cls 业务逻辑组件类 * @returns 业务逻辑组件实例,不存在则返回 null */ - getBusiness>(cls: BusinessCtor): T { + getBusiness>(cls: OopsFramework.BusinessCtor): T { if (!this.businesss) return null!; return (this.businesss.get(cls) as T) || null!; } @@ -278,7 +277,7 @@ export abstract class CCEntity extends ecs.Entity { * 移除业务逻辑组件 * @param cls 业务逻辑组件类 */ - removeBusiness>(cls: BusinessCtor): void { + removeBusiness>(cls: OopsFramework.BusinessCtor): void { if (this.businesss) { const business = this.businesss.get(cls); if (business) { diff --git a/assets/module/decorator/GamePrefabDecorator.ts b/assets/module/decorator/GamePrefabDecorator.ts index 7634107..0a7f051 100644 --- a/assets/module/decorator/GamePrefabDecorator.ts +++ b/assets/module/decorator/GamePrefabDecorator.ts @@ -1,5 +1,4 @@ import { resLoader } from '../../core/common/loader/ResLoader'; -import { GameComponentCtor } from '../../types/Module'; /** * 游戏装饰器命名空间 @@ -22,8 +21,8 @@ export namespace prefab { * await entity.addPrefab(V_Backpack_Prop, parentNode); * ``` */ - export function register(path: string, bundleName?: string): (ctor: GameComponentCtor) => void { - return function (ctor: GameComponentCtor): void { + export function register(path: string, bundleName?: string): (ctor: OopsFramework.GameComponentCtor) => void { + return function (ctor: OopsFramework.GameComponentCtor): void { const bundle = bundleName || resLoader.defaultBundleName; const c = ctor as any; c.GAME_PREFAB_PATH = path; diff --git a/assets/types/Module.d.ts b/assets/types/Module.d.ts index 419f260..27c2462 100644 --- a/assets/types/Module.d.ts +++ b/assets/types/Module.d.ts @@ -10,31 +10,35 @@ import type { CCBusiness } from 'db://oops-framework/module/common/CCBusiness'; /** 通用构造函数类型 */ type Ctor = new (...args: any[]) => T; -// ==================== 视图类型 ==================== +declare global { + namespace OopsFramework { + // ==================== 视图类型 ==================== -/** GameComponent 及其子类的构造函数类型,用于类型安全的组件实例化 */ -export type GameComponentCtor = Ctor; + /** GameComponent 及其子类的构造函数类型,用于类型安全的组件实例化 */ + type GameComponentCtor = Ctor; -/** UI 组件构造函数类型(用于继承自 GameComponent 并使用 gui.register 注册的组件) */ -export type UICtor = Ctor; + /** UI 组件构造函数类型(用于继承自 GameComponent 并使用 gui.register 注册的组件) */ + type UICtor = Ctor; -/** 通用的视图组件构造函数类型(支持 ECSView 或 GameComponent) */ -export type ViewCtor = Ctor; + /** 通用的视图组件构造函数类型(支持 ECSView 或 GameComponent) */ + type ViewCtor = Ctor; -/** ECS 游戏视图组件类型(继承自 CCView,用于完整的 ECS 组件) */ -export type ECSView = CCView; + /** ECS 游戏视图组件类型(继承自 CCView,用于完整的 ECS 组件) */ + type ECSView = CCView; -/** 视图节点类型(Node 或 GameComponent) */ -export type View = Node | GameComponent; + /** 视图节点类型(Node 或 GameComponent) */ + type View = Node | GameComponent; -// ==================== 实体类型 ==================== + // ==================== 实体类型 ==================== -/** ECS 实体构造函数类型 */ -export type EntityCtor = Ctor; + /** ECS 实体构造函数类型 */ + type EntityCtor = Ctor; -// ==================== 业务逻辑类型 ==================== + // ==================== 业务逻辑类型 ==================== -/** ECS 业务逻辑组件构造函数类型 */ -export type BusinessCtor = CCBusiness> = Ctor; + /** ECS 业务逻辑组件构造函数类型 */ + type BusinessCtor = CCBusiness> = Ctor; + } +} export {};