You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.9 KiB
45 lines
1.9 KiB
|
3 weeks ago
|
import { DEV } from 'cc/env';
|
||
|
|
import MTools from 'db://assets/mx/tools/MTools';
|
||
|
|
import { sdkConfig } from '../sdk/sdkConfig';
|
||
|
|
|
||
|
|
const CONFIG_DECRYPT_KEY = 'ZYZTGAMEHKCX2025SSHH12345678ZYZT';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 按客户端版本从服务器拉取配表 bin,成功则覆盖本地表;失败则沿用 bundle 内配置。
|
||
|
|
* 构建插件生成 bin 后由策划上传服务器,configname = name + vsion。
|
||
|
|
*/
|
||
|
|
export function fetchHotUpdateTables(): Promise<Record<string, unknown> | null> {
|
||
|
|
if (DEV) {
|
||
|
|
return Promise.resolve(null);
|
||
|
|
}
|
||
|
|
|
||
|
|
const configName = `${sdkConfig.config.name}${sdkConfig.config.vsion}`;
|
||
|
|
return new Promise((resolve) => {
|
||
|
|
ZYSDK.ZYSDK.getGameConfig(configName, (res) => {
|
||
|
|
try {
|
||
|
|
if (res == null || res === '') {
|
||
|
|
console.error('[ConfigHotUpdate] 远端配表为空,使用本地配置');
|
||
|
|
gg.sdk.reportDY('inLevel', '获取章节配置-失败');
|
||
|
|
resolve(null);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const str = ZYSDK.ZYSDK.decryptWithKey(res, CONFIG_DECRYPT_KEY);
|
||
|
|
const data = MTools.decompressJsonData(str);
|
||
|
|
if (data && typeof data === 'object') {
|
||
|
|
const tables = data as Record<string, unknown>;
|
||
|
|
const constRows = Array.isArray(tables.Const) ? tables.Const : [];
|
||
|
|
console.warn('[ConfigHotUpdate] 远端配表覆盖本地', configName, 'Const行数', constRows.length);
|
||
|
|
gg.data.table.applyHotUpdateTables(data);
|
||
|
|
}
|
||
|
|
resolve(data);
|
||
|
|
} catch (error) {
|
||
|
|
console.error('[ConfigHotUpdate] 远端配表解析失败,使用本地配置', String(error));
|
||
|
|
resolve(null);
|
||
|
|
}
|
||
|
|
}, (err) => {
|
||
|
|
console.error('[ConfigHotUpdate] 拉取配表失败,使用本地配置', String(err));
|
||
|
|
resolve(null);
|
||
|
|
});
|
||
|
|
});
|
||
|
|
}
|