diff --git a/Anamnesis/Actor/Pages/PosePage.xaml b/Anamnesis/Actor/Pages/PosePage.xaml index cfd485de1..2beae8c58 100644 --- a/Anamnesis/Actor/Pages/PosePage.xaml +++ b/Anamnesis/Actor/Pages/PosePage.xaml @@ -57,9 +57,15 @@ - + (); await Add(); await Add(); + await Add(); IsInitialized = true; diff --git a/Anamnesis/Services/CustomBoneNameService.cs b/Anamnesis/Services/CustomBoneNameService.cs new file mode 100644 index 000000000..640b5726d --- /dev/null +++ b/Anamnesis/Services/CustomBoneNameService.cs @@ -0,0 +1,77 @@ +// © Anamnesis. +// Licensed under the MIT license. +namespace Anamnesis.Services; + +using System; +using System.IO; +using System.Collections.Generic; +using System.Threading.Tasks; +using Anamnesis.Files; +using Anamnesis.Serialization; + +public class CustomBoneNameService : ServiceBase +{ + private static readonly string SavePath = FileService.ParseToFilePath(FileService.StoreDirectory + "/CustomBoneNames.json"); + private static Dictionary customBoneNames = new Dictionary(); + + public static string? GetBoneName(string bone) + { + if (customBoneNames.TryGetValue(bone, out var customName)) + return customName; + return null; + } + + public static void SetBoneName(string bone, string? customName) + { + if (customBoneNames.ContainsKey(bone)) + { + if (string.IsNullOrEmpty(customName)) + { + customBoneNames.Remove(bone); + } + else + { + customBoneNames[bone] = customName; + } + } + else + { + if (string.IsNullOrEmpty(customName)) + return; + customBoneNames.Add(bone, customName); + } + + Save(); + } + + public static void Save() + { + string json = SerializerService.Serialize(customBoneNames); + File.WriteAllText(SavePath, json); + } + + public override async Task Initialize() + { + await base.Initialize(); + try + { + if (File.Exists(SavePath)) + { + string json = File.ReadAllText(SavePath); + customBoneNames = SerializerService.Deserialize>(json); + } + } + catch (Exception ex) + { + Log.Warning(ex, "Failed to load custom bone names."); + customBoneNames = new Dictionary(); + Save(); + } + } + + public override Task Shutdown() + { + Save(); + return base.Shutdown(); + } +}