diff --git a/VPet.ModMaker/Models/Expansions.cs b/VPet.ModMaker/Models/Expansions.cs index 8f8208d..2660206 100644 --- a/VPet.ModMaker/Models/Expansions.cs +++ b/VPet.ModMaker/Models/Expansions.cs @@ -21,7 +21,7 @@ public static class Extensions return ((FileStream)image.StreamSource).Name; } - public static void CloseString(this ImageSource source) + public static void CloseStream(this ImageSource source) { if (source is BitmapImage image) { diff --git a/VPet.ModMaker/Models/ModLoader.cs b/VPet.ModMaker/Models/ModLoader.cs index 531947e..e966aaf 100644 --- a/VPet.ModMaker/Models/ModLoader.cs +++ b/VPet.ModMaker/Models/ModLoader.cs @@ -27,7 +27,7 @@ public class ModLoader /// public ulong ItemID { get; } public string Intro { get; } - public DirectoryInfo Path { get; } + public DirectoryInfo ModPath { get; } public int GameVer { get; } public int Ver { get; } public HashSet Tag { get; } = new(); @@ -38,19 +38,18 @@ public class ModLoader public List LowTexts { get; } = new(); public List ClickTexts { get; } = new(); public List SelectTexts { get; } = new(); + public Dictionary MultiGraphs { get; } = new(); public Dictionary I18nDatas { get; } = new(); public Dictionary> OtherI18nDatas { get; } = new(); - public ModLoader(DirectoryInfo directory) + public ModLoader(DirectoryInfo path) { try { - Path = directory; - LpsDocument modlps = new LpsDocument( - File.ReadAllText(directory.FullName + @"\info.lps") - ); + ModPath = path; + LpsDocument modlps = new LpsDocument(File.ReadAllText(path.FullName + @"\info.lps")); Name = modlps.FindLine("vupmod").Info; Intro = modlps.FindLine("intro").Info; GameVer = modlps.FindSub("gamever").InfoToInt; @@ -80,7 +79,7 @@ public class ModLoader I18nDatas.Add(line.Info, i18nData); } DirectoryInfo? langDirectory = null; - foreach (DirectoryInfo di in Path.EnumerateDirectories()) + foreach (DirectoryInfo di in path.EnumerateDirectories()) { switch (di.Name.ToLower()) { @@ -93,7 +92,16 @@ public class ModLoader if (lps.First().Name.ToLower() == "pet") { var name = lps.First().Info; - Pets.Add(new PetLoader(lps, di)); + var pet = new PetLoader(lps, di); + Pets.Add(pet); + // 此方法会导致 LoadImageToStream 无法使用 + //var graphCore = new GraphCore(0); + //foreach (var p in pet.path) + // PetLoader.LoadGraph(graphCore, di, p); + //MultiGraphs.Add(pet.Name, graphCore); + + + //var p = mw.Pets.FirstOrDefault(x => x.Id == name); //if (p == null) // mw.Pets.Add(new PetLoader(lps, di)); @@ -113,7 +121,7 @@ public class ModLoader foreach (ILine li in tmp) { var food = LPSConvert.DeserializeObject(li); - var imagePath = $"{Path.FullName}\\image\\food\\{food.Name}.png"; + var imagePath = $"{path.FullName}\\image\\food\\{food.Name}.png"; if (File.Exists(imagePath)) food.Image = imagePath; Foods.Add(food); @@ -208,7 +216,7 @@ public class ModLoader public void WriteFile() { - var lps = new LpsDocument(File.ReadAllText(Path.FullName + @"\info.lps")); + var lps = new LpsDocument(File.ReadAllText(ModPath.FullName + @"\info.lps")); lps.FindLine("vupmod").Info = Name; lps.FindLine("intro").Info = Intro; lps.FindSub("gamever").InfoToInt = GameVer; @@ -216,6 +224,6 @@ public class ModLoader lps.FindSub("author").Info = Author; lps.FindorAddLine("authorid").InfoToInt64 = AuthorID; lps.FindorAddLine("itemid").info = ItemID.ToString(); - File.WriteAllText(Path.FullName + @"\info.lps", lps.ToString()); + File.WriteAllText(ModPath.FullName + @"\info.lps", lps.ToString()); } } diff --git a/VPet.ModMaker/Models/ModMakerInfo.cs b/VPet.ModMaker/Models/ModMakerInfo.cs index 88264fd..8dfed66 100644 --- a/VPet.ModMaker/Models/ModMakerInfo.cs +++ b/VPet.ModMaker/Models/ModMakerInfo.cs @@ -10,4 +10,5 @@ public static class ModMakerInfo { public const string BaseDirectory = nameof(ModMaker); public const string HistoryFile = $"{BaseDirectory}\\history.lps"; + public const string InfoFile = "info.lps"; } diff --git a/VPet.ModMaker/Models/ModModel/AnimeModel.cs b/VPet.ModMaker/Models/ModModel/AnimeModel.cs index a675e42..8bf8f15 100644 --- a/VPet.ModMaker/Models/ModModel/AnimeModel.cs +++ b/VPet.ModMaker/Models/ModModel/AnimeModel.cs @@ -2,15 +2,36 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media.Imaging; +using VPet_Simulator.Core; +using static VPet_Simulator.Core.GraphInfo; namespace VPet.ModMaker.Models.ModModel; public class AnimeModel { - public ObservableValue CurrentImageModel { get; } = new(); - public ObservableCollection ImageModels { get; } = new(); + public ObservableValue Id { get; } = new(); + public ObservableValue AnimeType { get; } = new(); + + public ObservableCollection> MultiHappyImageModels = new(); + public ObservableCollection> MultiNomalImageModels = new(); + public ObservableCollection> MultiPoorConditionImageModels = + new(); + public ObservableCollection> MultiIllImageModels = new(); + + public AnimeModel() { } + + public AnimeModel(string name, AnimatType animatType, IList graphList) + { + Id.Value = name; + AnimeType.Value = animatType; + foreach (IGraph graph in graphList) + { + //if(graph.) + } + } } diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 8655751..412eb9b 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -9,6 +9,7 @@ using System.Collections.Specialized; using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Media.Imaging; using VPet_Simulator.Windows.Interface; @@ -50,13 +51,15 @@ public class ModInfoModel : I18nModel public ModInfoModel(ModLoader loader) : this() { - SourcePath.Value = loader.Path.FullName; + SourcePath.Value = loader.ModPath.FullName; Id.Value = loader.Name; DescriptionId.Value = loader.Intro; Author.Value = loader.Author; GameVersion.Value = loader.GameVer.ToString(); ModVersion.Value = loader.Ver.ToString(); - var imagePath = Path.Combine(loader.Path.FullName, "icon.png"); + var imagePath = Path.Combine(loader.ModPath.FullName, "icon.png"); + Thread.Sleep(1000); + GC.Collect(); if (File.Exists(imagePath)) Image.Value = Utils.LoadImageToStream(imagePath); foreach (var food in loader.Foods) @@ -243,7 +246,7 @@ public class ModInfoModel : I18nModel new Line("pet", pet.Id.Value) { new Sub("intor", pet.DescriptionId.Value), - new Sub("path", pet.Id.Value), + new Sub("ModPath", pet.Id.Value), new Sub("petname", pet.PetNameId.Value) } ); diff --git a/VPet.ModMaker/Models/ModModel/PetModel.cs b/VPet.ModMaker/Models/ModModel/PetModel.cs index 5e2cbc9..37ec374 100644 --- a/VPet.ModMaker/Models/ModModel/PetModel.cs +++ b/VPet.ModMaker/Models/ModModel/PetModel.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media.Imaging; +using VPet.ModMaker.Models.ModModel; using VPet_Simulator.Core; namespace VPet.ModMaker.Models; @@ -24,6 +25,10 @@ public class PetModel : I18nModel public ObservableCollection Moves { get; } = new(); + public ObservableValue CurrentAnime { get; } = new(); + public Dictionary> Animes { get; } = + new(); + public PetModel() { PetNameId.Value = $"{Id.Value}_{nameof(PetNameId)}"; @@ -112,6 +117,20 @@ public class PetModel : I18nModel Moves.Add(new(move)); } + public void LoadAnime(GraphCore core) + { + foreach (var info in core.GraphsName) + { + var list = new ObservableCollection(); + foreach (var name in info.Value) + { + foreach (var graph in core.GraphsList[name]) + list.Add(new AnimeModel(name, graph.Key, graph.Value)); + } + Animes.Add(info.Key, list); + } + } + public void Close() { } } diff --git a/VPet.ModMaker/Models/Utils.cs b/VPet.ModMaker/Models/Utils.cs index 221ffcd..6c16a37 100644 --- a/VPet.ModMaker/Models/Utils.cs +++ b/VPet.ModMaker/Models/Utils.cs @@ -15,8 +15,14 @@ public static class Utils { BitmapImage bitmapImage = new(); bitmapImage.BeginInit(); - bitmapImage.StreamSource = new StreamReader(imagePath).BaseStream; - bitmapImage.EndInit(); + try + { + bitmapImage.StreamSource = new StreamReader(imagePath).BaseStream; + } + finally + { + bitmapImage.EndInit(); + } return bitmapImage; } @@ -29,11 +35,17 @@ public static class Utils { BitmapImage bitmapImage = new(); bitmapImage.BeginInit(); - var ms = new MemoryStream(); - using var sr = new StreamReader(imagePath); - sr.BaseStream.CopyTo(ms); - bitmapImage.StreamSource = ms; - bitmapImage.EndInit(); + try + { + var ms = new MemoryStream(); + using var sr = new StreamReader(imagePath); + sr.BaseStream.CopyTo(ms); + bitmapImage.StreamSource = ms; + } + finally + { + bitmapImage.EndInit(); + } return bitmapImage; } diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs index a20a45f..73dae39 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs @@ -14,6 +14,8 @@ public class AnimeEditWindowVM { public AnimeModel OldAnime { get; set; } public ObservableValue Anime { get; } = new(new()); + + public ObservableValue CurrentImageModel { get; } = new(); #region Command public ObservableCommand PlayCommand { get; } = new(); public ObservableCommand PauseCommand { get; } = new(); @@ -24,14 +26,14 @@ public class AnimeEditWindowVM public AnimeEditWindowVM() { - foreach ( - var file in Directory.EnumerateFiles( - @"C:\Users\HKW\Desktop\TestPicture\0000_core\pet\vup\Default\Happy\1" - ) - ) - { - Anime.Value.ImageModels.Add(new(Utils.LoadImageToMemoryStream(file))); - } + //foreach ( + // var file in Directory.EnumerateFiles( + // @"C:\Users\HKW\Desktop\TestPicture\0000_core\pet\vup\Default\Happy\1" + // ) + //) + //{ + // Anime.Value.MultiImageModels.Add(new(Utils.LoadImageToMemoryStream(file))); + //} _playerTask = new(Play); PlayCommand.ExecuteEvent += PlayCommand_ExecuteEvent; PauseCommand.ExecuteEvent += PauseCommand_ExecuteEvent; @@ -49,13 +51,13 @@ public class AnimeEditWindowVM private void Play() { - while (_pause is false) - { - foreach (var model in Anime.Value.ImageModels) - { - Anime.Value.CurrentImageModel.Value = model; - Task.Delay(model.Duration.Value).Wait(); - } - } + //while (_pause is false) + //{ + // foreach (var model in Anime.Value.ImageModels) + // { + // Anime.Value.CurrentImageModel.Value = model; + // Task.Delay(model.Duration.Value).Wait(); + // } + //} } } diff --git a/VPet.ModMaker/Views/ModMakerWindow.xaml.cs b/VPet.ModMaker/Views/ModMakerWindow.xaml.cs index 10d2654..059240e 100644 --- a/VPet.ModMaker/Views/ModMakerWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModMakerWindow.xaml.cs @@ -36,7 +36,7 @@ public partial class ModMakerWindow : Window { InitializeComponent(); DataContext = new ModMakerWindowVM(this); - new AnimeEditWindow().Show(); + //new AnimeEditWindow().Show(); } private void ListBoxItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)