VPet/VPet-Simulator.Core/Handle/PetLoader.cs

122 lines
4.5 KiB
C#
Raw Normal View History

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-08-12 06:09:20 +00:00
public GraphCore Graph(int Resolution)
2023-01-08 16:57:10 +00:00
{
2023-08-12 06:09:20 +00:00
var g = new GraphCore(Resolution);
foreach (var p in path)
2023-07-17 15:38:06 +00:00
LoadGraph(g, new DirectoryInfo(p), p);
2023-01-20 07:08:28 +00:00
g.GraphConfig = Config;
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>
2023-08-09 14:17:28 +00:00
/// 宠物介绍名字
2023-01-08 16:57:10 +00:00
/// </summary>
public string Name;
/// <summary>
/// 宠物介绍
/// </summary>
public string Intor;
2023-08-09 14:17:28 +00:00
/// <summary>
/// 宠物默认名字
/// </summary>
public string PetName;
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-08-09 14:17:28 +00:00
PetName = lps.First()["petname"].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-17 15:38:06 +00:00
/// <summary>
/// 加载图像动画
/// </summary>
/// <param name="graph">要加载的动画核心</param>
/// <param name="di">当前历遍的目录</param>
/// <param name="startuppath">起始目录</param>
public static void LoadGraph(GraphCore graph, DirectoryInfo di, string startuppath)
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))
{
2023-07-17 15:38:06 +00:00
line.Add(new Sub("startuppath", startuppath));
2023-05-31 17:47:23 +00:00
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)
2023-07-17 15:38:06 +00:00
Picture.LoadGraph(graph, paths[0], new Line("picture", "", "", new Sub("startuppath", startuppath)));
2023-07-16 23:58:09 +00:00
else
2023-07-17 15:38:06 +00:00
PNGAnimation.LoadGraph(graph, di, new Line("pnganimation", "", "", new Sub("startuppath", startuppath)));
2023-02-22 05:37:23 +00:00
}
2023-01-08 16:57:10 +00:00
else
foreach (var p in list)
{
2023-07-17 15:38:06 +00:00
LoadGraph(graph, p, startuppath);
2023-01-08 16:57:10 +00:00
}
}
}
}