DP-S-Script/Dps_A/BaseClass/ConfigClass/ConfigClass.nut

47 lines
1.1 KiB
Plaintext

/*
文件名:ConfigClass.nut
路径:Dps_A/BaseClass/ConfigClass/ConfigClass.nut
创建日期:2025-03-29 23:54
文件用途:全局配置类
*/
class _GlobalConfig {
ConfigMap = null;
constructor() {
//在全局中注册自己
getroottable().GlobalConfig <- this;
ConfigMap = {};
local WorkPath = "/dp_s/OfficialConfig";
local FilePaths = sq_GetListFiles(WorkPath);
foreach(FilePath in FilePaths) {
try {
LoadJson(FilePath, WorkPath + "/" + FilePath);
} catch (exception) {
error("加载配置文件失败:" + FilePath);
}
}
//开启热重载配置
GameManager.OpenHotFix("/dp_s/OfficialConfig");
}
function LoadJson(FilePath, Path) {
local Config = sq_ReadJsonFile(Path);
if (Config) {
ConfigMap.rawset(FilePath, Config);
}
}
function Get(ConfigName) {
if (ConfigMap.rawin(ConfigName)) {
return ConfigMap[ConfigName];
} else {
return null;
}
}
}
_GlobalConfig();