From 5bc5b7c29a65f6073cb574b2fc9d30d777c030e7 Mon Sep 17 00:00:00 2001 From: Hakoyu Date: Thu, 4 Jan 2024 15:44:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20lps=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C=E6=89=80=E5=B8=A6=E6=9D=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VPet.ModMaker/Models/ModLoader.cs | 5 + VPet.ModMaker/Models/ModModel/FoodModel.cs | 2 +- VPet.ModMaker/Models/ModModel/ModInfoModel.cs | 133 +++++++++++------- .../Models/ModModel/SelectTextModel.cs | 2 +- 4 files changed, 93 insertions(+), 49 deletions(-) diff --git a/VPet.ModMaker/Models/ModLoader.cs b/VPet.ModMaker/Models/ModLoader.cs index 289371f..2525c94 100644 --- a/VPet.ModMaker/Models/ModLoader.cs +++ b/VPet.ModMaker/Models/ModLoader.cs @@ -149,7 +149,10 @@ public class ModLoader { var name = lps.First().Info; var pet = new PetLoader(lps, di); + if (pet.Name is null) + break; Pets.Add(pet); + // ! : 此方法会导致 LoadImageToStream 无法使用 //var graphCore = new GraphCore(0); //foreach (var p in pet.path) @@ -166,6 +169,8 @@ public class ModLoader foreach (ILine li in tmp) { var food = LPSConvert.DeserializeObject(li); + if (food.Name is null) + break; var imagePath = $"{path.FullName}\\image\\food\\{(string.IsNullOrWhiteSpace(food.Image) ? food.Name : food.Image)}.png"; if (File.Exists(imagePath)) diff --git a/VPet.ModMaker/Models/ModModel/FoodModel.cs b/VPet.ModMaker/Models/ModModel/FoodModel.cs index 9d617f9..4a91f81 100644 --- a/VPet.ModMaker/Models/ModModel/FoodModel.cs +++ b/VPet.ModMaker/Models/ModModel/FoodModel.cs @@ -140,8 +140,8 @@ public class FoodModel : I18nModel public FoodModel(Food food) : this() { - DescriptionId.Value = food.Desc; Id.Value = food.Name; + DescriptionId.Value = food.Desc; Graph.Value = food.Graph; Type.Value = food.Type; Strength.Value = food.Strength; diff --git a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs index 12de44a..984ba32 100644 --- a/VPet.ModMaker/Models/ModModel/ModInfoModel.cs +++ b/VPet.ModMaker/Models/ModModel/ModInfoModel.cs @@ -230,7 +230,8 @@ public class ModInfoModel : I18nModel I18nDatas.Add(lang.Key, lang.Value); OtherI18nDatas = loader.OtherI18nDatas; - LoadI18nData(); + LoadI18nDatas(); + RefreshAllId(); RefreshId(); } @@ -332,7 +333,7 @@ public class ModInfoModel : I18nModel /// /// 加载本地化数据 /// - private void LoadI18nData() + private void LoadI18nDatas() { foreach (var lang in I18nDatas.Keys.Union(OtherI18nDatas.Keys)) { @@ -344,55 +345,93 @@ public class ModInfoModel : I18nModel I18nHelper.Current.CultureName.Value = I18nHelper.Current.CultureNames.First(); foreach (var i18nData in OtherI18nDatas) { - foreach (var food in Foods) + LoadFoodI18nData(i18nData.Key, i18nData.Value); + LoadLowTextI18nData(i18nData.Key, i18nData.Value); + LoadClickTextI18nData(i18nData.Key, i18nData.Value); + LoadSelectTextI18nData(i18nData.Key, i18nData.Value); + LoadPetI18nData(i18nData.Key, i18nData.Value); + } + } + + private void LoadFoodI18nData(string key, Dictionary i18nData) + { + foreach (var food in Foods) + { + if (food.I18nDatas.TryGetValue(key, out var data) is false) + continue; + if (i18nData.TryGetValue(food.Id.Value, out var name)) + data.Name.Value = name; + if (i18nData.TryGetValue(food.DescriptionId.Value, out var description)) + data.Description.Value = description; + } + } + + private void LoadLowTextI18nData(string key, Dictionary i18nData) + { + foreach (var lowText in LowTexts) + { + if (lowText.I18nDatas.TryGetValue(key, out var data) is false) + continue; + if (i18nData.TryGetValue(lowText.Id.Value, out var text)) + data.Text.Value = text; + } + } + + private void LoadClickTextI18nData(string key, Dictionary i18nData) + { + foreach (var clickText in ClickTexts) + { + if (clickText.I18nDatas.TryGetValue(key, out var data) is false) + continue; + if (i18nData.TryGetValue(clickText.Id.Value, out var text)) + data.Text.Value = text; + } + } + + private void LoadSelectTextI18nData(string key, Dictionary i18nData) + { + foreach (var selectText in SelectTexts) + { + if (selectText.I18nDatas.TryGetValue(key, out var data) is false) + continue; + if (i18nData.TryGetValue(selectText.Id.Value, out var text)) + data.Text.Value = text; + if (i18nData.TryGetValue(selectText.ChooseId.Value, out var choose)) + data.Choose.Value = choose; + } + } + + private void LoadPetI18nData(string key, Dictionary i18nData) + { + foreach (var pet in Pets) + { + if (pet.I18nDatas.TryGetValue(key, out var data) is false) + continue; + if (i18nData.TryGetValue(pet.Id.Value, out var name)) + data.Name.Value = name; + if (i18nData.TryGetValue(pet.PetNameId.Value, out var petName)) + data.PetName.Value = petName; + if (i18nData.TryGetValue(pet.DescriptionId.Value, out var description)) + data.Description.Value = description; + foreach (var work in pet.Works) { - var foodI18n = food.I18nDatas[i18nData.Key]; - if (i18nData.Value.TryGetValue(food.Id.Value, out var name)) - foodI18n.Name.Value = name; - if (i18nData.Value.TryGetValue(food.DescriptionId.Value, out var description)) - foodI18n.Description.Value = description; - food.RefreshId(); - } - foreach (var lowText in LowTexts) - { - var lowTextI18n = lowText.I18nDatas[i18nData.Key]; - if (i18nData.Value.TryGetValue(lowText.Id.Value, out var text)) - lowTextI18n.Text.Value = text; - } - foreach (var clickText in ClickTexts) - { - var clickTextI18n = clickText.I18nDatas[i18nData.Key]; - if (i18nData.Value.TryGetValue(clickText.Id.Value, out var text)) - clickTextI18n.Text.Value = text; - } - foreach (var selectText in SelectTexts) - { - var selectTextI18n = selectText.I18nDatas[i18nData.Key]; - if (i18nData.Value.TryGetValue(selectText.Id.Value, out var text)) - selectTextI18n.Text.Value = text; - if (i18nData.Value.TryGetValue(selectText.ChooseId.Value, out var choose)) - selectTextI18n.Choose.Value = choose; - selectText.RefreshId(); - } - foreach (var pet in Pets) - { - var petI18n = pet.I18nDatas[i18nData.Key]; - if (i18nData.Value.TryGetValue(pet.Id.Value, out var name)) - petI18n.Name.Value = name; - if (i18nData.Value.TryGetValue(pet.PetNameId.Value, out var petName)) - petI18n.PetName.Value = petName; - if (i18nData.Value.TryGetValue(pet.DescriptionId.Value, out var description)) - petI18n.Description.Value = description; - pet.RefreshId(); - foreach (var work in pet.Works) - { - var workI18n = work.I18nDatas[i18nData.Key]; - if (i18nData.Value.TryGetValue(work.Id.Value, out var workName)) - workI18n.Name.Value = workName; - } + if (work.I18nDatas.TryGetValue(key, out var workData) is false) + continue; + if (i18nData.TryGetValue(work.Id.Value, out var workName)) + workData.Name.Value = workName; } } } + + private void RefreshAllId() + { + foreach (var food in Foods) + food.RefreshId(); + foreach (var selectText in SelectTexts) + selectText.RefreshId(); + foreach (var pet in Pets) + pet.RefreshId(); + } #endregion #region Save /// diff --git a/VPet.ModMaker/Models/ModModel/SelectTextModel.cs b/VPet.ModMaker/Models/ModModel/SelectTextModel.cs index e745f94..13ca7e4 100644 --- a/VPet.ModMaker/Models/ModModel/SelectTextModel.cs +++ b/VPet.ModMaker/Models/ModModel/SelectTextModel.cs @@ -125,8 +125,8 @@ public class SelectTextModel : I18nModel public SelectTextModel(SelectText text) : this() { - ChooseId.Value = text.Choose ?? string.Empty; Id.Value = text.Text; + ChooseId.Value = text.Choose ?? string.Empty; Mode.EnumValue.Value = text.Mode; Tags.Value = text.Tags is null ? string.Empty : string.Join(", ", text.Tags); ToTags.Value = text.ToTags is null ? string.Empty : string.Join(", ", text.ToTags);