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

136 lines
5.0 KiB
C#
Raw Normal View History

2023-01-08 16:57:10 +00:00
using LinePutScript;
using System.Collections.Generic;
using System.IO;
using System.Linq;
2023-05-31 17:47:23 +00:00
using System.Windows.Forms;
2023-01-08 16:57:10 +00:00
using static VPet_Simulator.Core.GraphCore;
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
{
var g = new GraphCore();
foreach (var p in path)
2023-01-22 17:33:13 +00:00
LoadGraph(g, new DirectoryInfo(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>
/// 宠物名字
/// </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-01-22 17:33:13 +00:00
public static void LoadGraph(GraphCore graph, DirectoryInfo di, string path_name)
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
MessageBox.Show("未知的图像位置: " + p);
}
else
func.Invoke(graph, di, line);
}
else
{
MessageBox.Show("未知的图像类型: " + line.Name.ToLower());
}
}
}
else if (list.Count() == 0)
2023-01-08 16:57:10 +00:00
{
2023-02-22 05:37:23 +00:00
//自动加载 PNG ANMIN
path_name = path_name.Trim('_').ToLower();
for (int i = 0; i < GraphTypeValue.Length; i++)
{
if (path_name.StartsWith(GraphTypeValue[i]))
2023-01-08 16:57:10 +00:00
{
2023-05-15 10:44:30 +00:00
bool isused = false;
2023-02-22 05:37:23 +00:00
if (path_name.Contains("happy"))
2023-01-08 16:57:10 +00:00
{
2023-05-09 23:16:58 +00:00
graph.AddGraph(di.FullName, GameSave.ModeType.Happy, (GraphType)i);
2023-05-15 10:44:30 +00:00
isused = true;
2023-02-22 05:37:23 +00:00
}
if (path_name.Contains("nomal"))
{
2023-05-09 23:16:58 +00:00
graph.AddGraph(di.FullName, GameSave.ModeType.Nomal, (GraphType)i);
2023-05-15 10:44:30 +00:00
isused = true;
2023-02-22 05:37:23 +00:00
}
if (path_name.Contains("poorcondition"))
{
2023-05-09 23:16:58 +00:00
graph.AddGraph(di.FullName, GameSave.ModeType.PoorCondition, (GraphType)i);
2023-05-15 10:44:30 +00:00
isused = true;
2023-02-22 05:37:23 +00:00
}
if (path_name.Contains("ill"))
{
2023-05-09 23:16:58 +00:00
graph.AddGraph(di.FullName, GameSave.ModeType.Ill, (GraphType)i);
2023-05-15 10:44:30 +00:00
isused = true;
2023-01-08 16:57:10 +00:00
}
2023-05-15 10:44:30 +00:00
if (!isused)
2023-03-28 13:18:14 +00:00
{
2023-05-09 23:16:58 +00:00
graph.AddGraph(di.FullName, GameSave.ModeType.Nomal, (GraphType)i);
2023-03-28 13:18:14 +00:00
}
2023-02-22 05:37:23 +00:00
return;
2023-01-08 16:57:10 +00:00
}
}
2023-02-22 05:37:23 +00:00
#if DEBUG
2023-05-31 17:47:23 +00:00
MessageBox.Show("未知的图像类型: " + path_name);
2023-02-22 05:37:23 +00:00
#endif
}
2023-01-08 16:57:10 +00:00
else
foreach (var p in list)
{
2023-01-22 17:33:13 +00:00
LoadGraph(graph, p, path_name + "_" + p.Name);
2023-01-08 16:57:10 +00:00
}
}
}
}