using LinePutScript; using LinePutScript.Localization.WPF; using System.Collections.Generic; using System.IO; using System.Linq; using System.Windows.Forms; using static VPet_Simulator.Core.GameSave; using static VPet_Simulator.Core.GraphCore; namespace VPet_Simulator.Core { /// /// 宠物加载器 /// public class PetLoader { /// /// 宠物图像 /// public GraphCore Graph(int Resolution) { var g = new GraphCore(Resolution); foreach (var p in path) LoadGraph(g, new DirectoryInfo(p), p); g.GraphConfig = Config; return g; } /// /// 图像位置 /// public List path = new List(); /// /// 宠物介绍名字 /// public string Name; /// /// 宠物介绍 /// public string Intor; /// /// 宠物默认名字 /// public string PetName; public GraphCore.Config Config; public PetLoader(LpsDocument lps, DirectoryInfo directory) { Name = lps.First().Info; Intor = lps.First()["intor"].Info; PetName = lps.First()["petname"].Info; path.Add(directory.FullName + "\\" + lps.First()["path"].Info); Config = new Config(lps); } public delegate void LoadGraphDelegate(GraphCore graph, FileSystemInfo path, ILine info); /// /// 自定义图片加载方法 /// public static Dictionary IGraphConvert = new Dictionary() { { "pnganimation", PNGAnimation.LoadGraph}, { "picture", Picture.LoadGraph }, { "foodanimation", FoodAnimation.LoadGraph }, }; /// /// 加载图像动画 /// /// 要加载的动画核心 /// 当前历遍的目录 /// 起始目录 public static void LoadGraph(GraphCore graph, DirectoryInfo di, string startuppath) { var list = di.EnumerateDirectories(); 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)) { line.Add(new Sub("startuppath", startuppath)); var str = line.GetString("path"); if (!string.IsNullOrEmpty(str)) { var p = Path.Combine(di.FullName, str); if (Directory.Exists(p)) func.Invoke(graph, new DirectoryInfo(p), line); else if (File.Exists(p)) func.Invoke(graph, new FileInfo(p), line); else MessageBox.Show(LocalizeCore.Translate("未知的图像位置: ") + p); } else func.Invoke(graph, di, line); } else { if (!string.IsNullOrEmpty(line.Name)) MessageBox.Show(LocalizeCore.Translate("未知的图像类型: ") + line.Name.ToLower()); } } } else if (list.Count() == 0) {//开始自动生成 var paths = di.GetFiles(); if (paths.Length == 0) return; if (paths.Length == 1) Picture.LoadGraph(graph, paths[0], new Line("picture", "", "", new Sub("startuppath", startuppath))); else PNGAnimation.LoadGraph(graph, di, new Line("pnganimation", "", "", new Sub("startuppath", startuppath))); } else foreach (var p in list) { LoadGraph(graph, p, startuppath); } } } }