diff --git a/VPet.Solution/Models/ModLoader.cs b/VPet.Solution/Models/ModLoader.cs index a14cda3..e9abc02 100644 --- a/VPet.Solution/Models/ModLoader.cs +++ b/VPet.Solution/Models/ModLoader.cs @@ -15,6 +15,7 @@ using System.Threading.Tasks; using VPet_Simulator.Core; using VPet_Simulator.Windows.Interface; using System.Windows.Media.Imaging; +using LinePutScript.Localization.WPF; namespace VPet.Solution.Models; @@ -75,10 +76,21 @@ public class ModLoader public BitmapImage? Image { get; } = null; + /// + /// 读取成功 + /// + public bool IsSuccesses { get; } = true; + public ModLoader(string path) { + var infoFile = Path.Combine(path, "info.lps"); + if (File.Exists(infoFile) is false) + { + IsSuccesses = false; + return; + } + var modlps = new LpsDocument(File.ReadAllText(infoFile)); ModPath = path; - var modlps = new LpsDocument(File.ReadAllText(Path.Combine(path + @"\info.lps"))); Name = modlps.FindLine("vupmod").Info; Intro = modlps.FindLine("intro").Info; GameVer = modlps.FindSub("gamever").InfoToInt; @@ -104,7 +116,8 @@ public class ModLoader } foreach (var dir in Directory.EnumerateDirectories(path)) { - switch (dir.ToLower()) + var dirName = Path.GetFileName(dir); + switch (dirName.ToLower()) { case "pet": //宠物模型 @@ -121,6 +134,23 @@ public class ModLoader break; case "lang": Tags.Add("lang"); + foreach (var langFile in Directory.EnumerateFiles(dir, "*.lps")) + { + LocalizeCore.AddCulture( + Path.GetFileNameWithoutExtension(dir), + new LPS_D(File.ReadAllText(langFile)) + ); + } + foreach (var langDir in Directory.EnumerateDirectories(dir)) + { + foreach (var langFile in Directory.EnumerateFiles(langDir, "*.lps")) + { + LocalizeCore.AddCulture( + Path.GetFileNameWithoutExtension(langDir), + new LPS_D(File.ReadAllText(langFile)) + ); + } + } break; } } diff --git a/VPet.Solution/Models/SettingEditor/ModSettingModel.cs b/VPet.Solution/Models/SettingEditor/ModSettingModel.cs index 6e3c122..0d44c82 100644 --- a/VPet.Solution/Models/SettingEditor/ModSettingModel.cs +++ b/VPet.Solution/Models/SettingEditor/ModSettingModel.cs @@ -17,6 +17,7 @@ public class ModSettingModel : ObservableClass public const string ModLineName = "onmod"; public const string PassModLineName = "passmod"; public const string MsgModLineName = "msgmod"; + public const string WorkShopLineName = "workshop"; public static string ModDirectory = Path.Combine(Environment.CurrentDirectory, "mod"); public static Dictionary LocalMods = Directory.Exists(ModDirectory) is false ? new(StringComparer.OrdinalIgnoreCase) @@ -40,7 +41,7 @@ public class ModSettingModel : ObservableClass foreach (var item in setting[ModLineName]) { var modName = item.Name; - if (LocalMods.TryGetValue(modName, out var loader)) + if (LocalMods.TryGetValue(modName, out var loader) && loader.IsSuccesses) { var modModel = new ModModel(loader); modModel.IsPass = setting[PassModLineName].Contains(modName); @@ -50,6 +51,16 @@ public class ModSettingModel : ObservableClass else Mods.Add(new()); } + foreach (var modPath in setting[WorkShopLineName]) + { + var loader = new ModLoader(modPath.Name); + if (loader.IsSuccesses is false) + return; + var modModel = new ModModel(loader); + modModel.IsPass = setting[PassModLineName].Contains(modModel.Name); + modModel.IsMsg = setting[MsgModLineName].Contains(modModel.Name); + Mods.Add(modModel); + } } public void Close()