diff --git a/VPet.ModMaker/Models/ModModel/AnimeModel.cs b/VPet.ModMaker/Models/ModModel/AnimeModel.cs index 5746a6d..8866c22 100644 --- a/VPet.ModMaker/Models/ModModel/AnimeModel.cs +++ b/VPet.ModMaker/Models/ModModel/AnimeModel.cs @@ -43,17 +43,6 @@ public class AnimeTypeModel IllAnimes.Add(anime.Copy()); } - public AnimeTypeModel(GraphInfo.GraphType graphType, string path) - { - GraphType.Value = graphType; - if (graphType is GraphInfo.GraphType.Default) - LoadDefault(path); - else if (graphType is GraphInfo.GraphType.Touch_Head or GraphInfo.GraphType.Touch_Body) - LoadMultiTypeAnime(path); - else - throw new Exception(); - } - public static AnimeTypeModel? Create(GraphInfo.GraphType graphType, string path) { try @@ -67,31 +56,63 @@ public class AnimeTypeModel } } + public AnimeTypeModel(GraphInfo.GraphType graphType, string path) + { + GraphType.Value = graphType; + if ( + graphType + is GraphInfo.GraphType.Default + or GraphInfo.GraphType.Shutdown + or GraphInfo.GraphType.StartUP + ) + LoadDefault(path); + else if ( + graphType + is GraphInfo.GraphType.Touch_Head + or GraphInfo.GraphType.Touch_Body + or GraphInfo.GraphType.Sleep + ) + LoadMultiType(path); + else + throw new Exception(); + } + + //private void LoadSingle(string path) + //{ + // foreach (var dir in Directory.EnumerateDirectories(path)) + // { + // var dirName = Path.GetFileName(dir); + // var dirInfo = dirName.Split(Utils.Separator); + // var mode = Enum.Parse(typeof(GameSave.ModeType), dirInfo[0], true); + // if (dirInfo.Length == 2) { } + // } + //} + private void LoadDefault(string path) { foreach (var dir in Directory.EnumerateDirectories(path)) { - var mode = Enum.Parse(typeof(GameSave.ModeType), Path.GetFileName(dir), true); - if (mode is GameSave.ModeType.Happy) + var dirName = Path.GetFileName(dir); + if (dirName.Contains(nameof(GameSave.ModeType.Happy))) { AddAnime(HappyAnimes, dir); } - else if (mode is GameSave.ModeType.Nomal) + else if (dirName.Contains(nameof(GameSave.ModeType.Nomal))) { AddAnime(NomalAnimes, dir); } - else if (mode is GameSave.ModeType.PoorCondition) + else if (dirName.Contains(nameof(GameSave.ModeType.PoorCondition))) { AddAnime(PoorConditionAnimes, dir); } - else if (mode is GameSave.ModeType.Ill) + else if (dirName.Contains(nameof(GameSave.ModeType.Ill))) { AddAnime(IllAnimes, dir); } } } - private void LoadMultiTypeAnime(string path) + private void LoadMultiType(string path) { foreach (var dir in Directory.EnumerateDirectories(path)) { @@ -182,6 +203,136 @@ public class AnimeTypeModel } } } + + public void Save(string path) + { + if ( + GraphType.Value + is GraphInfo.GraphType.Default + or GraphInfo.GraphType.Shutdown + or GraphInfo.GraphType.StartUP + ) + SaveDefault(path, this); + else if ( + GraphType.Value + is GraphInfo.GraphType.Touch_Head + or GraphInfo.GraphType.Touch_Body + or GraphInfo.GraphType.Sleep + ) + SaveMultiType(path, this); + } + + void SaveMultiType(string path, AnimeTypeModel animeType) + { + var animePath = Path.Combine(path, animeType.GraphType.ToString()); + Directory.CreateDirectory(animePath); + if (animeType.HappyAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Happy)); + SaveAnimes(modePath, animeType.HappyAnimes); + } + if (animeType.NomalAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Nomal)); + SaveAnimes(modePath, animeType.NomalAnimes); + } + if (animeType.PoorConditionAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.PoorCondition)); + SaveAnimes(modePath, animeType.PoorConditionAnimes); + } + if (animeType.IllAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Ill)); + SaveAnimes(modePath, animeType.IllAnimes); + } + + static void SaveAnimes(string animePath, ObservableCollection animes) + { + Directory.CreateDirectory(animePath); + var countA = 0; + var countB = 0; + var countC = 0; + foreach (var anime in animes) + { + if (anime.AnimeType.Value is GraphInfo.AnimatType.A_Start) + { + var animatTypePath = Path.Combine(animePath, "A"); + Directory.CreateDirectory(animatTypePath); + SaveImages(Path.Combine(animatTypePath, countA.ToString()), anime); + countA++; + } + else if (anime.AnimeType.Value is GraphInfo.AnimatType.B_Loop) + { + var animatTypePath = Path.Combine(animePath, "B"); + Directory.CreateDirectory(animatTypePath); + SaveImages(Path.Combine(animatTypePath, countB.ToString()), anime); + countB++; + } + else if (anime.AnimeType.Value is GraphInfo.AnimatType.C_End) + { + var animatTypePath = Path.Combine(animePath, "C"); + Directory.CreateDirectory(animatTypePath); + SaveImages(Path.Combine(animatTypePath, countC.ToString()), anime); + countC++; + } + } + } + } + + static void SaveDefault(string path, AnimeTypeModel animeType) + { + var animePath = Path.Combine(path, animeType.GraphType.ToString()); + Directory.CreateDirectory(animePath); + if (animeType.HappyAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Happy)); + SaveAnimes(modePath, animeType.HappyAnimes); + } + if (animeType.NomalAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Nomal)); + SaveAnimes(modePath, animeType.NomalAnimes); + } + if (animeType.PoorConditionAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.PoorCondition)); + SaveAnimes(modePath, animeType.PoorConditionAnimes); + } + if (animeType.IllAnimes.Count > 0) + { + var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Ill)); + SaveAnimes(modePath, animeType.IllAnimes); + } + static void SaveAnimes(string animePath, ObservableCollection animes) + { + Directory.CreateDirectory(animePath); + var count = 0; + foreach (var anime in animes) + { + SaveImages(Path.Combine(animePath, count.ToString()), anime); + count++; + } + } + } + + static void SaveImages(string imagesPath, AnimeModel model) + { + Directory.CreateDirectory(imagesPath); + var imageIndex = 0; + foreach (var image in model.Images) + { + File.Copy( + image.Image.Value.GetSourceFile(), + Path.Combine( + imagesPath, + $"{model.Id.Value}_{imageIndex:000}_{image.Duration.Value}.png" + ), + true + ); + imageIndex++; + } + } } public class AnimeModel @@ -190,8 +341,6 @@ public class AnimeModel public ObservableValue AnimeType { get; } = new(); - //public ObservableValue ModeType { get; } = new(); - public ObservableCollection Images { get; } = new(); public AnimeModel() { } diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index f0ca72c..395e4c5 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -248,149 +248,8 @@ public class ModInfoModel : I18nModel File.WriteAllText(petFile, lps.ToString()); var petAnimePath = Path.Combine(petPath, pet.Id.Value); - Directory.CreateDirectory(petAnimePath); - SaveAnime_Default(petAnimePath, pet); - SaveAnime_MultiType(petAnimePath, pet); - } - } - - void SaveAnime_MultiType(string path, PetModel pet) - { - if ( - pet.Animes.FirstOrDefault(m => m.GraphType.Value is GraphInfo.GraphType.Touch_Head) - is AnimeTypeModel animeType1 - ) - { - SaveMultiTypeAnime( - Path.Combine(path, nameof(GraphInfo.GraphType.Touch_Head)), - animeType1 - ); - } - if ( - pet.Animes.FirstOrDefault(m => m.GraphType.Value is GraphInfo.GraphType.Touch_Body) - is AnimeTypeModel animeType2 - ) - { - SaveMultiTypeAnime( - Path.Combine(path, nameof(GraphInfo.GraphType.Touch_Body)), - animeType2 - ); - } - - static void SaveMultiTypeAnime(string animePath, AnimeTypeModel model) - { - Directory.CreateDirectory(animePath); - if (model.HappyAnimes.Count > 0) - { - var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Happy)); - SaveAnimes(modePath, model.HappyAnimes); - } - if (model.NomalAnimes.Count > 0) - { - var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Nomal)); - SaveAnimes(modePath, model.NomalAnimes); - } - if (model.PoorConditionAnimes.Count > 0) - { - var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.PoorCondition)); - SaveAnimes(modePath, model.PoorConditionAnimes); - } - if (model.IllAnimes.Count > 0) - { - var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Ill)); - SaveAnimes(modePath, model.IllAnimes); - } - } - - static void SaveAnimes(string animePath, ObservableCollection animes) - { - Directory.CreateDirectory(animePath); - var countA = 0; - var countB = 0; - var countC = 0; - foreach (var anime in animes) - { - if (anime.AnimeType.Value is GraphInfo.AnimatType.A_Start) - { - var animatTypePath = Path.Combine(animePath, "A"); - Directory.CreateDirectory(animatTypePath); - SaveImages(Path.Combine(animatTypePath, countA.ToString()), anime); - countA++; - } - else if (anime.AnimeType.Value is GraphInfo.AnimatType.B_Loop) - { - var animatTypePath = Path.Combine(animePath, "B"); - Directory.CreateDirectory(animatTypePath); - SaveImages(Path.Combine(animatTypePath, countB.ToString()), anime); - countB++; - } - else if (anime.AnimeType.Value is GraphInfo.AnimatType.C_End) - { - var animatTypePath = Path.Combine(animePath, "C"); - Directory.CreateDirectory(animatTypePath); - SaveImages(Path.Combine(animatTypePath, countC.ToString()), anime); - countC++; - } - } - } - } - - void SaveAnime_Default(string path, PetModel pet) - { - if ( - pet.Animes.FirstOrDefault(m => m.GraphType.Value == GraphInfo.GraphType.Default) - is not AnimeTypeModel animeType - ) - return; - var animePath = Path.Combine(path, nameof(GraphInfo.GraphType.Default)); - Directory.CreateDirectory(animePath); - if (animeType.HappyAnimes.Count > 0) - { - var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Happy)); - SaveAnimes(modePath, animeType.HappyAnimes); - } - if (animeType.NomalAnimes.Count > 0) - { - var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Nomal)); - SaveAnimes(modePath, animeType.NomalAnimes); - } - if (animeType.PoorConditionAnimes.Count > 0) - { - var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.PoorCondition)); - SaveAnimes(modePath, animeType.PoorConditionAnimes); - } - if (animeType.IllAnimes.Count > 0) - { - var modePath = Path.Combine(animePath, nameof(GameSave.ModeType.Ill)); - SaveAnimes(modePath, animeType.IllAnimes); - } - static void SaveAnimes(string animePath, ObservableCollection animes) - { - Directory.CreateDirectory(animePath); - var count = 0; - foreach (var anime in animes) - { - SaveImages(Path.Combine(animePath, count.ToString()), anime); - count++; - } - } - } - - static void SaveImages(string imagesPath, AnimeModel model) - { - Directory.CreateDirectory(imagesPath); - var imageIndex = 0; - foreach (var image in model.Images) - { - File.Copy( - image.Image.Value.GetSourceFile(), - Path.Combine( - imagesPath, - $"{model.Id.Value}_{imageIndex:000}_{image.Duration.Value}.png" - ), - true - ); - imageIndex++; + foreach (var animeType in pet.Animes) + animeType.Save(petAnimePath); } } diff --git a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs index 482d2fb..90dfaae 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/AnimeEdit/AnimeEditWindowVM.cs @@ -65,6 +65,7 @@ public class AnimeEditWindowVM model.GraphType.Value is GraphInfo.GraphType.Touch_Body or GraphInfo.GraphType.Touch_Head + or GraphInfo.GraphType.Sleep ) HasMultiType.Value = true; } @@ -72,8 +73,10 @@ public class AnimeEditWindowVM private void CurrentAnimeModel_ValueChanged(AnimeModel oldValue, AnimeModel newValue) { StopCommand_ExecuteEvent(); - oldValue.Images.CollectionChanged -= Images_CollectionChanged; - newValue.Images.CollectionChanged += Images_CollectionChanged; + if (oldValue is not null) + oldValue.Images.CollectionChanged -= Images_CollectionChanged; + if (newValue is not null) + newValue.Images.CollectionChanged += Images_CollectionChanged; } private void Images_CollectionChanged( diff --git a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs index 2d61a72..5a0de71 100644 --- a/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs +++ b/VPet.ModMaker/Views/ModEdit/AnimeEdit/AnimeEditWindow.xaml.cs @@ -60,7 +60,10 @@ public partial class AnimeEditWindow : Window ) return; if (Enum.TryParse(str, true, out var mode)) + { ViewModel.CurrentMode = mode; + ViewModel.CurrentAnimeModel.Value = null; + } } private void ListBox_PreviewMouseWheel(object sender, MouseWheelEventArgs e)