mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-19 06:31:54 +08:00
统一框架中d.ts文件风格
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
@@ -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<EntityCtor, ECSEntity> = null!;
|
||||
private singletons: Map<OopsFramework.EntityCtor, ECSEntity> = null!;
|
||||
|
||||
/**
|
||||
* 批量添加单例子实体
|
||||
* @param clss 单例子实体类数组
|
||||
*/
|
||||
addChildSingletons<T extends CCEntity>(...clss: EntityCtor<T>[]): void {
|
||||
addChildSingletons<T extends CCEntity>(...clss: OopsFramework.EntityCtor<T>[]): void {
|
||||
for (const ctor of clss) {
|
||||
this.addChildSingleton<T>(ctor);
|
||||
}
|
||||
@@ -33,7 +32,7 @@ export abstract class CCEntity extends ecs.Entity {
|
||||
* @param cls 单例子实体类
|
||||
* @returns 单例子实体
|
||||
*/
|
||||
addChildSingleton<T extends CCEntity>(cls: EntityCtor<T>): T {
|
||||
addChildSingleton<T extends CCEntity>(cls: OopsFramework.EntityCtor<T>): 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<T extends CCEntity>(cls: EntityCtor<T>): T {
|
||||
getChildSingleton<T extends CCEntity>(cls: OopsFramework.EntityCtor<T>): 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<T extends CCEntity>(cls: EntityCtor<T>): void {
|
||||
removeChildSingleton<T extends CCEntity>(cls: OopsFramework.EntityCtor<T>): 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<T extends GameComponent>(
|
||||
ctor: ViewCtor<T>,
|
||||
parent: View,
|
||||
ctor: OopsFramework.ViewCtor<T>,
|
||||
parent: OopsFramework.View,
|
||||
path?: string,
|
||||
bundleName?: string
|
||||
): Promise<Node | null> {
|
||||
@@ -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<T extends GameComponent>(ctor: UICtor<T>, params?: UIParam): Promise<Node | null> {
|
||||
async addUi<T extends GameComponent>(ctor: OopsFramework.UICtor<T>, params?: UIParam): Promise<Node | null> {
|
||||
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<BusinessCtor, CCBusiness<CCEntity>> = null!;
|
||||
private businesss: Map<OopsFramework.BusinessCtor, CCBusiness<CCEntity>> = 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<T extends CCBusiness<CCEntity>>(cls: BusinessCtor<T>): T {
|
||||
addBusiness<T extends CCBusiness<CCEntity>>(cls: OopsFramework.BusinessCtor<T>): 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<T extends CCBusiness<CCEntity>>(cls: BusinessCtor<T>): T {
|
||||
getBusiness<T extends CCBusiness<CCEntity>>(cls: OopsFramework.BusinessCtor<T>): 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<T extends CCBusiness<CCEntity>>(cls: BusinessCtor<T>): void {
|
||||
removeBusiness<T extends CCBusiness<CCEntity>>(cls: OopsFramework.BusinessCtor<T>): void {
|
||||
if (this.businesss) {
|
||||
const business = this.businesss.get(cls);
|
||||
if (business) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
38
assets/types/Module.d.ts
vendored
38
assets/types/Module.d.ts
vendored
@@ -10,31 +10,35 @@ import type { CCBusiness } from 'db://oops-framework/module/common/CCBusiness';
|
||||
/** 通用构造函数类型 */
|
||||
type Ctor<T = any> = new (...args: any[]) => T;
|
||||
|
||||
// ==================== 视图类型 ====================
|
||||
declare global {
|
||||
namespace OopsFramework {
|
||||
// ==================== 视图类型 ====================
|
||||
|
||||
/** GameComponent 及其子类的构造函数类型,用于类型安全的组件实例化 */
|
||||
export type GameComponentCtor<T extends GameComponent = GameComponent> = Ctor<T>;
|
||||
/** GameComponent 及其子类的构造函数类型,用于类型安全的组件实例化 */
|
||||
type GameComponentCtor<T extends GameComponent = GameComponent> = Ctor<T>;
|
||||
|
||||
/** UI 组件构造函数类型(用于继承自 GameComponent 并使用 gui.register 注册的组件) */
|
||||
export type UICtor<T extends GameComponent = GameComponent> = Ctor<T>;
|
||||
/** UI 组件构造函数类型(用于继承自 GameComponent 并使用 gui.register 注册的组件) */
|
||||
type UICtor<T extends GameComponent = GameComponent> = Ctor<T>;
|
||||
|
||||
/** 通用的视图组件构造函数类型(支持 ECSView 或 GameComponent) */
|
||||
export type ViewCtor<T extends GameComponent | ecs.Comp = GameComponent | ecs.Comp> = Ctor<T>;
|
||||
/** 通用的视图组件构造函数类型(支持 ECSView 或 GameComponent) */
|
||||
type ViewCtor<T extends GameComponent | ecs.Comp = GameComponent | ecs.Comp> = Ctor<T>;
|
||||
|
||||
/** ECS 游戏视图组件类型(继承自 CCView,用于完整的 ECS 组件) */
|
||||
export type ECSView = CCView<CCEntity>;
|
||||
/** ECS 游戏视图组件类型(继承自 CCView,用于完整的 ECS 组件) */
|
||||
type ECSView = CCView<CCEntity>;
|
||||
|
||||
/** 视图节点类型(Node 或 GameComponent) */
|
||||
export type View = Node | GameComponent;
|
||||
/** 视图节点类型(Node 或 GameComponent) */
|
||||
type View = Node | GameComponent;
|
||||
|
||||
// ==================== 实体类型 ====================
|
||||
// ==================== 实体类型 ====================
|
||||
|
||||
/** ECS 实体构造函数类型 */
|
||||
export type EntityCtor<T extends CCEntity = CCEntity> = Ctor<T>;
|
||||
/** ECS 实体构造函数类型 */
|
||||
type EntityCtor<T extends CCEntity = CCEntity> = Ctor<T>;
|
||||
|
||||
// ==================== 业务逻辑类型 ====================
|
||||
// ==================== 业务逻辑类型 ====================
|
||||
|
||||
/** ECS 业务逻辑组件构造函数类型 */
|
||||
export type BusinessCtor<T extends CCBusiness<CCEntity> = CCBusiness<CCEntity>> = Ctor<T>;
|
||||
/** ECS 业务逻辑组件构造函数类型 */
|
||||
type BusinessCtor<T extends CCBusiness<CCEntity> = CCBusiness<CCEntity>> = Ctor<T>;
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
|
||||
Reference in New Issue
Block a user