diff --git a/AppConfig.yaml b/AppConfig.yaml index 4203649..5fb9788 100644 --- a/AppConfig.yaml +++ b/AppConfig.yaml @@ -1,3 +1,4 @@ open_observe: - address: [address] - access_token: [token] \ No newline at end of file + address: http://test.coldmint.top/ + access_token: 我的Token + org_id: default \ No newline at end of file diff --git a/locals/Log.csv b/locals/Log.csv index 7186f21..8f19f54 100644 --- a/locals/Log.csv +++ b/locals/Log.csv @@ -23,7 +23,7 @@ log_player_packed_scene_not_exist,玩家预制场景不存在。,Player packed s log_exit_the_room_debug,节点{0}退出房间{1}。,"Node {0} exits room {1}.",ノード{0}が部屋{1}を退出します。 log_enter_the_room_debug,节点{0}进入房间{1}。,"Node {0} enters room {1}.",ノード{0}が部屋{1}に入ります。 log_death_info,生物{0}被{1}击败。,"Creature {0} was defeated by {1}.",生物{0}が{1}によって打ち負かされました。 - +log_appConfig_not_exist,您可以在项目根目录创建名为AppConfig.yaml的文件,并在其中配置OpenObserve的数据,以便在游戏发布后持续收集日志和运行数据。,You can create a file named AppConfig.yaml in the project root directory and configure OpenObserve data in it to collect log and run data continuously after the game has been released.,プロジェクトのルートディレクトリにappconfig.yamlというファイルを作成し、そこにOpenObserveのデータを配置して、リリース後も継続的にログや実行データを収集することができます。 log_loot_list_has_no_entries,ID为{0}的战利品表,没有指定条目。,"Loot list with ID {0}, no entry specified.",ID{0}の戦利品テーブルは、エントリ指定されていません。 log_not_within_the_loot_spawn_range,给定的数值{0}没有在战利品{1}的生成范围{2}内。,The given value {0} is not within the spawn range {2} of loot {1}.,与えられた数値{0}は戦利品{1}の生成範囲{2}内にありません。 log_loot_data_quantity,有{0}个战利品数据被返回。,{0} loot data was returned.,{0}個の戦利品データが返されます。 diff --git a/scripts/AppConfig.cs b/scripts/AppConfig.cs new file mode 100644 index 0000000..97c3c5b --- /dev/null +++ b/scripts/AppConfig.cs @@ -0,0 +1,76 @@ +using ColdMint.scripts.debug; +using ColdMint.scripts.openObserve; +using ColdMint.scripts.serialization; +using Godot; + +namespace ColdMint.scripts; + +public class AppConfig +{ + /// + /// Load configuration from file + /// 从文件加载配置 + /// + public static AppConfigData? LoadFromFile() + { + var appConfigExists = FileAccess.FileExists(Config.AppConfigPath); + if (!appConfigExists) + { + LogCat.LogWarning("appConfig_not_exist"); + return null; + } + + var appConfigFileAccess = FileAccess.Open(Config.AppConfigPath, FileAccess.ModeFlags.Read); + var yamlData = appConfigFileAccess.GetAsText(); + appConfigFileAccess.Close(); + return YamlSerialization.Deserialize(yamlData); + } + + + /// + /// ApplyAppConfig + /// 应用配置 + /// + /// + public static void ApplyAppConfig(AppConfigData appConfigData) + { + if (appConfigData.OpenObserve != null) + { + LogCollector.UpdateHttpClient(appConfigData.OpenObserve); + } + } +} + +public class AppConfigData +{ + /// + /// OpenObserve configuration information + /// OpenObserve的配置信息 + /// + public OpenObserve? OpenObserve { get; set; } +} + +/// +/// OpenObserve Configuration information +/// OpenObserve配置信息 +/// +public class OpenObserve +{ + /// + /// server address + /// 服务器地址 + /// + public string? Address { get; set; } + + /// + /// Access Token + /// 访问密匙 + /// + public string? AccessToken { get; set; } + + /// + /// Organization ID + /// 组织ID + /// + public string? OrgId { get; set; } +} \ No newline at end of file diff --git a/scripts/Config.cs b/scripts/Config.cs index fa14572..d626cbb 100644 --- a/scripts/Config.cs +++ b/scripts/Config.cs @@ -85,6 +85,12 @@ public static class Config public const string Aborigines = "Aborigines"; } + /// + /// Path of the App configuration file + /// App配置文件路径 + /// + public const string AppConfigPath = "res://AppConfig.yaml"; + /// /// The percentage of speed reduced after a thrown item hits an enemy /// 抛出的物品击中敌人后减少的速度百分比 diff --git a/scripts/debug/LogCat.cs b/scripts/debug/LogCat.cs index b59e859..4c89bd3 100644 --- a/scripts/debug/LogCat.cs +++ b/scripts/debug/LogCat.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using ColdMint.scripts.openObserve; using ColdMint.scripts.utils; using Godot; @@ -206,7 +207,13 @@ public static class LogCat return; } - GD.Print(HandleMessage(InfoLogLevel, message, label)); + + var msg = HandleMessage(InfoLogLevel, message, label); + var logData = new LogData(); + logData.Message = msg.ToString(); + logData.AppId = "test"; + LogCollector.Push(logData); + GD.Print(msg); } /// diff --git a/scripts/loader/uiLoader/MainMenuLoader.cs b/scripts/loader/uiLoader/MainMenuLoader.cs index 5c19867..b4fe177 100644 --- a/scripts/loader/uiLoader/MainMenuLoader.cs +++ b/scripts/loader/uiLoader/MainMenuLoader.cs @@ -20,148 +20,154 @@ namespace ColdMint.scripts.loader.uiLoader; /// public partial class MainMenuLoader : UiLoaderTemplate { - private Button? _startGameButton; - private Label? _copyrightLabel; - private StringBuilder? _copyrightBuilder; - private PackedScene? _gameScene; - private PackedScene? _contributor; - private PackedScene? _levelGraphEditor; - private Label? _sloganLabel; - private Label? _versionLabel; - private Button? _levelGraphEditorButton; - private LinkButton? _contributorButton; + private Button? _startGameButton; + private Label? _copyrightLabel; + private StringBuilder? _copyrightBuilder; + private PackedScene? _gameScene; + private PackedScene? _contributor; + private PackedScene? _levelGraphEditor; + private Label? _sloganLabel; + private Label? _versionLabel; + private Button? _levelGraphEditorButton; + private LinkButton? _contributorButton; - public override void InitializeData() - { - if (Config.IsDebug()) - { - //Set the minimum log level to Info in debug mode.(Print all logs) - //在调试模式下将最小日志等级设置为Info。(打印全部日志) - LogCat.MinLogLevel = LogCat.InfoLogLevel; - } - else - { - //Disable all logs in the release version. - //在发行版禁用所有日志。 - LogCat.MinLogLevel = LogCat.DisableAllLogLevel; - } + public override void InitializeData() + { + AppConfigData? appConfigData = AppConfig.LoadFromFile(); + if (appConfigData != null) + { + AppConfig.ApplyAppConfig(appConfigData); + } - ContributorDataManager.RegisterAllContributorData(); - DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler()); - MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor()); - MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor()); - //Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package - //注册对应的编码提供程序,解决压缩包中文路径乱码问题 - Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); - //创建游戏数据文件夹 - var dataPath = Config.GetGameDataDirectory(); - if (!Directory.Exists(dataPath)) - { - Directory.CreateDirectory(dataPath); - } + if (Config.IsDebug()) + { + //Set the minimum log level to Info in debug mode.(Print all logs) + //在调试模式下将最小日志等级设置为Info。(打印全部日志) + LogCat.MinLogLevel = LogCat.InfoLogLevel; + } + else + { + //Disable all logs in the release version. + //在发行版禁用所有日志。 + LogCat.MinLogLevel = LogCat.DisableAllLogLevel; + } + + ContributorDataManager.RegisterAllContributorData(); + DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler()); + MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor()); + MapGenerator.RegisterRoomInjectionProcessor(new TimeIntervalRoomInjectorProcessor()); + //Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package + //注册对应的编码提供程序,解决压缩包中文路径乱码问题 + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + //创建游戏数据文件夹 + var dataPath = Config.GetGameDataDirectory(); + if (!Directory.Exists(dataPath)) + { + Directory.CreateDirectory(dataPath); + } - //Registered camp - //注册阵营 - var defaultCamp = new Camp(Config.CampId.Default) - { - FriendInjury = true - }; - CampManager.SetDefaultCamp(defaultCamp); - var mazoku = new Camp(Config.CampId.Mazoku); - CampManager.AddCamp(mazoku); - var aborigines = new Camp(Config.CampId.Aborigines); - CampManager.AddCamp(aborigines); - _gameScene = GD.Load("res://scenes/game.tscn"); - _contributor = GD.Load("res://scenes/contributor.tscn"); - _levelGraphEditor = GD.Load("res://scenes/levelGraphEditor.tscn"); + //Registered camp + //注册阵营 + var defaultCamp = new Camp(Config.CampId.Default) + { + FriendInjury = true + }; + CampManager.SetDefaultCamp(defaultCamp); + var mazoku = new Camp(Config.CampId.Mazoku); + CampManager.AddCamp(mazoku); + var aborigines = new Camp(Config.CampId.Aborigines); + CampManager.AddCamp(aborigines); + _gameScene = GD.Load("res://scenes/game.tscn"); + _contributor = GD.Load("res://scenes/contributor.tscn"); + _levelGraphEditor = GD.Load("res://scenes/levelGraphEditor.tscn"); - //Register ItemTypes from file - //从文件注册物品类型 - ItemTypeRegister.RegisterFromFile(); - //Hardcoded ItemTypes Register - //硬编码注册物品类型 - ItemTypeRegister.StaticRegister(); + //Register ItemTypes from file + //从文件注册物品类型 + ItemTypeRegister.RegisterFromFile(); + //Hardcoded ItemTypes Register + //硬编码注册物品类型 + ItemTypeRegister.StaticRegister(); - //静态注册掉落表 - LootRegister.StaticRegister(); - } + //静态注册掉落表 + LootRegister.StaticRegister(); + } - public override void InitializeUi() - { - _contributorButton = GetNode("VBoxContainer2/ContributorButton"); - _startGameButton = GetNode