-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathEmoteIdentifier.cs
85 lines (67 loc) · 3.2 KB
/
EmoteIdentifier.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
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using Dalamud.Utility;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using Lumina.Excel.Sheets;
using Newtonsoft.Json;
namespace SimpleHeels;
public unsafe record EmoteIdentifier([property: JsonProperty("e")] uint EmoteModeId, [property: JsonProperty("c")] byte CPoseState) {
public virtual bool Equals(EmoteIdentifier? other) => other != null && EmoteModeId == other.EmoteModeId && CPoseState == other.CPoseState;
public override int GetHashCode() => HashCode.Combine(EmoteModeId, CPoseState);
public static Lazy<List<EmoteIdentifier>> EmoteList = new(() => {
var l = new List<EmoteIdentifier>();
foreach (var emoteMode in PluginService.Data.GetExcelSheet<EmoteMode>()!) {
if (emoteMode.RowId == 0 || emoteMode.StartEmote.RowId == 0) continue;
for (byte i = 0; i < emoteMode.RowId switch { 1 => 4, 2 => 5, 3 => 3, _ => 1 }; i++) l.Add(new EmoteIdentifier(emoteMode.RowId, i));
}
return l;
});
public static IReadOnlyList<EmoteIdentifier> List => EmoteList.Value;
private static readonly Dictionary<uint, string> Names = new();
private static readonly Dictionary<uint, uint> Icons = new() {
[3] = 64013 // Sleep -> Doze
};
private static string FetchName(uint emoteModeId) {
var emoteMode = PluginService.Data.GetExcelSheet<EmoteMode>()?.GetRow(emoteModeId);
if (emoteMode == null) return $"EmoteMode#{emoteModeId}";
var emote = emoteMode.Value.StartEmote;
if (!emote.IsValid || emote.RowId == 0) return $"EmoteMode#{emoteModeId}";
return emote.Value.Name.ExtractText();
}
private static uint FetchIcon(uint emoteModeId) {
var emoteMode = PluginService.Data.GetExcelSheet<EmoteMode>()?.GetRow(emoteModeId);
if (emoteMode == null) return 0;
var emote = emoteMode.Value.StartEmote;
if (!emote.IsValid || emote.RowId == 0) return 0;
return emote.Value.Icon;
}
[Newtonsoft.Json.JsonIgnore]
public string EmoteName {
get {
if (Names.TryGetValue(EmoteModeId, out var name)) return name;
name = FetchName(EmoteModeId);
Names.TryAdd(EmoteModeId, name);
return name;
}
}
[Newtonsoft.Json.JsonIgnore] public string Name => EmoteModeId is 1 or 2 or 3 ? $"{EmoteName} Pose {CPoseState + 1}" : EmoteName;
[Newtonsoft.Json.JsonIgnore]
public uint Icon {
get {
if (Icons.TryGetValue(EmoteModeId, out var icon)) return icon;
icon = FetchIcon(EmoteModeId);
Icons.TryAdd(EmoteModeId, icon);
return icon;
}
}
public static EmoteIdentifier? Get(Character* character) {
if (character == null) return null;
if (character->Mode is not (CharacterModes.InPositionLoop or CharacterModes.EmoteLoop)) return null;
return new EmoteIdentifier(character->ModeParam, character->EmoteController.CPoseState);
}
public static bool TryGet(Character* character, [NotNullWhen(true)] out EmoteIdentifier? emoteIdentifier) {
emoteIdentifier = Get(character);
return emoteIdentifier != null;
}
}