mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-22 17:06:53 +08:00
框架配置数据支持强类型
This commit is contained in:
@@ -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<GameConfigCustomType, IConfigEnvironment>;
|
||||
/** 界面层级配置 */
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user