From c4889d67b642f0f16cbef105cdba6b2477cca3a3 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Sat, 13 Jul 2024 21:05:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4Demo=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ColdMint.Traveler.csproj | 2 + scripts/debug/LogCat.cs | 28 ++- scripts/loader/uiLoader/MainMenuLoader.cs | 263 +++++++++++----------- 3 files changed, 159 insertions(+), 134 deletions(-) diff --git a/ColdMint.Traveler.csproj b/ColdMint.Traveler.csproj index 9ba3342..c8681d1 100644 --- a/ColdMint.Traveler.csproj +++ b/ColdMint.Traveler.csproj @@ -10,6 +10,8 @@ + + \ No newline at end of file diff --git a/scripts/debug/LogCat.cs b/scripts/debug/LogCat.cs index b59e859..c90a570 100644 --- a/scripts/debug/LogCat.cs +++ b/scripts/debug/LogCat.cs @@ -3,6 +3,9 @@ using System.Collections.Generic; using System.Text; using ColdMint.scripts.utils; using Godot; +using Microsoft.Extensions.Logging; +using OpenTelemetry.Exporter; +using OpenTelemetry.Logs; namespace ColdMint.scripts.debug; @@ -27,19 +30,19 @@ public static class LogCat /// 阵营管理器 /// public const string CampManager = "CampManager"; - + /// /// State context /// 状态上下文 /// public const string StateContext = "StateContext"; - + /// /// StateMachineTemplate /// 状态机模板 /// public const string StateMachineTemplate = "StateMachineTemplate"; - + /// /// Pursuit enemy processor /// 追击敌人处理器 @@ -103,6 +106,25 @@ public static class LogCat private static HashSet DisabledLogLabels { get; } = []; + public static void Init() + { + var loggerFactory = LoggerFactory.Create(builder => + { + builder.AddOpenTelemetry(options => { options.AddOtlpExporter(OtlpExporterOptions); }); + }); + var logger = loggerFactory.CreateLogger("323"); + logger.Log(LogLevel.Debug, "你好"); + } + + public static void OtlpExporterOptions(OtlpExporterOptions options) + { + options.Protocol = OtlpExportProtocol.HttpProtobuf; + options.Endpoint = new Uri("http://test.coldmint.top/api/default/traces"); + options.Headers = + "Authorization=Basic cm9vdEBleGFtcGxlLmNvbTp5V0kwVzZYcWhteTBzQml3,organization=default,stream-name=default"; + } + + /// /// Disable log Label /// 禁用某个日志标签 diff --git a/scripts/loader/uiLoader/MainMenuLoader.cs b/scripts/loader/uiLoader/MainMenuLoader.cs index ef57519..3a2bb87 100644 --- a/scripts/loader/uiLoader/MainMenuLoader.cs +++ b/scripts/loader/uiLoader/MainMenuLoader.cs @@ -20,148 +20,149 @@ 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() + { + LogCat.Init(); + 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); - } + 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