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

105 lines
3.4 KiB
C#
Raw Normal View History

2023-01-08 16:57:10 +00:00
using LinePutScript;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Threading;
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-01-10 10:43:32 +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();
if (list.Count() == 0)
{
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-30 16:51:17 +00:00
//throw new Exception("未知的图像类型: " + path_name);
2023-02-22 05:37:23 +00:00
#endif
}
else if (File.Exists(di.FullName + @"\info.lps"))
{//如果自带描述信息,则手动加载
//TODO:
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
}
}
}
}