mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-06-07 18:52:23 +08:00
修改框架配置格式,支持分组设置游戏配置,方便开发、测试、生产环境切换
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2023-08-28 10:02:57
|
||||
*/
|
||||
import { _decorator, Component, director, Game, game, JsonAsset, Node, resources, screen, sys } from "cc";
|
||||
import { _decorator, Component, director, Game, game, JsonAsset, Node, profiler, resources, screen, sys } from "cc";
|
||||
import { GameConfig } from "../module/config/GameConfig";
|
||||
import { GameQueryConfig } from "../module/config/GameQueryConfig";
|
||||
import { oops, version } from "./Oops";
|
||||
@@ -94,6 +94,8 @@ export class Root extends Component {
|
||||
//@ts-ignore
|
||||
oops.gui.initLayer(this.gui, config.json.gui);
|
||||
|
||||
// 初始化统计信息
|
||||
oops.config.game.stats ? profiler.showStats() : profiler.hideStats();
|
||||
// 初始化每秒传输帧数
|
||||
game.frameRate = oops.config.game.frameRate;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ const keys = (Object.keys(buildTimeConstants) as (keyof typeof buildTimeConstant
|
||||
|
||||
/* 游戏运行环境 */
|
||||
export class BuildTimeConstants {
|
||||
constructor() {
|
||||
toString() {
|
||||
const keyNameMaxLen = keys.reduce((len, key) => Math.max(len, key.length), 0);
|
||||
const enviroment = `${keys.map((key) => {
|
||||
const value = buildTimeConstants[key];
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
* @LastEditTime: 2022-11-01 15:47:16
|
||||
*/
|
||||
|
||||
import { BuildTimeConstants } from "./BuildTimeConstants";
|
||||
import { GameConfig } from "./GameConfig";
|
||||
import { GameQueryConfig } from "./GameQueryConfig";
|
||||
|
||||
/** 游戏配置静态访问类 */
|
||||
export class Config {
|
||||
/** 环境常量 */
|
||||
// btc!: BuildTimeConstants;
|
||||
btc: BuildTimeConstants = new BuildTimeConstants();
|
||||
|
||||
/** 游戏配置数据,版本号、支持语种等数据 */
|
||||
game!: GameConfig;
|
||||
|
||||
@@ -20,27 +20,55 @@ export enum GameConfigCustomType {
|
||||
export class GameConfig {
|
||||
/** 客户端版本号配置 */
|
||||
get version(): string {
|
||||
return this._data.config.version;
|
||||
}
|
||||
/** 游戏每秒传输帧数 */
|
||||
get frameRate(): number {
|
||||
return this._data.config.frameRate;
|
||||
return this.data.version;
|
||||
}
|
||||
/** 本地存储内容加密 key */
|
||||
get localDataKey(): string {
|
||||
return this._data.config.localDataKey;
|
||||
return this.data.localDataKey;
|
||||
}
|
||||
/** 本地存储内容加密 iv */
|
||||
get localDataIv(): string {
|
||||
return this._data.config.localDataIv;
|
||||
return this.data.localDataIv;
|
||||
}
|
||||
/** 游戏每秒传输帧数 */
|
||||
get frameRate(): number {
|
||||
return this.data.frameRate;
|
||||
}
|
||||
/** 是否开启移动设备安全区域适配 */
|
||||
get mobileSafeArea(): boolean {
|
||||
return this.data.mobileSafeArea || false;
|
||||
}
|
||||
/** 加载界面资源超时提示 */
|
||||
get loadingTimeoutGui(): number {
|
||||
return this.data.loadingTimeoutGui || 1000;
|
||||
}
|
||||
/** 是否显示统计信息 */
|
||||
get stats(): number {
|
||||
return this.data.stats;
|
||||
}
|
||||
/** Http 服务器地址 */
|
||||
get httpServer(): string {
|
||||
return this._data.config.httpServer;
|
||||
return this.data.httpServer;
|
||||
}
|
||||
/** Http 请求超时时间 */
|
||||
get httpTimeout(): number {
|
||||
return this._data.config.httpTimeout;
|
||||
return this.data.httpTimeout;
|
||||
}
|
||||
/** WebSocket 服务器地址 */
|
||||
get webSocketServer(): string {
|
||||
return this.data.webSocketServer;
|
||||
}
|
||||
/** WebSocket 心跳间隔时间(毫秒) */
|
||||
get webSocketHeartTime(): number {
|
||||
return this.data.webSocketHeartTime;
|
||||
}
|
||||
/** WebSocket 指定时间没收到消息就断开连接(毫秒) */
|
||||
get webSocketReceiveTime(): number {
|
||||
return this.data.webSocketReceiveTime;
|
||||
}
|
||||
/** WebSocket 重连间隔时间(毫秒) */
|
||||
get webSocketReconnetTimeOut(): number {
|
||||
return this.data.webSocketReconnetTimeOut;
|
||||
}
|
||||
|
||||
/** 获取当前客户端支持的语言类型 */
|
||||
@@ -65,40 +93,26 @@ export class GameConfig {
|
||||
return this._data.bundle.default;
|
||||
}
|
||||
|
||||
/** 加载界面资源超时提示 */
|
||||
get loadingTimeoutGui(): number {
|
||||
return this._data.config.loadingTimeoutGui || 1000;
|
||||
}
|
||||
|
||||
/** 是否开启移动设备安全区域适配 */
|
||||
get mobileSafeArea(): boolean {
|
||||
return this._data.config.mobileSafeArea || false;
|
||||
}
|
||||
|
||||
private _data: any = null;
|
||||
/** 游戏配置数据 */
|
||||
get data(): any {
|
||||
return this._data;
|
||||
return this._data.config[this._configType];
|
||||
}
|
||||
|
||||
/** 当前游戏配置分组类型 */
|
||||
private _configType: GameConfigCustomType = GameConfigCustomType.Prod;
|
||||
|
||||
constructor(config: any) {
|
||||
this._data = Object.freeze(config.json);
|
||||
|
||||
this.setConfigType(this._data.type);
|
||||
oops.log.logConfig(this._data, "游戏配置");
|
||||
}
|
||||
|
||||
private _customType: GameConfigCustomType = GameConfigCustomType.Dev;
|
||||
|
||||
/**
|
||||
* 设置自定义游戏参数配置类型
|
||||
* 设置游戏参数类型
|
||||
* @param type
|
||||
*/
|
||||
setCustomType(type: GameConfigCustomType) {
|
||||
this._customType = type;
|
||||
}
|
||||
|
||||
/** 获取游戏自定义配置 */
|
||||
get custom(): any {
|
||||
return this.data.custom[this._customType];
|
||||
setConfigType(type: GameConfigCustomType) {
|
||||
this._configType = type;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user