Compare commits
3 Commits
d218109354
...
f0f954f10c
Author | SHA1 | Date | |
---|---|---|---|
f0f954f10c | |||
549248cf6b | |||
015efbc271 |
|
@ -52,6 +52,10 @@ You need to fill in the Export Presets > Resources > Filter to export non-resour
|
|||
data/*
|
||||
```
|
||||
|
||||
#### Custom feature
|
||||
|
||||
- **disableVersionIsolation** Disable version isolation.
|
||||
|
||||
## Configuring Openobserve
|
||||
|
||||
> This is optional, and the game will work even if you do not configure Openobserve.
|
||||
|
|
|
@ -50,6 +50,10 @@ git clone https://github.com/Cold-Mint/Traveller.git
|
|||
data/*
|
||||
```
|
||||
|
||||
#### 風習特徴
|
||||
|
||||
- **disableVersionIsolation** 版孤立を無効化する。
|
||||
|
||||
## はいちOpenobserve
|
||||
|
||||
> これはオプションなので、Openobserveを設定しなくてもゲームは正常に動作します。
|
||||
|
|
|
@ -52,6 +52,10 @@ git clone https://github.com/Cold-Mint/Traveller.git
|
|||
data/*
|
||||
```
|
||||
|
||||
#### 自定义特性
|
||||
|
||||
- **disableVersionIsolation** 禁用版本隔离。
|
||||
|
||||
## 配置Openobserve
|
||||
|
||||
> 这是可选的操作,即使您不配置Openobserve,游戏也能正常运行。
|
||||
|
|
|
@ -33,7 +33,7 @@ log_start_item_register_from_file,开始从文件注册物品信息,Start regist
|
|||
log_found_files,找到{0}个文件,Found {0} files,{0}ファイルが見つかりました
|
||||
log_found_item_types,从文件中找到{0}个物品类型,Found {0} item types in files,ファイルから{0}個のアイテム・タイプが見つかった
|
||||
log_register_item,注册物品类型{0}结果为{1},Registered item type {0}; results in {1},登録されたアイテム・タイプ {0} の結果は {1} です。
|
||||
log_error_when_open_item_regs_dir,尝试打开物品信息目录时发生错误,错误代码:{1},"An error occurred when trying to open the item information directory, error code: {1}",アイテム情報ディレクトリを開こうとしてエラーが発生しました、エラーコード:{1}
|
||||
log_error_when_open_item_regs_dir,尝试打开物品信息目录{0}时发生错误,错误代码:{1},"An error occurred when trying to open the item information directory {0}, error code: {1}",アイテム情報ディレクトリ{0}を開こうとしてエラーが発生しました、エラーコード:{1}
|
||||
log_wrong_custom_arg,不匹配的参数:类型为{0}而值为{1},Mismatched parameter: type {0} and value {1},パラメータの不一致:型{0}と値{1}。
|
||||
log_item_container_is_null,物品容器为空,Item container is null,アイテム・コンテナが空です
|
||||
log_item_has_no_owner,物品没有所有者,Item has no owner,アイテムに所有者がいません
|
||||
|
@ -98,3 +98,14 @@ log_load_dll_file_load_exception,加载DLL文件{0}失败。,Failed to load the
|
|||
log_load_dll_bad_image_format_exception,{0}不是有效的程序集。,{0} is not a valid assembly.,{0}は有効なアセンブリではありません。
|
||||
log_load_dll_success,成功加载位于{0}的dll文件。,Successfully loaded the dll file located at {0}.,{0}にあるDLLファイルを正常にロードしました。
|
||||
log_mod_folder_does_not_exist,位于{0}的模组文件夹不存在。,The module folder at {0} does not exist.,{0}に位置するモジュールフォルダは存在しません。
|
||||
log_mod_not_contain_dll,模组{0}不包含DLL文件。,The module {0} does not contain a DLL file.,モジュール{0}にDLLファイルが含まれていません。
|
||||
log_mod_not_contain_pck,模组{0}不包含PCK文件。,The module {0} does not contain a PCK file.,モジュール{0}にPCKファイルが含まれていません。
|
||||
log_load_pck_success,成功加载位于{0}的PCK文件。,Successfully loaded the PCK file located at {0}.,{0}にあるPCKファイルを正常にロードしました。
|
||||
log_load_pck_failed,加载PCK文件{0}失败。,Failed to load the PCK file {0}.,PCKファイル{0}のロードに失敗しました。
|
||||
log_projectile_container_is_null,抛射体容器为空。,Projectile container is null.,射出体コンテナが空です。
|
||||
log_marker2d_is_null,Marker2D为空。,Marker2D is null.,Marker2Dが空です。
|
||||
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>
|
||||
public const string CompanyName = "ColdMint";
|
||||
|
||||
/// <summary>
|
||||
/// <para>Module life handler name</para>
|
||||
/// <para>模组生命周期处理器名称</para>
|
||||
/// </summary>
|
||||
public const string ModLifecycleHandlerName = "ModLifecycleHandler";
|
||||
|
||||
/// <summary>
|
||||
/// <para>Solution Name</para>
|
||||
/// <para>解决方案名称</para>
|
||||
/// </summary>
|
||||
public static string SolutionName = "ColdMint.Traveler";
|
||||
public const string SolutionName = "ColdMint.Traveler";
|
||||
|
||||
/// <summary>
|
||||
/// <para>How many item slots are there on the shortcut bar</para>
|
||||
|
@ -119,7 +125,12 @@ public static class Config
|
|||
/// <para>Whether version isolation is enabled</para>
|
||||
/// <para>是否启用版本隔离</para>
|
||||
/// </summary>
|
||||
public const bool EnableVersionIsolation = true;
|
||||
public static bool EnableVersionIsolation()
|
||||
{
|
||||
//By default, we enable version isolation, but special feature identifiers can be set to disable version isolation.
|
||||
//默认情况,我们启用版本隔离,但是可以设置特殊的功能标识来禁用版本隔离。
|
||||
return !OS.HasFeature("disableVersionIsolation");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Default version name</para>
|
||||
|
@ -210,10 +221,14 @@ public static class Config
|
|||
/// <para>Get what platform is currently running on</para>
|
||||
/// <para>获取当前在什么平台上运行</para>
|
||||
/// </summary>
|
||||
/// <param name="containEditor">
|
||||
///<para>Whether to include an editor environment</para>
|
||||
///<para>是否包含编辑器环境</para>
|
||||
/// </param>
|
||||
/// <returns></returns>
|
||||
public static OsEnum GetOs()
|
||||
public static OsEnum GetOs(bool containEditor = false)
|
||||
{
|
||||
if (OS.HasFeature("editor"))
|
||||
if (containEditor && OS.HasFeature("editor"))
|
||||
{
|
||||
return OsEnum.Editor;
|
||||
}
|
||||
|
@ -271,7 +286,7 @@ public static class Config
|
|||
/// <returns></returns>
|
||||
public static string GetGameDataDirectory()
|
||||
{
|
||||
if (EnableVersionIsolation)
|
||||
if (EnableVersionIsolation())
|
||||
{
|
||||
return Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), CompanyName,
|
||||
ProjectSettings.GetSetting("application/config/name").AsString(), UserId,
|
||||
|
@ -285,6 +300,15 @@ public static class Config
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>GetModDataDirectory</para>
|
||||
/// <para>获取模组文件夹</para>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string GetModDataDirectory()
|
||||
{
|
||||
return Path.Join(GetGameDataDirectory(), "Mods");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Get the export directory for the level graph</para>
|
||||
|
|
|
@ -35,6 +35,12 @@ public static class GameSceneNodeHolder
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>ProjectileContainer</para>
|
||||
/// <para>抛射体容器</para>
|
||||
/// </summary>
|
||||
public static Node2D? ProjectileContainer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>WeaponContainer</para>
|
||||
/// <para>武器容器</para>
|
||||
|
|
|
@ -249,11 +249,14 @@ public static class LogCat
|
|||
|
||||
switch (level)
|
||||
{
|
||||
case WarningLogLevel:
|
||||
GD.PrintRich("[color=#FFDE66]"+concreteLog+"[/color]");
|
||||
break;
|
||||
case ErrorLogLevel:
|
||||
GD.PrintErr(concreteLog);
|
||||
GD.PrintRich("[color=#FF4E39]"+concreteLog+"[/color]");
|
||||
break;
|
||||
default:
|
||||
GD.Print(concreteLog);
|
||||
GD.PrintRich("[color=#CCCED1]"+concreteLog+"[/color]");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +296,7 @@ public static class LogCat
|
|||
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,
|
||||
upload);
|
||||
|
|
|
@ -31,12 +31,14 @@ public static class ItemTypeRegister
|
|||
LogCat.Log("start_item_register_from_file");
|
||||
//初始化文件目录
|
||||
//initialize file dir
|
||||
var itemRegsDirPath = "res://data/itemRegs/";
|
||||
var itemRegsDirPath = "res://data/itemRegs";
|
||||
var itemRegsDir = DirAccess.Open(itemRegsDirPath);
|
||||
var error = DirAccess.GetOpenError();
|
||||
if (error is not Error.Ok)
|
||||
{
|
||||
LogCat.LogError("error_when_open_item_regs_dir", error.ToString());
|
||||
LogCat.LogErrorWithFormat("error_when_open_item_regs_dir", LogCat.LogLabel.Default, true, itemRegsDirPath,
|
||||
error.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
//找到文件
|
||||
|
@ -69,7 +71,7 @@ public static class ItemTypeRegister
|
|||
/// </summary>
|
||||
/// <param name="filePath"></param>
|
||||
/// <returns></returns>
|
||||
private static IList<ItemTypeInfo> ParseFile(string filePath)
|
||||
private static IList<ItemTypeInfo>? ParseFile(string filePath)
|
||||
{
|
||||
var yamlFile = FileAccess.Open(filePath, FileAccess.ModeFlags.Read);
|
||||
|
||||
|
|
|
@ -39,6 +39,10 @@ public partial class GameSceneLoader : SceneLoaderTemplate
|
|||
//加载武器容器
|
||||
var weaponContainer = GetNode<Node2D>("WeaponContainer");
|
||||
GameSceneNodeHolder.WeaponContainer = weaponContainer;
|
||||
//Load projectile container
|
||||
//加载抛射体容器
|
||||
var projectileContainer = GetNode<Node2D>("ProjectileContainer");
|
||||
GameSceneNodeHolder.ProjectileContainer = projectileContainer;
|
||||
//Load Packsack container
|
||||
//加载背包容器
|
||||
var packsackContainer = GetNode<Node2D>("PacksackContainer");
|
||||
|
|
|
@ -82,7 +82,6 @@ public partial class SplashScreenLoader : UiLoaderTemplate
|
|||
//Disable all logs in the release version.
|
||||
//在发行版禁用所有日志。
|
||||
LogCat.MinLogLevel = Config.IsDebug() ? LogCat.InfoLogLevel : LogCat.DisableAllLogLevel;
|
||||
ModLoader.Init();
|
||||
ContributorDataManager.RegisterAllContributorData();
|
||||
DeathInfoGenerator.RegisterDeathInfoHandler(new SelfDeathInfoHandler());
|
||||
MapGenerator.RegisterRoomInjectionProcessor(new ChanceRoomInjectionProcessor());
|
||||
|
@ -90,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
|
||||
//注册对应的编码提供程序,解决压缩包中文路径乱码问题
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
//Create a game data folder
|
||||
//创建游戏数据文件夹
|
||||
var dataPath = Config.GetGameDataDirectory();
|
||||
if (!Directory.Exists(dataPath))
|
||||
|
@ -116,6 +116,15 @@ public partial class SplashScreenLoader : UiLoaderTemplate
|
|||
ItemTypeRegister.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));
|
||||
}
|
||||
}
|
|
@ -330,7 +330,7 @@ public static class MapGenerator
|
|||
|
||||
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);
|
||||
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,8 +1,11 @@
|
|||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.utils;
|
||||
using Godot;
|
||||
|
||||
namespace ColdMint.scripts.mod;
|
||||
|
||||
|
@ -18,8 +21,16 @@ public class ModLoader
|
|||
/// </summary>
|
||||
private static AssemblyLoadContext? _assemblyLoadContext;
|
||||
|
||||
private static string[] _requiredDllList = new[] { Config.SolutionName };
|
||||
private static readonly string[] RequiredDllList = [Config.SolutionName];
|
||||
|
||||
/// <summary>
|
||||
/// <para>Initializes the mod loader</para>
|
||||
/// <para>初始化模组加载器</para>
|
||||
/// </summary>
|
||||
/// <exception cref="FileNotFoundException">
|
||||
///<para>This exception is thrown if the built-in dll file cannot be found when it is loaded.</para>
|
||||
///<para>如果加载内置dll文件时,找不到文件,则抛出此异常。</para>
|
||||
/// </exception>
|
||||
public static void Init()
|
||||
{
|
||||
//Initialize the context.
|
||||
|
@ -39,7 +50,7 @@ public class ModLoader
|
|||
return;
|
||||
}
|
||||
|
||||
foreach (var requiredDll in _requiredDllList)
|
||||
foreach (var requiredDll in RequiredDllList)
|
||||
{
|
||||
var dllPath = Path.Join(dllFolder, requiredDll + ".dll");
|
||||
//Load the necessary dll files.
|
||||
|
@ -49,85 +60,269 @@ public class ModLoader
|
|||
//When the dll that must be loaded does not exist, an error is reported immediately.
|
||||
//当必须加载的dll不存在时,立即报错。
|
||||
LogCat.LogErrorWithFormat("dll_not_exist", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
throw new NullReferenceException("dll not exist:" + dllPath);
|
||||
throw new FileNotFoundException("dll not exist:" + dllPath);
|
||||
}
|
||||
|
||||
//Load the dll.
|
||||
//加载dll。
|
||||
LogCat.LogWithFormat("load_dll", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
try
|
||||
{
|
||||
_assemblyLoadContext.LoadFromAssemblyPath(dllPath);
|
||||
}
|
||||
catch (ArgumentNullException argumentNullException)
|
||||
{
|
||||
//The assemblyPath parameter is null.
|
||||
//assemblyPath参数为空。
|
||||
LogCat.LogErrorWithFormat("load_dll_argument_null_exception", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
LogCat.WhenCaughtException(argumentNullException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
}
|
||||
catch (ArgumentException argumentException)
|
||||
{
|
||||
//Not an absolute path.
|
||||
//不是绝对路径
|
||||
LogCat.LogErrorWithFormat("load_dll_argument_exception", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
LogCat.WhenCaughtException(argumentException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
}
|
||||
catch (FileLoadException fileLoadException)
|
||||
{
|
||||
//A file that was found could not be loaded.
|
||||
//无法加载找到的文件。
|
||||
LogCat.LogErrorWithFormat("load_dll_file_load_exception", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
LogCat.WhenCaughtException(fileLoadException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
}
|
||||
catch (BadImageFormatException badImageFormatException)
|
||||
{
|
||||
//assemblyPath is not a valid assembly.
|
||||
//assemblyPath不是有效的程序集。
|
||||
LogCat.LogErrorWithFormat("load_dll_bad_image_format_exception", LogCat.LogLabel.ModLoader, true,
|
||||
dllPath);
|
||||
LogCat.WhenCaughtException(badImageFormatException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
}
|
||||
|
||||
//Loading the dll succeeded.
|
||||
//加载dll成功。
|
||||
LogCat.LogWithFormat("load_dll_success", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
LoadDllFile(dllPath);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Load a module for a directory</para>
|
||||
/// <para>加载某个目录的模组</para>
|
||||
/// <para>Load Dll file</para>
|
||||
/// <para>加载Dll文件</para>
|
||||
/// </summary>
|
||||
/// <param name="dllPath">
|
||||
///<para>dll file path</para>
|
||||
///<para>dll的文件路径</para>
|
||||
/// </param>
|
||||
/// <exception cref="NullReferenceException">
|
||||
///<para>Throw this error if the assemblyLoadContext has not been initialized.</para>
|
||||
///<para>如果assemblyLoadContext尚未初始化,那么抛出此错误。</para>
|
||||
/// </exception>
|
||||
private static void LoadDllFile(string dllPath)
|
||||
{
|
||||
if (_assemblyLoadContext == null)
|
||||
{
|
||||
throw new NullReferenceException("assemblyLoadContext is null.");
|
||||
}
|
||||
|
||||
//Load the dll.
|
||||
//加载dll。
|
||||
LogCat.LogWithFormat("load_dll", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
//The assemblyPath parameter is null.
|
||||
//assemblyPath参数为空。
|
||||
LogCat.LogErrorWithFormat("load_dll_argument_null_exception", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
LogCat.WhenCaughtException(argumentNullException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
}
|
||||
catch (ArgumentException argumentException)
|
||||
{
|
||||
//Not an absolute path.
|
||||
//不是绝对路径
|
||||
LogCat.LogErrorWithFormat("load_dll_argument_exception", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
LogCat.WhenCaughtException(argumentException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
}
|
||||
catch (FileLoadException fileLoadException)
|
||||
{
|
||||
//A file that was found could not be loaded.
|
||||
//无法加载找到的文件。
|
||||
LogCat.LogErrorWithFormat("load_dll_file_load_exception", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
LogCat.WhenCaughtException(fileLoadException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
}
|
||||
catch (BadImageFormatException badImageFormatException)
|
||||
{
|
||||
//assemblyPath is not a valid assembly.
|
||||
//assemblyPath不是有效的程序集。
|
||||
LogCat.LogErrorWithFormat("load_dll_bad_image_format_exception", LogCat.LogLabel.ModLoader, true,
|
||||
dllPath);
|
||||
LogCat.WhenCaughtException(badImageFormatException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
}
|
||||
|
||||
//Loading the dll succeeded.
|
||||
//加载dll成功。
|
||||
LogCat.LogWithFormat("load_dll_success", LogCat.LogLabel.ModLoader, true, dllPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Load all mods</para>
|
||||
/// <para>加载全部模组</para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///<para>This method scans the incoming subfolders and loads them as module folders.</para>
|
||||
///<para>此方法会将扫描传入的子文件夹,并将其子文件夹看作模组文件夹加载。</para>
|
||||
/// </remarks>
|
||||
/// <param name="modFolder">
|
||||
///<para>Mod folder</para>
|
||||
///<para>模组文件夹</para>
|
||||
/// </param>
|
||||
/// <exception cref="DirectoryNotFoundException">
|
||||
///<para>If the given folder does not exist, throw this exception.</para>
|
||||
///<para>如果给定的文件夹不存在,则抛出此异常。</para>
|
||||
/// </exception>
|
||||
public static void LoadAllMods(string modFolder)
|
||||
{
|
||||
if (!Directory.Exists(modFolder))
|
||||
{
|
||||
//The mod directory does not exist.
|
||||
//模组目录不存在。
|
||||
throw new DirectoryNotFoundException("mod folder not exist:" + modFolder);
|
||||
}
|
||||
|
||||
var directoryInfo = new DirectoryInfo(modFolder);
|
||||
foreach (var directory in directoryInfo.GetDirectories())
|
||||
{
|
||||
LoadSingleMod(directory.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Load a single mod</para>
|
||||
/// <para>加载单个模组</para>
|
||||
/// </summary>
|
||||
/// <param name="modFolderPath">
|
||||
///<para>Mod path</para>
|
||||
///<para>模组路径</para>
|
||||
/// </param>
|
||||
public static void LoadMod(string modFolderPath)
|
||||
/// <exception cref="DirectoryNotFoundException">
|
||||
/// <para>If the given directory does not exist, throw this exception.</para>
|
||||
///<para>如果给定的目录不存在,那么抛出此异常。</para>
|
||||
/// </exception>
|
||||
/// <exception cref="NullReferenceException">
|
||||
///<para>Throw this exception if the manifest file creation deserialization fails.</para>
|
||||
///<para>如果清单文件创建反序列化失败,则抛出此异常。</para>
|
||||
/// </exception>
|
||||
private static void LoadSingleMod(string modFolderPath)
|
||||
{
|
||||
if (!Directory.Exists(modFolderPath))
|
||||
{
|
||||
//The module folder does not exist.
|
||||
//模组文件夹不存在。
|
||||
LogCat.LogErrorWithFormat("mod_folder_does_not_exist", LogCat.LogLabel.ModLoader, true, modFolderPath);
|
||||
return;
|
||||
throw new DirectoryNotFoundException("Mod folder does not exist:" + modFolderPath);
|
||||
}
|
||||
|
||||
try
|
||||
var modManifestPath = Path.Join(modFolderPath, Config.ModManifestFileName);
|
||||
var modManifest =
|
||||
ModManifest.CreateModManifestFromPath(modManifestPath);
|
||||
if (modManifest == null)
|
||||
{
|
||||
var modManifest =
|
||||
ModManifest.CreateModManifestFromPath(Path.Join(modFolderPath, Config.ModManifestFileName));
|
||||
throw new NullReferenceException("mod manifest is null:" + modManifestPath);
|
||||
}
|
||||
catch (FileNotFoundException fileNotFoundException)
|
||||
|
||||
var dllList = modManifest.DllList;
|
||||
if (dllList == null || dllList.Length == 0)
|
||||
{
|
||||
//Do not continue to load the file when it does not exist.
|
||||
//当文件不存在时就不要继续加载了。
|
||||
LogCat.WhenCaughtException(fileNotFoundException, LogCat.LogLabel.ModLoader);
|
||||
return;
|
||||
//The module does not contain a dll file.
|
||||
//模组不包含dll文件。
|
||||
LogCat.LogWarningWithFormat("mod_not_contain_dll", LogCat.LogLabel.ModLoader, LogCat.UploadFormat,
|
||||
modFolderPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
//The module contains dll files, load the dll files.
|
||||
//包含dll文件,加载dll文件。
|
||||
foreach (var dll in dllList)
|
||||
{
|
||||
var dllPath = Path.GetFullPath(dll, modFolderPath);
|
||||
LoadDllFile(dllPath);
|
||||
}
|
||||
}
|
||||
|
||||
var pakList = modManifest.PckList;
|
||||
if (pakList == null || pakList.Length == 0)
|
||||
{
|
||||
//The module does not contain a pck file.
|
||||
//模组不包含pck文件。
|
||||
LogCat.LogWarningWithFormat("mod_not_contain_pck", LogCat.LogLabel.ModLoader, LogCat.UploadFormat,
|
||||
modFolderPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
//The module contains pck files, load the pck files.
|
||||
//包含pck文件,加载pck文件。
|
||||
foreach (var pak in pakList)
|
||||
{
|
||||
var pakPath = Path.GetFullPath(pak, modFolderPath);
|
||||
LoadPckFile(pakPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>Load the Pck file</para>
|
||||
/// <para>加载Pck文件</para>
|
||||
/// </summary>
|
||||
/// <param name="pckPath">
|
||||
///<para>Pck path</para>
|
||||
///<para>Pck路径</para>
|
||||
/// </param>
|
||||
/// <exception cref="FileNotFoundException">
|
||||
///<para>If the given path does not exist, throw this exception.</para>
|
||||
///<para>如果给定的路径不存在,那么抛出此异常。</para>
|
||||
/// </exception>
|
||||
/// <exception cref="Exception">
|
||||
///<para>Throw this exception if the pck package fails to load.</para>
|
||||
///<para>如果pck包加载失败了,抛出此异常。</para>
|
||||
/// </exception>
|
||||
private static void LoadPckFile(string pckPath)
|
||||
{
|
||||
if (!File.Exists(pckPath))
|
||||
{
|
||||
throw new FileNotFoundException("pck file not exist:" + pckPath);
|
||||
}
|
||||
|
||||
var success = ProjectSettings.LoadResourcePack(pckPath);
|
||||
if (success)
|
||||
{
|
||||
LogCat.LogWithFormat("load_pck_success", LogCat.LogLabel.ModLoader, true, pckPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogCat.LogErrorWithFormat("load_pck_failed", LogCat.LogLabel.ModLoader, true, pckPath);
|
||||
//Throw a suitable exception here for handling at the caller.
|
||||
//为这里抛出合适的异常,以便在调用方处理。
|
||||
throw new DataException("load pck failed:" + pckPath);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,12 +25,20 @@ public class ModManifest
|
|||
/// <para>Dll path list of the mod</para>
|
||||
/// <para>模组的Dll路径列表</para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///<para>Allow relative paths, such as:... / Points to the parent directory.</para>
|
||||
///<para>允许使用相对路径,例如: ../指向上级目录。</para>
|
||||
/// </remarks>
|
||||
public string[]? DllList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Pck path list of mod</para>
|
||||
/// <para>模组的Pck路径列表</para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///<para>Allow relative paths, such as:... / Points to the parent directory.</para>
|
||||
///<para>允许使用相对路径,例如: ../指向上级目录。</para>
|
||||
/// </remarks>
|
||||
public string[]? PckList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -50,7 +58,7 @@ public class ModManifest
|
|||
///<para>当给定的路径不存在时,抛出此异常。</para>
|
||||
/// </exception>
|
||||
/// <returns></returns>
|
||||
public static ModManifest CreateModManifestFromPath(string filePath)
|
||||
public static ModManifest? CreateModManifestFromPath(string filePath)
|
||||
{
|
||||
if (!filePath.EndsWith(Config.ModManifestFileName))
|
||||
{
|
||||
|
|
|
@ -51,8 +51,10 @@ public static class YamlSerialization
|
|||
/// <param name="yaml"></param>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
public static T Deserialize<T>(string yaml)
|
||||
// ReSharper disable ReturnTypeCanBeNotNullable
|
||||
public static T? Deserialize<T>(string yaml)
|
||||
{
|
||||
return YamlDeserializer.Deserialize<T>(yaml);
|
||||
}
|
||||
// ReSharper restore ReturnTypeCanBeNotNullable
|
||||
}
|
|
@ -58,6 +58,7 @@ public static class ExplorerUtils
|
|||
case Config.OsEnum.Macos:
|
||||
case Config.OsEnum.Ios:
|
||||
case Config.OsEnum.Web:
|
||||
case Config.OsEnum.Editor:
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.projectile;
|
||||
using Godot;
|
||||
using Packsack = ColdMint.scripts.inventory.Packsack;
|
||||
using PacksackUi = ColdMint.scripts.loader.uiLoader.PacksackUi;
|
||||
|
@ -235,6 +236,11 @@ public static class NodeUtils
|
|||
/// <returns></returns>
|
||||
public static Node FindContainerNode(Node childNode, Node defaultParentNode)
|
||||
{
|
||||
if (GameSceneNodeHolder.ProjectileContainer != null && childNode is Projectile)
|
||||
{
|
||||
return GameSceneNodeHolder.ProjectileContainer;
|
||||
}
|
||||
|
||||
if (GameSceneNodeHolder.WeaponContainer != null && childNode is WeaponTemplate)
|
||||
{
|
||||
return GameSceneNodeHolder.WeaponContainer;
|
||||
|
@ -278,7 +284,7 @@ public static class NodeUtils
|
|||
if (node is T result) return result;
|
||||
// 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));
|
||||
node.QueueFree();
|
||||
return null;
|
||||
|
|
|
@ -23,20 +23,22 @@ public static class ResUtils
|
|||
public static string? GetSelfDllFolder()
|
||||
{
|
||||
var currentDirectory = Environment.CurrentDirectory;
|
||||
if (Config.GetOs() == Config.OsEnum.Editor)
|
||||
var osEnum = Config.GetOs(true);
|
||||
if (osEnum == Config.OsEnum.Editor)
|
||||
{
|
||||
return Path.Join(currentDirectory, ".godot", "mono", "temp", "bin", "Debug");
|
||||
}
|
||||
|
||||
if (Config.GetOs() == Config.OsEnum.Windows)
|
||||
if (osEnum == Config.OsEnum.Windows)
|
||||
{
|
||||
return Path.Join(currentDirectory, "data_" + Config.SolutionName + "_windows_x86_64");
|
||||
}
|
||||
|
||||
if (Config.GetOs() == Config.OsEnum.Linux)
|
||||
if (osEnum == Config.OsEnum.Linux)
|
||||
{
|
||||
return Path.Join(currentDirectory, "data_" + Config.SolutionName + "_linuxbsd_x86_64");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,21 +23,33 @@ public partial class ProjectileWeapon : WeaponTemplate
|
|||
|
||||
[Export] protected PackedScene[] ProjectileScenes { get; set; } = [];
|
||||
|
||||
private Node2D? _projectileContainer;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
_marker2D = GetNode<Marker2D>("Marker2D");
|
||||
|
||||
_projectileContainer = GetNode("/root/Game/ProjectileContainer") as Node2D;
|
||||
}
|
||||
|
||||
|
||||
protected override void DoFire(Node2D? owner, Vector2 enemyGlobalPosition)
|
||||
{
|
||||
if (owner == null || _projectileContainer == null || _marker2D == null) return;
|
||||
if (owner == null)
|
||||
{
|
||||
LogCat.LogError("owner_is_null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_marker2D == null)
|
||||
{
|
||||
LogCat.LogError("marker2d_is_null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameSceneNodeHolder.ProjectileContainer == null)
|
||||
{
|
||||
LogCat.LogError("projectile_container_is_null");
|
||||
return;
|
||||
}
|
||||
//Empty list check
|
||||
//空列表检查
|
||||
if (ProjectileScenes is [])
|
||||
{
|
||||
|
@ -51,7 +63,7 @@ public partial class ProjectileWeapon : WeaponTemplate
|
|||
// var projectileScene = _projectileCache[_projectiles[0]];
|
||||
var projectile = NodeUtils.InstantiatePackedScene<ProjectileTemplate>(projectileScene);
|
||||
if (projectile == null) return;
|
||||
NodeUtils.CallDeferredAddChild(_projectileContainer, projectile);
|
||||
NodeUtils.CallDeferredAddChild(GameSceneNodeHolder.ProjectileContainer, projectile);
|
||||
projectile.Owner = owner;
|
||||
projectile.Velocity = (enemyGlobalPosition - _marker2D.GlobalPosition).Normalized() * projectile.Speed;
|
||||
projectile.Position = _marker2D.GlobalPosition;
|
||||
|
|
Loading…
Reference in New Issue
Block a user