2023-06-12 15:51:41 +08:00
|
|
|
using System;
|
|
|
|
using Godot;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Microsoft.Extensions.Logging.Console;
|
|
|
|
using HttpClient = System.Net.Http.HttpClient;
|
|
|
|
|
|
|
|
namespace BITKit;
|
|
|
|
/// <summary>
|
|
|
|
/// 为Godot提供的BITApp加载服务
|
|
|
|
/// </summary>
|
|
|
|
public partial class BITAppForGodot : Node
|
|
|
|
{
|
2023-06-13 14:43:03 +08:00
|
|
|
|
2023-06-12 15:51:41 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 在构造函数中注册Logger
|
|
|
|
/// </summary>
|
|
|
|
public BITAppForGodot()
|
|
|
|
{
|
|
|
|
BIT4Log.OnLog += GD.Print;
|
|
|
|
BIT4Log.OnWarning += GD.PushWarning;
|
|
|
|
BIT4Log.OnNextLine += () => GD.Print();
|
|
|
|
BIT4Log.OnException += x=>GD.PrintErr(x.ToString());
|
|
|
|
|
|
|
|
//启动BITApp
|
|
|
|
BITApp.Start();
|
|
|
|
BIT4Log.Log<BITAppForGodot>("已创建BITApp");
|
|
|
|
}
|
|
|
|
|
2023-06-13 14:43:03 +08:00
|
|
|
public override void _Ready()
|
2023-06-12 15:51:41 +08:00
|
|
|
{
|
|
|
|
BIT4Log.Log<BITAppForGodot>("正在创建BITWebApp");
|
|
|
|
|
|
|
|
//添加测试用HttpClient
|
2023-06-13 14:43:03 +08:00
|
|
|
BITApp.ServiceCollection.AddSingleton<HttpClient>();
|
2023-06-12 15:51:41 +08:00
|
|
|
|
|
|
|
//构造依赖服务提供接口
|
2023-06-13 14:43:03 +08:00
|
|
|
BITApp.BuildService();
|
2023-06-12 15:51:41 +08:00
|
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
#pragma warning disable CS4014
|
|
|
|
//停止BITApp
|
|
|
|
BITApp.Stop();
|
|
|
|
#pragma warning restore CS4014
|
|
|
|
BIT4Log.Log<BITAppForGodot>("已安全退出App");
|
|
|
|
}
|
|
|
|
}
|