239 lines
8.4 KiB
C#
239 lines
8.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using SGModule.Common.Extensions;
|
|
using SGModule.Common.Helper;
|
|
using SGModule.ConfigLoader;
|
|
using SGModule.NetKit;
|
|
using UnityEngine;
|
|
|
|
namespace RedHotRoast {
|
|
public class ConfigSystem : BaseSystem {
|
|
public static string web_through_str;
|
|
public static List<GameUrls> light_weblist = new List<GameUrls>();
|
|
public static List<GameUrls> dark_weblist = new List<GameUrls>();
|
|
|
|
public ConfigSystem(bool isAutoInit = true) {
|
|
if (isAutoInit) {
|
|
Init();
|
|
}
|
|
}
|
|
|
|
public sealed override void Init() {
|
|
base.Init();
|
|
AddListener();
|
|
}
|
|
|
|
private void AddListener() {
|
|
NetworkDispatcher.Instance.AddListener(NetworkMsg.GetConfig, OnGetConfig);
|
|
}
|
|
|
|
private void RemoveListener() {
|
|
NetworkDispatcher.Instance.RemoveListener(NetworkMsg.GetConfig, OnGetConfig);
|
|
}
|
|
|
|
private void OnGetConfig(object obj) {
|
|
TrackKit.TrackLoginFunnel(LoginFunnelEventType.LoadBegin); //加载开始打点
|
|
|
|
var loginModel = LoginKit.Instance.LoginModel;
|
|
ConfigLoader.Instance.Init(new ConfigInitOptions {
|
|
Setting = loginModel.Setting,
|
|
CdnUrl = loginModel.CdnURL,
|
|
OnComplete = state => {
|
|
Debug.Log($"配置加载状态{state}");
|
|
if (state == ConfigLoaderState.Successful) {
|
|
ReloadConfig();
|
|
}
|
|
},
|
|
OnError = (errorName, message) => {
|
|
Debug.LogError($"配置解析错误 {errorName} 错误信息:{message}");
|
|
},
|
|
OnHandleUnmarkedConfig = ParseGameConfig
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重新加载配置
|
|
/// </summary>
|
|
/// <param name="json"></param>
|
|
private void ReloadConfig() {
|
|
var CdnURL = "https://asserts.minskyfun.top";
|
|
|
|
TrackKit.TrackLoginFunnel(LoginFunnelEventType.LoadFinish); //加载完成打点
|
|
|
|
TextureHelper.imgUrl = CdnURL + "/" + GetConfigResVersion() + "/";
|
|
LiveVideoManager.videoBaseUrl = CdnURL + "/" + GetConfigResVersion() + "/";
|
|
|
|
// ParseGameConfig();
|
|
UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.NetLoadingUI_Close);
|
|
AppDispatcher.Instance.Dispatch(AppMsg.LoginInit);
|
|
CtrlDispatcher.Instance.Dispatch(CtrlMsg.Game_StartBefore);
|
|
SaveingPotHelper.ResetHistory();
|
|
}
|
|
|
|
|
|
#region 游戏配置
|
|
|
|
private void ParseGameConfig() {
|
|
var gameConfigModel = new GameConfigModel();
|
|
foreach (var key in ConfigLoader.Instance.GetJsonKeys()) {
|
|
if (!key.StartsWith("GameBoard")) {
|
|
continue;
|
|
}
|
|
|
|
// 提取 boardIndex
|
|
var boardIndex = 1;
|
|
var parts = key.Split('_');
|
|
if (parts.Length > 1 && int.TryParse(parts[1], out var parsed)) {
|
|
boardIndex = parsed;
|
|
}
|
|
|
|
// 获取 json 并反序列化
|
|
if (ConfigLoader.Instance.TryGetJsonValue(key, out var gameboardJson)) {
|
|
try {
|
|
var gameBoards = gameboardJson.As<List<GameBoard>>();
|
|
if (gameBoards != null) {
|
|
gameConfigModel.game_conf[boardIndex] = gameBoards;
|
|
}
|
|
else {
|
|
Log.ConfigLoader.Warning($"GameBoard 配置 {key} 反序列化为空");
|
|
}
|
|
}
|
|
catch (Exception ex) {
|
|
Log.ConfigLoader.Error($"GameBoard 配置 {key} 反序列化失败: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
|
|
ConfigLoader.Instance.AddConfig(gameConfigModel);
|
|
|
|
|
|
SetGameUrlConfig();
|
|
}
|
|
|
|
private static List<GameUrls> data_new;
|
|
public static void SetGameUrlConfig()
|
|
{
|
|
|
|
|
|
light_weblist.Clear();
|
|
dark_weblist.Clear();
|
|
web_through_str = "";
|
|
data_new = GetConfig<GameUrls>();
|
|
List<int> type_list = new List<int>();
|
|
for (int i = 0; i < data_new.Count; i++)
|
|
{
|
|
|
|
if (data_new[i].webType == 2)
|
|
{
|
|
if (GameHelper.IsGiftSwitch() && (data_new[i].isMagic == 1)) light_weblist.Add(data_new[i]);
|
|
else if (!GameHelper.IsGiftSwitch() && (data_new[i].isMagic == 0)) light_weblist.Add(data_new[i]);
|
|
}
|
|
else
|
|
{
|
|
dark_weblist.Add(data_new[i]);
|
|
if (!type_list.Contains(data_new[i].wvType))
|
|
{
|
|
web_through_str += data_new[i].wvthrough;
|
|
web_through_str += "|";
|
|
type_list.Add(data_new[i].wvType);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
web_through_str.Remove(web_through_str.Length - 1);
|
|
|
|
Debug.Log("light_weblist-----" + light_weblist.Count);
|
|
Debug.Log("dark_weblist-----"+ dark_weblist.Count);
|
|
Debug.Log("////////////////////////");
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
public static CommonModel GetCommonConf() {
|
|
return ConfigLoader.Instance.GetConfig<CommonModel>();
|
|
}
|
|
|
|
public static List<T> GetConfig<T>() where T : class {
|
|
return ConfigLoader.Instance.GetConfig<List<T>>() ?? new List<T>();
|
|
}
|
|
|
|
public static bool IsOrganic()
|
|
{
|
|
bool b = false;
|
|
|
|
if (GameHelper.IsGiftSwitch())
|
|
{
|
|
if (SuperApplication.Instance.attribution == "organic")
|
|
{
|
|
b = GetCommonConf().non == 1;
|
|
}
|
|
}
|
|
|
|
// Debug.Log($"下载---------开关:{b} non: {GetCommonConf().non}");
|
|
return b;
|
|
}
|
|
|
|
private static List<T> GetConfigWithOrganicFallback<T, TOrganic>() where T : class
|
|
{
|
|
if (IsOrganic())
|
|
{
|
|
var organicConfig = ConfigLoader.Instance.GetConfig<List<TOrganic>>();
|
|
if (organicConfig != null)
|
|
{
|
|
var json = Newtonsoft.Json.JsonConvert.SerializeObject(organicConfig);
|
|
return Newtonsoft.Json.JsonConvert.DeserializeObject<List<T>>(json);
|
|
}
|
|
}
|
|
|
|
return GetConfig<T>();
|
|
}
|
|
|
|
public static string GetConfigResVersion()
|
|
{
|
|
return IsOrganic() ? GetCommonConf().ResVersion1 : GetCommonConf().ResVersion;
|
|
}
|
|
|
|
public static List<Live> GetLiveConfig()
|
|
{
|
|
return GetConfigWithOrganicFallback<Live, Live_A>();
|
|
}
|
|
|
|
public static List<SecretAlbums> GetSecretAlbumsConfig()
|
|
{
|
|
return GetConfigWithOrganicFallback<SecretAlbums, SecretAlbums_A>();
|
|
}
|
|
public static List<FreeImageLibrary> GetFreeImageConfig()
|
|
{
|
|
return GetConfigWithOrganicFallback<FreeImageLibrary, FreeImageLibrary_A>();
|
|
}
|
|
public static List<ADImageLibrary> GetADImageConfig()
|
|
{
|
|
return GetConfigWithOrganicFallback<ADImageLibrary, ADImageLibrary_A>();
|
|
}
|
|
|
|
public static List<SpecialImageLibrary> GetSpecialImageConfig()
|
|
{
|
|
return GetConfigWithOrganicFallback<SpecialImageLibrary, SpecialImageLibrary_A>();
|
|
}
|
|
|
|
public static List<VIPImageLibrary> GetVIPImageConfig()
|
|
{
|
|
return GetConfigWithOrganicFallback<VIPImageLibrary, VIPImageLibrary_A>();
|
|
}
|
|
|
|
public static List<LevelUnlock> GetLevelUnlockConfig()
|
|
{
|
|
return GetConfigWithOrganicFallback<LevelUnlock, LevelUnlock_A>();
|
|
}
|
|
|
|
|
|
public override void Dispose() {
|
|
base.Dispose();
|
|
RemoveListener();
|
|
}
|
|
}
|
|
}
|