2023-01-08 16:57:10 +00:00
|
|
|
|
using LinePutScript;
|
2023-07-01 07:46:08 +00:00
|
|
|
|
using LinePutScript.Localization.WPF;
|
2023-01-08 16:57:10 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2023-05-31 17:47:23 +00:00
|
|
|
|
using System.Windows.Forms;
|
2023-07-16 23:58:09 +00:00
|
|
|
|
using static VPet_Simulator.Core.GameSave;
|
2023-01-08 16:57:10 +00:00
|
|
|
|
using static VPet_Simulator.Core.GraphCore;
|
|
|
|
|
|
2023-07-16 23:58:09 +00:00
|
|
|
|
|
2023-01-20 07:08:28 +00:00
|
|
|
|
namespace VPet_Simulator.Core
|
2023-01-08 16:57:10 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2023-01-20 07:08:28 +00:00
|
|
|
|
/// 宠物加载器
|
2023-01-08 16:57:10 +00:00
|
|
|
|
/// </summary>
|
2023-01-20 07:08:28 +00:00
|
|
|
|
public class PetLoader
|
2023-01-08 16:57:10 +00:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 宠物图像
|
|
|
|
|
/// </summary>
|
2023-01-22 17:33:13 +00:00
|
|
|
|
public GraphCore Graph()
|
2023-01-08 16:57:10 +00:00
|
|
|
|
{
|
2023-01-18 18:00:30 +00:00
|
|
|
|
var g = new GraphCore();
|
|
|
|
|
foreach (var p in path)
|
2023-07-16 23:58:09 +00:00
|
|
|
|
LoadGraph(g, new DirectoryInfo(p));
|
2023-01-20 07:08:28 +00:00
|
|
|
|
g.GraphConfig = Config;
|
2023-01-18 18:00:30 +00:00
|
|
|
|
return g;
|
2023-01-08 16:57:10 +00:00
|
|
|
|
}
|
2023-01-10 10:43:32 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 图像位置
|
|
|
|
|
/// </summary>
|
|
|
|
|
public List<string> path = new List<string>();
|
2023-01-08 16:57:10 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 宠物名字
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Name;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 宠物介绍
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Intor;
|
2023-01-20 07:08:28 +00:00
|
|
|
|
public GraphCore.Config Config;
|
|
|
|
|
public PetLoader(LpsDocument lps, DirectoryInfo directory)
|
2023-01-08 16:57:10 +00:00
|
|
|
|
{
|
|
|
|
|
Name = lps.First().Info;
|
|
|
|
|
Intor = lps.First()["intor"].Info;
|
2023-01-10 10:43:32 +00:00
|
|
|
|
path.Add(directory.FullName + "\\" + lps.First()["path"].Info);
|
2023-01-20 07:08:28 +00:00
|
|
|
|
Config = new Config(lps);
|
2023-01-08 16:57:10 +00:00
|
|
|
|
}
|
2023-05-31 17:47:23 +00:00
|
|
|
|
public delegate void LoadGraphDelegate(GraphCore graph, FileSystemInfo path, ILine info);
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 自定义图片加载方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static Dictionary<string, LoadGraphDelegate> IGraphConvert = new Dictionary<string, LoadGraphDelegate>()
|
|
|
|
|
{
|
|
|
|
|
{ "pnganimation", PNGAnimation.LoadGraph},
|
2023-06-01 08:16:45 +00:00
|
|
|
|
{ "picture", Picture.LoadGraph },
|
|
|
|
|
{ "foodanimation", FoodAnimation.LoadGraph },
|
2023-05-31 17:47:23 +00:00
|
|
|
|
};
|
2023-07-16 23:58:09 +00:00
|
|
|
|
public static void LoadGraph(GraphCore graph, DirectoryInfo di)
|
2023-01-08 16:57:10 +00:00
|
|
|
|
{
|
|
|
|
|
var list = di.EnumerateDirectories();
|
2023-05-31 17:47:23 +00:00
|
|
|
|
if (File.Exists(di.FullName + @"\info.lps"))
|
|
|
|
|
{
|
|
|
|
|
//如果自带描述信息,则手动加载
|
|
|
|
|
LpsDocument lps = new LpsDocument(File.ReadAllText(di.FullName + @"\info.lps"));
|
|
|
|
|
foreach (ILine line in lps)
|
|
|
|
|
{
|
|
|
|
|
if (IGraphConvert.TryGetValue(line.Name.ToLower(), out var func))
|
|
|
|
|
{
|
|
|
|
|
var str = line.GetString("path");
|
|
|
|
|
if (!string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
var p = Path.Combine(di.FullName, str);
|
2023-06-01 08:16:45 +00:00
|
|
|
|
if (Directory.Exists(p))
|
2023-05-31 17:47:23 +00:00
|
|
|
|
func.Invoke(graph, new DirectoryInfo(p), line);
|
|
|
|
|
else if (File.Exists(p))
|
|
|
|
|
func.Invoke(graph, new FileInfo(p), line);
|
|
|
|
|
else
|
2023-07-01 07:46:08 +00:00
|
|
|
|
MessageBox.Show(LocalizeCore.Translate("未知的图像位置: ") + p);
|
2023-05-31 17:47:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
func.Invoke(graph, di, line);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-20 18:39:54 +00:00
|
|
|
|
if (!string.IsNullOrEmpty(line.Name))
|
2023-07-01 07:46:08 +00:00
|
|
|
|
MessageBox.Show(LocalizeCore.Translate("未知的图像类型: ") + line.Name.ToLower());
|
2023-05-31 17:47:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (list.Count() == 0)
|
2023-07-16 23:58:09 +00:00
|
|
|
|
{//开始自动生成
|
|
|
|
|
var paths = di.GetFiles();
|
|
|
|
|
if (paths.Length == 0)
|
|
|
|
|
return;
|
|
|
|
|
if (paths.Length == 1)
|
|
|
|
|
Picture.LoadGraph(graph, paths[0], new Line("picture"));
|
|
|
|
|
else
|
|
|
|
|
PNGAnimation.LoadGraph(graph, di, new Line("pnganimation"));
|
2023-02-22 05:37:23 +00:00
|
|
|
|
}
|
2023-01-08 16:57:10 +00:00
|
|
|
|
else
|
|
|
|
|
foreach (var p in list)
|
|
|
|
|
{
|
2023-07-16 23:58:09 +00:00
|
|
|
|
LoadGraph(graph, p);
|
2023-01-08 16:57:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|