From 13cfa37bf3cca84d60d0c68d8a26901b9678919c Mon Sep 17 00:00:00 2001 From: dgflash Date: Tue, 24 Feb 2026 21:50:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E9=85=8D=E7=BD=AE=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=94=AF=E6=8C=81=E5=BC=BA=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/module/config/GameConfig.ts | 71 +++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/assets/module/config/GameConfig.ts b/assets/module/config/GameConfig.ts index cf7fe49..f6835a5 100644 --- a/assets/module/config/GameConfig.ts +++ b/assets/module/config/GameConfig.ts @@ -16,6 +16,65 @@ export enum GameConfigCustomType { Prod = 'prod', } +/** 框架基础环境配置(dev/test/prod 三类字段相同,仅值不同) */ +export interface IConfigEnvironmentBase { + /** 客户端版本号 */ + version: string; + /** 本地存储内容加密 key */ + localDataKey: string; + /** 本地存储内容加密 iv */ + localDataIv: string; + /** 游戏每秒传输帧数 */ + frameRate: number; + /** 加载界面资源超时提示(毫秒) */ + loadingTimeoutGui: number; + /** 是否开启移动设备安全区域适配 */ + mobileSafeArea: boolean; + /** 是否显示统计信息 */ + stats: boolean; + /** Http 服务器地址 */ + httpServer: string; + /** Http 请求超时时间(毫秒) */ + httpTimeout: number; + /** WebSocket 服务器地址 */ + webSocketServer: string; + /** WebSocket 心跳间隔时间(毫秒) */ + webSocketHeartTime: number; + /** WebSocket 指定时间没收到消息就断开连接(毫秒) */ + webSocketReceiveTime: number; + /** WebSocket 重连间隔时间(毫秒) */ + webSocketReconnetTimeOut: number; +} + +/** 环境配置类型(游戏项目可通过模块增强扩展自定义字段) */ +export interface IConfigEnvironment extends IConfigEnvironmentBase {} + +/** config.json 完整配置结构 */ +export interface IConfigJson { + /** 当前使用的环境类型(dev/test/prod) */ + type: GameConfigCustomType; + /** 各环境配置数据 */ + config: Record; + /** 界面层级配置 */ + gui: Array<{ name: string; type: string }>; + /** 多语言配置 */ + language: { + /** 默认语言 */ + default: string; + /** 支持的语言类型列表 */ + type: string[]; + /** 语言资源路径 */ + path: { json: string; texture: string; spine?: string }; + }; + /** 远程资源包配置 */ + bundle: { default: string }; +} + +/** 资源配置加载器传入的 config 结构 */ +export interface IConfigResource { + json: IConfigJson; +} + /* 游戏配置解析,对应 resources/config/config.json 配置 */ export class GameConfig { /** 客户端版本号配置 */ @@ -43,7 +102,7 @@ export class GameConfig { return this.data.loadingTimeoutGui || 1000; } /** 是否显示统计信息 */ - get stats(): number { + get stats(): boolean { return this.data.stats; } /** Http 服务器地址 */ @@ -93,17 +152,17 @@ export class GameConfig { return this._data.bundle.default; } - private _data: any = null; + private _data!: IConfigJson; /** 游戏配置数据 */ - get data(): any { + get data(): IConfigEnvironment { return this._data.config[this._configType]; } /** 当前游戏配置分组类型 */ private _configType: GameConfigCustomType = GameConfigCustomType.Prod; - constructor(config: any) { - this._data = Object.freeze(config.json); + constructor(config: IConfigResource) { + this._data = Object.freeze(config.json) as IConfigJson; this.setConfigType(this._data.type); oops.log.logConfig(this._data, '游戏配置'); } @@ -115,4 +174,4 @@ export class GameConfig { setConfigType(type: GameConfigCustomType) { this._configType = type; } -} +}