修复宠物Id重复问题

This commit is contained in:
Hakoyu 2023-11-01 18:33:03 +08:00
parent 4e9ed4630c
commit ea3a8f0cac
4 changed files with 30 additions and 5 deletions

View File

@ -53,7 +53,8 @@ public class ModMaker : MainPlugin
foreach (var pet in MW.Pets)
{
var petModel = new PetModel();
petModel.Id.Value = pet.Name;
petModel.SourceId = pet.Name;
petModel.Id.Value = pet.Name + " (来自本体)".Translate();
ModMakerInfo.Pets.Add(petModel);
}
//Maker.ModMaker = this;

View File

@ -32,5 +32,8 @@ public static class ModMakerInfo
/// </summary>
public static int GameVersion { get; set; } = 100;
/// <summary>
/// 本体的宠物
/// </summary>
public static List<PetModel> Pets { get; } = new();
}

View File

@ -96,7 +96,7 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
/// <summary>
/// 宠物
/// </summary>
public ObservableCollection<PetModel> Pets { get; } = new(ModMakerInfo.Pets);
public ObservableCollection<PetModel> Pets { get; } = new();
/// <summary>
/// 其它I18n数据
@ -139,15 +139,25 @@ public class ModInfoModel : I18nModel<I18nModInfoModel>
LowTexts.Add(new(lowText));
foreach (var selectText in loader.SelectTexts)
SelectTexts.Add(new(selectText));
// 缓存pets
var pets = new List<PetModel>();
foreach (var pet in loader.Pets)
{
var petModel = new PetModel(pet);
Pets.Add(petModel);
pets.Add(petModel);
foreach (var p in pet.path)
{
LoadAnime(petModel, p);
}
}
// 先载入本体宠物
foreach (var pet in ModMakerInfo.Pets)
{
// 确保Id不重复
if (pets.All(i => i.Id.Value != pet.SourceId))
Pets.Add(pet);
}
// 再载入模组宠物
foreach (var pet in pets)
Pets.Add(pet);
foreach (var lang in loader.I18nDatas)
I18nDatas.Add(lang.Key, lang.Value);

View File

@ -1,6 +1,7 @@
using HKW.HKWViewModels.SimpleObservable;
using LinePutScript;
using LinePutScript.Converter;
using LinePutScript.Localization.WPF;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -20,6 +21,11 @@ namespace VPet.ModMaker.Models;
/// </summary>
public class PetModel : I18nModel<I18nPetInfoModel>
{
/// <summary>
/// 显示的Id 若不为空则判断为来自本体的宠物
/// </summary>
public string? SourceId { get; set; } = null;
/// <summary>
/// Id
/// </summary>
@ -92,6 +98,7 @@ public class PetModel : I18nModel<I18nPetInfoModel>
public PetModel()
{
PetNameId.Value = $"{Id.Value}_{nameof(PetNameId)}";
DescriptionId.Value = $"{Id.Value}_{nameof(DescriptionId)}";
Id.ValueChanged += (o, n) =>
{
@ -208,6 +215,8 @@ public class PetModel : I18nModel<I18nPetInfoModel>
/// <param name="path">路径</param>
public void Save(string path)
{
if (SourceId is not null)
Id.Value = SourceId;
if (IsSimplePetModel)
{
SaveSimplePetInfo(path);
@ -242,6 +251,8 @@ public class PetModel : I18nModel<I18nPetInfoModel>
anime.Save(petAnimePath);
foreach (var anime in FoodAnimes)
anime.Save(petAnimePath);
if (SourceId is not null)
Id.Value = SourceId + " (来自本体)".Translate();
}
private void SaveSimplePetInfo(string path)