Add ModManifest class.
添加ModManifest类。
This commit is contained in:
parent
aa35550940
commit
d218109354
|
@ -97,3 +97,4 @@ log_load_dll_argument_null_exception,{0}参数为空。,The {0} parameter is emp
|
||||||
log_load_dll_file_load_exception,加载DLL文件{0}失败。,Failed to load the DLL file {0}.,DLLファイル{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_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_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}に位置するモジュールフォルダは存在しません。
|
|
|
@ -65,6 +65,12 @@ public static class Config
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const int HeartRepresentsHealthValue = 4;
|
public const int HeartRepresentsHealthValue = 4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>The name of the mod manifest file</para>
|
||||||
|
/// <para>模组清单文件的名字</para>
|
||||||
|
/// </summary>
|
||||||
|
public const string ModManifestFileName = "ModManifest.yaml";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>The maximum number of stacked items in a single inventory</para>
|
/// <para>The maximum number of stacked items in a single inventory</para>
|
||||||
/// <para>单个物品栏最大堆叠的物品数量</para>
|
/// <para>单个物品栏最大堆叠的物品数量</para>
|
||||||
|
|
|
@ -247,7 +247,15 @@ public static class LogCat
|
||||||
LogCollector.Push(logData);
|
LogCollector.Push(logData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (level)
|
||||||
|
{
|
||||||
|
case ErrorLogLevel:
|
||||||
|
GD.PrintErr(concreteLog);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
GD.Print(concreteLog);
|
GD.Print(concreteLog);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -274,7 +282,7 @@ public static class LogCat
|
||||||
|
|
||||||
public static void LogErrorWithFormat(string message, string label, bool upload, params object?[] args)
|
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);
|
upload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,35 @@ public class ModLoader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadMod()
|
/// <summary>
|
||||||
|
/// <para>Load a module for a directory</para>
|
||||||
|
/// <para>加载某个目录的模组</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="modFolderPath">
|
||||||
|
///<para>Mod path</para>
|
||||||
|
///<para>模组路径</para>
|
||||||
|
/// </param>
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
68
scripts/mod/ModManifest.cs
Normal file
68
scripts/mod/ModManifest.cs
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using ColdMint.scripts.serialization;
|
||||||
|
|
||||||
|
namespace ColdMint.scripts.mod;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Module manifest file</para>
|
||||||
|
/// <para>模组清单文件</para>
|
||||||
|
/// </summary>
|
||||||
|
public class ModManifest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>模组Id</para>
|
||||||
|
/// </summary>
|
||||||
|
public string? Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Mod name</para>
|
||||||
|
/// <para>模组名称</para>
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Dll path list of the mod</para>
|
||||||
|
/// <para>模组的Dll路径列表</para>
|
||||||
|
/// </summary>
|
||||||
|
public string[]? DllList { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Pck path list of mod</para>
|
||||||
|
/// <para>模组的Pck路径列表</para>
|
||||||
|
/// </summary>
|
||||||
|
public string[]? PckList { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Creates module list information from a path</para>
|
||||||
|
/// <para>从路径创建模组清单信息</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filePath">
|
||||||
|
///<para>filePath</para>
|
||||||
|
///<para>文件路径</para>
|
||||||
|
/// </param>
|
||||||
|
/// <exception cref="ArgumentException">
|
||||||
|
///<para>When a given path is not to <see cref="Config.ModManifestFileName"/> end throw this exception.</para>
|
||||||
|
///<para>当给定的路径不是以<see cref="Config.ModManifestFileName"/>结尾时抛出此异常。</para>
|
||||||
|
/// </exception>
|
||||||
|
/// <exception cref="FileNotFoundException">
|
||||||
|
///<para>This exception is thrown when the given path does not exist.</para>
|
||||||
|
///<para>当给定的路径不存在时,抛出此异常。</para>
|
||||||
|
/// </exception>
|
||||||
|
/// <returns></returns>
|
||||||
|
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<ModManifest>(content);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user