forked from XIV-Tools/CustomizePlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSkeletonService.cs
78 lines (65 loc) · 1.71 KB
/
SkeletonService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// © Anamnesis.
// Developed by W and A Walsh.
// Licensed under the MIT license.
namespace Anamnesis.PoseModule
{
using System;
using System.Collections.Generic;
using System.IO;
using Anamnesis.Memory;
using Anamnesis.Posing.Templates;
using Anamnesis.Serialization;
public static class SkeletonService
{
private static List<SkeletonFile> skeletonFiles = new List<SkeletonFile>();
public static void LoadSkeletons()
{
string[] templates = Directory.GetFiles("Data/Skeletons/", "*.json");
foreach (string templatePath in templates)
{
Load(templatePath);
}
}
public static SkeletonFile? GetSkeletonFile(Appearance customize)
{
int maxDepth = int.MinValue;
SkeletonFile? maxSkel = null;
foreach (SkeletonFile template in skeletonFiles)
{
if (template.IsValid(customize))
{
if (template.Depth > maxDepth)
{
maxDepth = template.Depth;
maxSkel = template;
}
}
}
if (maxSkel != null)
return maxSkel;
return null;
}
private static SkeletonFile Load(string path)
{
SkeletonFile template = SerializerService.DeserializeFile<SkeletonFile>(path);
skeletonFiles.Add(template);
if (template.BasedOn != null)
{
SkeletonFile baseTemplate = Load("Data/Skeletons/" + template.BasedOn);
template.CopyBaseValues(baseTemplate);
}
// Validate that all bone names are unique
if (template.BoneNames != null)
{
HashSet<string> boneNames = new HashSet<string>();
foreach ((string orignal, string name) in template.BoneNames)
{
if (boneNames.Contains(name))
throw new Exception($"Duplicate bone name: {name} in skeleton file: {path}");
boneNames.Add(name);
}
}
return template;
}
}
}