VPet.Solution 新增 setting-workshop支持

This commit is contained in:
Hakoyu 2024-01-19 03:44:39 +08:00
parent 66d955e4bd
commit 94e34d2aaf
2 changed files with 44 additions and 3 deletions

View File

@ -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;
/// <summary>
/// 读取成功
/// </summary>
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;
}
}

View File

@ -17,6 +17,7 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
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<string, ModLoader> LocalMods = Directory.Exists(ModDirectory) is false
? new(StringComparer.OrdinalIgnoreCase)
@ -40,7 +41,7 @@ public class ModSettingModel : ObservableClass<ModSettingModel>
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<ModSettingModel>
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()