mirror of
https://github.com/LorisYounger/VPet.ModMaker.git
synced 2024-08-30 18:22:21 +00:00
修复宠物Id重复问题
This commit is contained in:
parent
4e9ed4630c
commit
ea3a8f0cac
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user