From 37b69b92a9798b39dc47fe13c78652f1dc26d9f4 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Wed, 30 Aug 2023 17:00:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=98=E6=A1=A3=E7=B3=BB=E7=BB=9F=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/Models/FoodModel.cs | 2 +- VPet.ModMaker/Models/ModInfoModel.cs | 86 +++++++++++++++++-- .../ViewModels/ModEdit/ModEditWindowVM.cs | 12 +++ VPet.ModMaker/ViewModels/ModMakerWindowVM.cs | 2 +- .../Views/ModEdit/ModEditWindow.xaml | 10 ++- 5 files changed, 102 insertions(+), 10 deletions(-) diff --git a/VPet.ModMaker/Models/FoodModel.cs b/VPet.ModMaker/Models/FoodModel.cs index d1a669e..0f1a7ec 100644 --- a/VPet.ModMaker/Models/FoodModel.cs +++ b/VPet.ModMaker/Models/FoodModel.cs @@ -48,7 +48,7 @@ public class FoodModel : I18nModel : this() { Name = food.Name; - Description = food.Description; + Description = food.Desc; Type.Value = food.Type; Strength.Value = food.Strength; StrengthDrink.Value = food.StrengthDrink; diff --git a/VPet.ModMaker/Models/ModInfoModel.cs b/VPet.ModMaker/Models/ModInfoModel.cs index 16e1aef..f568baf 100644 --- a/VPet.ModMaker/Models/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModInfoModel.cs @@ -1,4 +1,6 @@ using HKW.HKWViewModels.SimpleObservable; +using LinePutScript; +using LinePutScript.Converter; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -16,8 +18,8 @@ public class ModInfoModel : I18nModel { public static ModInfoModel Current { get; set; } - public ObservableValue Id { get; } = new(); - + public ObservableValue Name { get; } = new(); + public ObservableValue Description { get; } = new(); public ObservableValue Summary { get; } = new(); public ObservableValue Author { get; } = new(); public ObservableValue GameVersion { get; } = new(); @@ -35,13 +37,14 @@ public class ModInfoModel : I18nModel public ModInfoModel(ModLoader loader) { SourcePath.Value = loader.Path.FullName; - Id.Value = loader.Name; - var imagePath = Path.Combine(loader.Path.FullName, "icon.png"); - if (File.Exists(imagePath)) - ModImage.Value = Utils.LoadImageToStream(imagePath); + Name.Value = loader.Name; + Description.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"); + if (File.Exists(imagePath)) + ModImage.Value = Utils.LoadImageToStream(imagePath); foreach (var food in loader.Foods) Foods.Add(new(food)); foreach (var clickText in loader.ClickTexts) @@ -61,6 +64,77 @@ public class ModInfoModel : I18nModel 点击文本: {ClickTexts.Count} 低状态文本: {LowTexts.Count}"; } + + public const string ModInfoFile = "info.lps"; + + public void Save() + { + SaveTo(SourcePath.Value); + } + + public void SaveTo(string path) + { + var modInfoFile = Path.Combine(path, ModInfoFile); + if (File.Exists(modInfoFile) is false) + File.Create(modInfoFile).Close(); + //var lps = new LpsDocument(File.ReadAllText(modInfoFile)); + var lps = new LPS() + { + new Line("vupmod", Name.Value) + { + new Sub("author", Author.Value), + new Sub("gamever", GameVersion.Value), + new Sub("ver", ModVersion.Value) + }, + new Line("authorid", "0"), + new Line("itemid", "0"), + new Line("cachedate", DateTime.Now.Date.ToString()) + }; + //lps.FindLine("vupmod").Info = Name.Value; + //lps.FindLine("intro").Info = Description.Value; + //lps.FindSub("gamever").Info = GameVersion.Value; + //lps.FindSub("ver").Info = ModVersion.Value; + //lps.FindSub("author").Info = Author.Value; + //lps.FindorAddLine("authorid").InfoToInt64 = 0; + //lps.FindorAddLine("itemid").info = "0"; + File.WriteAllText(modInfoFile, lps.ToString()); + SaveFoods(path); + SaveLang(path); + } + + public void SaveFoods(string path) + { + if (Foods.Count == 0) + return; + var foodPath = Path.Combine(path, "food"); + Directory.CreateDirectory(foodPath); + var foodFile = Path.Combine(foodPath, "food.lps"); + if (File.Exists(foodFile) is false) + File.Create(foodFile).Close(); + var lps = new LPS(); + foreach (var food in Foods) + lps.Add(LPSConvert.SerializeObjectToLine(food.ToFood(), "food")); + File.WriteAllText(foodFile, lps.ToString()); + } + + public void SaveLang(string path) + { + var langPath = Path.Combine(path, "lang"); + Directory.CreateDirectory(langPath); + foreach (var cultureName in I18nHelper.Current.CultureNames) + { + var culturePath = Path.Combine(langPath, cultureName); + Directory.CreateDirectory(culturePath); + var cultureFile = Path.Combine(culturePath, $"{cultureName}.lps"); + File.Create(cultureFile).Close(); + var lps = new LPS(); + foreach (var food in Foods) + { + lps.Add(new Line(food.Name, food.I18nDatas[cultureName].Name.Value)); + lps.Add(new Line(food.Description, food.I18nDatas[cultureName].Description.Value)); + } + } + } } public class I18nModInfoModel diff --git a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs index f27d062..6a51128 100644 --- a/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModEdit/ModEditWindowVM.cs @@ -12,6 +12,7 @@ using System.Collections.Specialized; using System.ComponentModel; using VPet.ModMaker.Views.ModEdit; using System.Windows; +using System.IO; namespace VPet.ModMaker.ViewModels.ModEdit; @@ -176,6 +177,17 @@ public class ModEditWindowVM private void SaveTo() { + SaveFileDialog saveFileDialog = + new() + { + Title = "保存 模组信息文件,并在文件夹内保存模组数据", + Filter = $"LPS文件|*.lps;", + DefaultExt = "info.lps" + }; + if (saveFileDialog.ShowDialog() is true) + { + ModInfo.Value.SaveTo(Path.GetDirectoryName(saveFileDialog.FileName)); + } return; } } diff --git a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs index e94de03..66e4006 100644 --- a/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs +++ b/VPet.ModMaker/ViewModels/ModMakerWindowVM.cs @@ -56,7 +56,7 @@ public class ModMakerWindowVM if (string.IsNullOrEmpty(value)) ShowMods = Mods; else - ShowMods = new(Mods.Where(i => i.Id.Value.Contains(value))); + ShowMods = new(Mods.Where(i => i.Name.Value.Contains(value))); } public void CreateNewMod() diff --git a/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml b/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml index af1a592..389fc6a 100644 --- a/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml +++ b/VPet.ModMaker/Views/ModEdit/ModEditWindow.xaml @@ -241,8 +241,14 @@ -