223 lines
7.2 KiB
C#
223 lines
7.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using IgnoreOPS;
|
|
using SGModule.Common.Extensions;
|
|
using SGModule.Common.Helper;
|
|
using SGModule.ConfigLoader;
|
|
using SGModule.NetKit;
|
|
using UnityEngine;
|
|
using CommonModel = IgnoreOPS.CommonModel;
|
|
|
|
namespace BallKingdomCrush
|
|
{
|
|
public class ConfigSystem : BaseSystem
|
|
{
|
|
public static string web_through_str;
|
|
|
|
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;
|
|
Log.Info("Config", $"服务器传过来的配置表:{loginModel.Setting}");
|
|
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); //加载完成打点
|
|
|
|
ParseGameConfig();
|
|
TextureHelper.imgUrl = CdnURL + "/" + GetConfigResVersion() + "/";
|
|
LiveVideoManager.videoBaseUrl = CdnURL + "/" + GetConfigResVersion() + "/";
|
|
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);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
public static CommonModel GetCommonConf()
|
|
{
|
|
return ConfigLoader.Instance.GetConfig<CommonModel>();
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns>true:非自然 false:自然</returns>
|
|
public static bool IsOrganic()
|
|
{
|
|
bool b = false;
|
|
|
|
if (GameHelper.IsGiftSwitch() && SuperApplication.Instance.attribution == "organic")
|
|
{
|
|
b = GetCommonConf().IsOrganic == 1;
|
|
}
|
|
|
|
Debug.Log($"下载---------开关:{b}");
|
|
return b;
|
|
}
|
|
|
|
public static string GetConfigResVersion()
|
|
{
|
|
return IsOrganic() ? GetCommonConf().ResVersion : GetCommonConf().ResVersion1;
|
|
}
|
|
|
|
public static List<T> GetConfig<T>() where T : class
|
|
{
|
|
return ConfigLoader.Instance.GetConfig<List<T>>() ?? new List<T>();
|
|
}
|
|
|
|
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 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();
|
|
}
|
|
}
|
|
} |