Support to print color logs, join Mod lifecycle processor.
支持打印彩色日志,加入Mod生命周期处理器。
This commit is contained in:
parent
549248cf6b
commit
f0f954f10c
|
@ -105,3 +105,7 @@ log_load_pck_failed,加载PCK文件{0}失败。,Failed to load the PCK file {0}.
|
||||||
log_projectile_container_is_null,抛射体容器为空。,Projectile container is null.,射出体コンテナが空です。
|
log_projectile_container_is_null,抛射体容器为空。,Projectile container is null.,射出体コンテナが空です。
|
||||||
log_marker2d_is_null,Marker2D为空。,Marker2D is null.,Marker2Dが空です。
|
log_marker2d_is_null,Marker2D为空。,Marker2D is null.,Marker2Dが空です。
|
||||||
log_owner_is_null,所有者为空。,Owner is null.,所有者が空です。
|
log_owner_is_null,所有者为空。,Owner is null.,所有者が空です。
|
||||||
|
log_dll_name,已加载{0}。,Loaded {0}.,{0}をロードしました。
|
||||||
|
log_dll_does_not_register_lifecycle_processor,位于{0}的dll文件,未注册生命周期处理器{1}。,"The DLL file located at {0} does not register the lifecycle processor {1}.",{0}にあるDLLファイルは、ライフサイクルプロセッサ{1}を登録していません。
|
||||||
|
log_mod_lifecycle_handler_not_implement_interface,位于{0}的dll文件,生命周期处理器未实现IModLifecycleHandler接口。,"The DLL file located at {0}, the lifecycle processor does not implement the IModLifecycleHandler interface.",{0}にあるDLLファイル、ライフサイクルプロセッサはIModLifecycleHandlerインターフェースを実装していません。
|
||||||
|
log_dll_no_parameterless_constructor,位于{0}的dll文件,没有无参构造函数。,"The DLL file located at {0} does not have a parameterless constructor.",{0}にあるDLLファイルにはパラメータのないコンストラクタがありません。
|
|
|
@ -96,11 +96,17 @@ public static class Config
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string CompanyName = "ColdMint";
|
public const string CompanyName = "ColdMint";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Module life handler name</para>
|
||||||
|
/// <para>模组生命周期处理器名称</para>
|
||||||
|
/// </summary>
|
||||||
|
public const string ModLifecycleHandlerName = "ModLifecycleHandler";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Solution Name</para>
|
/// <para>Solution Name</para>
|
||||||
/// <para>解决方案名称</para>
|
/// <para>解决方案名称</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string SolutionName = "ColdMint.Traveler";
|
public const string SolutionName = "ColdMint.Traveler";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>How many item slots are there on the shortcut bar</para>
|
/// <para>How many item slots are there on the shortcut bar</para>
|
||||||
|
|
|
@ -249,11 +249,14 @@ public static class LogCat
|
||||||
|
|
||||||
switch (level)
|
switch (level)
|
||||||
{
|
{
|
||||||
|
case WarningLogLevel:
|
||||||
|
GD.PrintRich("[color=#FFDE66]"+concreteLog+"[/color]");
|
||||||
|
break;
|
||||||
case ErrorLogLevel:
|
case ErrorLogLevel:
|
||||||
GD.PrintErr(concreteLog);
|
GD.PrintRich("[color=#FF4E39]"+concreteLog+"[/color]");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GD.Print(concreteLog);
|
GD.PrintRich("[color=#CCCED1]"+concreteLog+"[/color]");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,7 +296,7 @@ public static class LogCat
|
||||||
upload);
|
upload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LogWarningWithFormat(string message, bool upload, string label, params object?[] args)
|
public static void LogWarningWithFormat(string message, string label, bool upload, params object?[] args)
|
||||||
{
|
{
|
||||||
PrintLog(WarningLogLevel, string.Format(HandleMessage(WarningLogLevel, message, label).ToString(), args), label,
|
PrintLog(WarningLogLevel, string.Format(HandleMessage(WarningLogLevel, message, label).ToString(), args), label,
|
||||||
upload);
|
upload);
|
||||||
|
|
|
@ -89,6 +89,7 @@ public partial class SplashScreenLoader : UiLoaderTemplate
|
||||||
//Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package
|
//Register the corresponding encoding provider to solve the problem of garbled Chinese path of the compressed package
|
||||||
//注册对应的编码提供程序,解决压缩包中文路径乱码问题
|
//注册对应的编码提供程序,解决压缩包中文路径乱码问题
|
||||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||||
|
//Create a game data folder
|
||||||
//创建游戏数据文件夹
|
//创建游戏数据文件夹
|
||||||
var dataPath = Config.GetGameDataDirectory();
|
var dataPath = Config.GetGameDataDirectory();
|
||||||
if (!Directory.Exists(dataPath))
|
if (!Directory.Exists(dataPath))
|
||||||
|
@ -96,14 +97,6 @@ public partial class SplashScreenLoader : UiLoaderTemplate
|
||||||
Directory.CreateDirectory(dataPath);
|
Directory.CreateDirectory(dataPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
ModLoader.Init();
|
|
||||||
var modPath = Config.GetModDataDirectory();
|
|
||||||
if (!Directory.Exists(modPath))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(modPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
ModLoader.LoadAllMods(modPath);
|
|
||||||
//Registered camp
|
//Registered camp
|
||||||
//注册阵营
|
//注册阵营
|
||||||
var defaultCamp = new Camp(Config.CampId.Default)
|
var defaultCamp = new Camp(Config.CampId.Default)
|
||||||
|
@ -123,6 +116,15 @@ public partial class SplashScreenLoader : UiLoaderTemplate
|
||||||
ItemTypeRegister.StaticRegister();
|
ItemTypeRegister.StaticRegister();
|
||||||
//静态注册掉落表
|
//静态注册掉落表
|
||||||
LootRegister.StaticRegister();
|
LootRegister.StaticRegister();
|
||||||
|
//Load mod
|
||||||
|
//加载模组
|
||||||
|
var modPath = Config.GetModDataDirectory();
|
||||||
|
if (!Directory.Exists(modPath))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(modPath);
|
||||||
|
}
|
||||||
|
ModLoader.Init();
|
||||||
|
ModLoader.LoadAllMods(modPath);
|
||||||
await Task.Delay(TimeSpan.FromMilliseconds(500));
|
await Task.Delay(TimeSpan.FromMilliseconds(500));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -330,7 +330,7 @@ public static class MapGenerator
|
||||||
|
|
||||||
if (!await _roomPlacementStrategy.PlaceRoom(_mapRoot, roomPlacementData))
|
if (!await _roomPlacementStrategy.PlaceRoom(_mapRoot, roomPlacementData))
|
||||||
{
|
{
|
||||||
LogCat.LogWarningWithFormat("room_placement_failed", LogCat.UploadFormat, LogCat.LogLabel.Default,
|
LogCat.LogWarningWithFormat("room_placement_failed", LogCat.LogLabel.Default, LogCat.UploadFormat,
|
||||||
roomNodeDataId);
|
roomNodeDataId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
14
scripts/mod/IModLifecycleHandler.cs
Normal file
14
scripts/mod/IModLifecycleHandler.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
namespace ColdMint.scripts.mod;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Mod life cycle handler</para>
|
||||||
|
/// <para>模组生命周期处理器</para>
|
||||||
|
/// </summary>
|
||||||
|
public interface IModLifecycleHandler
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>When loading the Mod</para>
|
||||||
|
/// <para>当加载Mod时</para>
|
||||||
|
/// </summary>
|
||||||
|
void OnModLoaded();
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
using ColdMint.scripts.utils;
|
using ColdMint.scripts.utils;
|
||||||
|
@ -90,7 +91,60 @@ public class ModLoader
|
||||||
LogCat.LogWithFormat("load_dll", LogCat.LogLabel.ModLoader, true, dllPath);
|
LogCat.LogWithFormat("load_dll", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_assemblyLoadContext.LoadFromAssemblyPath(dllPath);
|
var assembly = _assemblyLoadContext.LoadFromAssemblyPath(dllPath);
|
||||||
|
var assemblyName = assembly.GetName().Name;
|
||||||
|
if (assemblyName == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LogCat.LogWithFormat("dll_name", LogCat.LogLabel.ModLoader, true, assemblyName);
|
||||||
|
// if (assemblyName != Config.SolutionName)
|
||||||
|
// {
|
||||||
|
// //If the load is not its own Dll file.
|
||||||
|
// //如果加载的不是自身的Dll文件.
|
||||||
|
// }
|
||||||
|
|
||||||
|
//Call the method of the entry class.
|
||||||
|
//调用入口类的方法
|
||||||
|
var modLifecycleHandlerFullName = assemblyName + "." + Config.ModLifecycleHandlerName;
|
||||||
|
var modLifecycleHandlerType = assembly.GetType(modLifecycleHandlerFullName);
|
||||||
|
if (modLifecycleHandlerType == null)
|
||||||
|
{
|
||||||
|
//The module does not register a lifecycle processor.
|
||||||
|
//模组没有注册生命周期处理器。
|
||||||
|
LogCat.LogWarningWithFormat("dll_does_not_register_lifecycle_processor", LogCat.LogLabel.ModLoader,
|
||||||
|
LogCat.UploadFormat,
|
||||||
|
dllPath, modLifecycleHandlerFullName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var constructor = modLifecycleHandlerType.GetConstructor(Type.EmptyTypes);
|
||||||
|
if (constructor == null)
|
||||||
|
{
|
||||||
|
//No parameterless constructor found.
|
||||||
|
//未找到无参构造方法。
|
||||||
|
LogCat.LogWarningWithFormat("dll_no_parameterless_constructor", LogCat.LogLabel.ModLoader,
|
||||||
|
LogCat.UploadFormat,
|
||||||
|
dllPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var modLifecycleHandler = constructor.Invoke(null) as IModLifecycleHandler;
|
||||||
|
if (modLifecycleHandler == null)
|
||||||
|
{
|
||||||
|
//The ModLifecycleHandler class in the dll does not yet implement the IModLifecycleHandler interface.
|
||||||
|
//dll内的ModLifecycleHandler类尚未实现IModLifecycleHandler接口。
|
||||||
|
LogCat.LogWarningWithFormat("mod_lifecycle_handler_not_implement_interface",
|
||||||
|
LogCat.LogLabel.ModLoader,
|
||||||
|
LogCat.UploadFormat, dllPath);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modLifecycleHandler.OnModLoaded();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException argumentNullException)
|
catch (ArgumentNullException argumentNullException)
|
||||||
{
|
{
|
||||||
|
@ -201,7 +255,8 @@ public class ModLoader
|
||||||
{
|
{
|
||||||
//The module does not contain a dll file.
|
//The module does not contain a dll file.
|
||||||
//模组不包含dll文件。
|
//模组不包含dll文件。
|
||||||
LogCat.LogWarningWithFormat("mod_not_contain_dll", true, LogCat.LogLabel.ModLoader, modFolderPath);
|
LogCat.LogWarningWithFormat("mod_not_contain_dll", LogCat.LogLabel.ModLoader, LogCat.UploadFormat,
|
||||||
|
modFolderPath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -219,7 +274,8 @@ public class ModLoader
|
||||||
{
|
{
|
||||||
//The module does not contain a pck file.
|
//The module does not contain a pck file.
|
||||||
//模组不包含pck文件。
|
//模组不包含pck文件。
|
||||||
LogCat.LogWarningWithFormat("mod_not_contain_pck", true, LogCat.LogLabel.ModLoader, modFolderPath);
|
LogCat.LogWarningWithFormat("mod_not_contain_pck", LogCat.LogLabel.ModLoader, LogCat.UploadFormat,
|
||||||
|
modFolderPath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -284,7 +284,7 @@ public static class NodeUtils
|
||||||
if (node is T result) return result;
|
if (node is T result) return result;
|
||||||
// If the transformation fails, release the created node
|
// If the transformation fails, release the created node
|
||||||
//如果转型失败,释放所创建的节点
|
//如果转型失败,释放所创建的节点
|
||||||
LogCat.LogWarningWithFormat("warning_node_cannot_cast_to", LogCat.UploadFormat, LogCat.LogLabel.Default, node,
|
LogCat.LogWarningWithFormat("warning_node_cannot_cast_to", LogCat.LogLabel.Default,LogCat.UploadFormat, node,
|
||||||
nameof(T));
|
nameof(T));
|
||||||
node.QueueFree();
|
node.QueueFree();
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user