2024-03-15 17:33:56 +00:00
|
|
|
|
using LinePutScript.Converter;
|
|
|
|
|
using LinePutScript.Dictionary;
|
|
|
|
|
using LinePutScript.Localization.WPF;
|
|
|
|
|
using LinePutScript;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using VPet_Simulator.Core;
|
|
|
|
|
using VPet_Simulator.Windows.Interface;
|
|
|
|
|
|
|
|
|
|
namespace VPet_Simulator.Windows;
|
|
|
|
|
public class MPMOD
|
|
|
|
|
{
|
|
|
|
|
public static void LoadImage(MPFriends mw, DirectoryInfo di, string pre = "")
|
|
|
|
|
{
|
|
|
|
|
//加载其他放在文件夹的图片
|
|
|
|
|
foreach (FileInfo fi in di.EnumerateFiles("*.png"))
|
|
|
|
|
{
|
|
|
|
|
mw.ImageSources.AddSource(pre + fi.Name.ToLower().Substring(0, fi.Name.Length - 4), fi.FullName);
|
|
|
|
|
}
|
|
|
|
|
//加载其他放在文件夹中文件夹的图片
|
|
|
|
|
foreach (DirectoryInfo fordi in di.EnumerateDirectories())
|
|
|
|
|
{
|
|
|
|
|
LoadImage(mw, fordi, pre + fordi.Name + "_");
|
|
|
|
|
}
|
|
|
|
|
//加载标志好的图片和图片设置
|
|
|
|
|
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
|
|
|
|
|
{
|
|
|
|
|
var tmp = new LpsDocument(File.ReadAllText(fi.FullName));
|
|
|
|
|
if (fi.Name.ToLower().StartsWith("set_"))
|
|
|
|
|
foreach (var line in tmp)
|
|
|
|
|
mw.ImageSources.ImageSetting.AddorReplaceLine(line);
|
|
|
|
|
else
|
|
|
|
|
mw.ImageSources.AddImages(tmp, di.FullName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public MPMOD(DirectoryInfo directory, MPFriends mw)
|
|
|
|
|
{
|
|
|
|
|
#if !DEBUG
|
2024-03-16 11:22:07 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
2024-03-15 17:33:56 +00:00
|
|
|
|
#endif
|
2024-03-16 11:22:07 +00:00
|
|
|
|
var Path = directory;
|
|
|
|
|
LpsDocument modlps = new LpsDocument(File.ReadAllText(directory.FullName + @"\info.lps"));
|
|
|
|
|
Name = modlps.FindLine("vupmod").Info;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
|
2024-03-16 11:22:07 +00:00
|
|
|
|
//MOD未加载时支持翻译
|
|
|
|
|
foreach (var line in modlps.FindAllLine("lang"))
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-16 11:22:07 +00:00
|
|
|
|
List<ILine> ls = new List<ILine>();
|
|
|
|
|
foreach (var sub in line)
|
|
|
|
|
{
|
|
|
|
|
ls.Add(new Line(sub.Name, sub.info));
|
|
|
|
|
}
|
|
|
|
|
LocalizeCore.AddCulture(line.info, ls);
|
|
|
|
|
}
|
|
|
|
|
if (!IsOnMOD(mw))
|
|
|
|
|
{
|
|
|
|
|
return;
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-16 11:22:07 +00:00
|
|
|
|
foreach (DirectoryInfo di in Path.EnumerateDirectories())
|
|
|
|
|
{
|
|
|
|
|
switch (di.Name.ToLower())
|
|
|
|
|
{
|
|
|
|
|
case "pet":
|
|
|
|
|
//宠物模型
|
|
|
|
|
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-16 11:22:07 +00:00
|
|
|
|
LpsDocument lps = new LpsDocument(File.ReadAllText(fi.FullName));
|
|
|
|
|
if (lps.First().Name.ToLower() == "pet")
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-16 11:22:07 +00:00
|
|
|
|
var name = lps.First().Info;
|
|
|
|
|
var p = mw.Pets.FirstOrDefault(x => x.Name == name);
|
|
|
|
|
if (p == null)
|
|
|
|
|
{
|
|
|
|
|
p = new PetLoader(lps, di);
|
|
|
|
|
mw.Pets.Add(p);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var dis = new DirectoryInfo(di.FullName + "\\" + lps.First()["path"].Info);
|
|
|
|
|
p.path.Add(di.FullName + "\\" + lps.First()["path"].Info);
|
|
|
|
|
p.Config.Set(lps);
|
|
|
|
|
}
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
2024-03-16 11:22:07 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "food":
|
|
|
|
|
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
|
|
|
|
|
{
|
|
|
|
|
var tmp = new LpsDocument(File.ReadAllText(fi.FullName));
|
|
|
|
|
foreach (ILine li in tmp)
|
|
|
|
|
{
|
|
|
|
|
if (li.Name != "food")
|
|
|
|
|
continue;
|
|
|
|
|
string tmps = li.Find("name").info;
|
|
|
|
|
mw.Foods.RemoveAll(x => x.Name == tmps);
|
|
|
|
|
mw.Foods.Add(LPSConvert.DeserializeObject<Food>(li));
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-16 11:22:07 +00:00
|
|
|
|
break;
|
|
|
|
|
case "image":
|
|
|
|
|
LoadImage(mw, di);
|
|
|
|
|
break;
|
|
|
|
|
case "lang":
|
|
|
|
|
foreach (FileInfo fi in di.EnumerateFiles("*.lps"))
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-16 11:22:07 +00:00
|
|
|
|
LocalizeCore.AddCulture(fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length), new LPS_D(File.ReadAllText(fi.FullName)));
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
2024-03-16 11:22:07 +00:00
|
|
|
|
foreach (DirectoryInfo dis in di.EnumerateDirectories())
|
2024-03-15 17:33:56 +00:00
|
|
|
|
{
|
2024-03-16 11:22:07 +00:00
|
|
|
|
foreach (FileInfo fi in dis.EnumerateFiles("*.lps"))
|
|
|
|
|
{
|
|
|
|
|
LocalizeCore.AddCulture(dis.Name, new LPS_D(File.ReadAllText(fi.FullName)));
|
|
|
|
|
}
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
2024-03-16 11:22:07 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
2024-03-16 11:22:07 +00:00
|
|
|
|
#if !DEBUG
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
2024-03-16 11:22:07 +00:00
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-03-15 17:33:56 +00:00
|
|
|
|
}
|
|
|
|
|
public bool IsOnMOD(MPFriends mw) => mw.IsOnMod(Name);
|
|
|
|
|
}
|