diff --git a/locals/Log.csv b/locals/Log.csv
index f09a131..1d1a5f9 100644
--- a/locals/Log.csv
+++ b/locals/Log.csv
@@ -96,4 +96,5 @@ log_load_dll_argument_exception,{0}不是绝对路径。,{0} is not an absolute
log_load_dll_argument_null_exception,{0}参数为空。,The {0} parameter is empty.,{0}パラメータが空です。
log_load_dll_file_load_exception,加载DLL文件{0}失败。,Failed to load the DLL file {0}.,DLLファイル{0}のロードに失敗しました。
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ファイルを正常にロードしました。
\ No newline at end of file
+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}に位置するモジュールフォルダは存在しません。
\ No newline at end of file
diff --git a/scripts/Config.cs b/scripts/Config.cs
index 7cf9ba5..4c9668b 100644
--- a/scripts/Config.cs
+++ b/scripts/Config.cs
@@ -65,6 +65,12 @@ public static class Config
///
public const int HeartRepresentsHealthValue = 4;
+ ///
+ /// The name of the mod manifest file
+ /// 模组清单文件的名字
+ ///
+ public const string ModManifestFileName = "ModManifest.yaml";
+
///
/// The maximum number of stacked items in a single inventory
/// 单个物品栏最大堆叠的物品数量
diff --git a/scripts/debug/LogCat.cs b/scripts/debug/LogCat.cs
index 91324b7..607da7a 100644
--- a/scripts/debug/LogCat.cs
+++ b/scripts/debug/LogCat.cs
@@ -247,7 +247,15 @@ public static class LogCat
LogCollector.Push(logData);
}
- GD.Print(concreteLog);
+ switch (level)
+ {
+ case ErrorLogLevel:
+ GD.PrintErr(concreteLog);
+ break;
+ default:
+ GD.Print(concreteLog);
+ break;
+ }
}
///
@@ -274,7 +282,7 @@ public static class LogCat
public static void LogErrorWithFormat(string message, string label, bool upload, params object?[] args)
{
- PrintLog(WarningLogLevel, string.Format(HandleMessage(ErrorLogLevel, message, label).ToString(), args), label,
+ PrintLog(ErrorLogLevel, string.Format(HandleMessage(ErrorLogLevel, message, label).ToString(), args), label,
upload);
}
diff --git a/scripts/mod/ModLoader.cs b/scripts/mod/ModLoader.cs
index 2a4b41e..380b7bb 100644
--- a/scripts/mod/ModLoader.cs
+++ b/scripts/mod/ModLoader.cs
@@ -99,7 +99,35 @@ public class ModLoader
}
}
- public static void LoadMod()
+ ///
+ /// Load a module for a directory
+ /// 加载某个目录的模组
+ ///
+ ///
+ ///Mod path
+ ///模组路径
+ ///
+ public static void LoadMod(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;
+ }
+
+ try
+ {
+ var modManifest =
+ ModManifest.CreateModManifestFromPath(Path.Join(modFolderPath, Config.ModManifestFileName));
+ }
+ catch (FileNotFoundException fileNotFoundException)
+ {
+ //Do not continue to load the file when it does not exist.
+ //当文件不存在时就不要继续加载了。
+ LogCat.WhenCaughtException(fileNotFoundException, LogCat.LogLabel.ModLoader);
+ return;
+ }
}
}
\ No newline at end of file
diff --git a/scripts/mod/ModManifest.cs b/scripts/mod/ModManifest.cs
new file mode 100644
index 0000000..4892f9d
--- /dev/null
+++ b/scripts/mod/ModManifest.cs
@@ -0,0 +1,68 @@
+using System;
+using System.IO;
+using ColdMint.scripts.serialization;
+
+namespace ColdMint.scripts.mod;
+
+///
+/// Module manifest file
+/// 模组清单文件
+///
+public class ModManifest
+{
+ ///
+ /// 模组Id
+ ///
+ public string? Id { get; set; }
+
+ ///
+ /// Mod name
+ /// 模组名称
+ ///
+ public string? Name { get; set; }
+
+ ///
+ /// Dll path list of the mod
+ /// 模组的Dll路径列表
+ ///
+ public string[]? DllList { get; set; }
+
+ ///
+ /// Pck path list of mod
+ /// 模组的Pck路径列表
+ ///
+ public string[]? PckList { get; set; }
+
+ ///
+ /// Creates module list information from a path
+ /// 从路径创建模组清单信息
+ ///
+ ///
+ ///filePath
+ ///文件路径
+ ///
+ ///
+ ///When a given path is not to end throw this exception.
+ ///当给定的路径不是以结尾时抛出此异常。
+ ///
+ ///
+ ///This exception is thrown when the given path does not exist.
+ ///当给定的路径不存在时,抛出此异常。
+ ///
+ ///
+ public static ModManifest CreateModManifestFromPath(string filePath)
+ {
+ if (!filePath.EndsWith(Config.ModManifestFileName))
+ {
+ throw new ArgumentException("path must end with " + Config.ModManifestFileName + ".");
+ }
+
+ if (!File.Exists(filePath))
+ {
+ throw new FileNotFoundException("The file at " + filePath + " does not exist.");
+ }
+
+ var content = File.ReadAllText(filePath);
+ return YamlSerialization.Deserialize(content);
+ }
+}
\ No newline at end of file