Load up to 1000 emotes
This commit is contained in:
+17
-6
@@ -15,6 +15,9 @@ public static class EmoteCache
|
|||||||
{
|
{
|
||||||
[JsonPropertyName("emote")]
|
[JsonPropertyName("emote")]
|
||||||
public Emote Emote { get; set; }
|
public Emote Emote { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("id")]
|
||||||
|
public string Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct Emote
|
public struct Emote
|
||||||
@@ -29,7 +32,7 @@ public static class EmoteCache
|
|||||||
public bool Animated { get; set; }
|
public bool Animated { get; set; }
|
||||||
};
|
};
|
||||||
|
|
||||||
private enum LoadingState
|
public enum LoadingState
|
||||||
{
|
{
|
||||||
Unloaded,
|
Unloaded,
|
||||||
Loading,
|
Loading,
|
||||||
@@ -39,12 +42,13 @@ public static class EmoteCache
|
|||||||
private const string BetterTTV = "https://api.betterttv.net/3";
|
private const string BetterTTV = "https://api.betterttv.net/3";
|
||||||
private const string GlobalEmotes = $"{BetterTTV}/cached/emotes/global";
|
private const string GlobalEmotes = $"{BetterTTV}/cached/emotes/global";
|
||||||
private const string Top100Emotes = $"{BetterTTV}/emotes/shared/top?limit=100";
|
private const string Top100Emotes = $"{BetterTTV}/emotes/shared/top?limit=100";
|
||||||
|
private const string Top100BeforeEmotes = "{0}/emotes/shared/top?before={1}&limit=100";
|
||||||
private const string EmotePath = "https://cdn.betterttv.net/emote/{0}/3x";
|
private const string EmotePath = "https://cdn.betterttv.net/emote/{0}/3x";
|
||||||
|
|
||||||
private static readonly HttpClient Client = new();
|
private static readonly HttpClient Client = new();
|
||||||
|
|
||||||
// All of this data is uninitalized while State is not `LoadingState.Done`
|
// All of this data is uninitalized while State is not `LoadingState.Done`
|
||||||
private static LoadingState State = LoadingState.Unloaded;
|
public static LoadingState State = LoadingState.Unloaded;
|
||||||
private static Dictionary<string, IEmote> EmoteImages = new();
|
private static Dictionary<string, IEmote> EmoteImages = new();
|
||||||
|
|
||||||
private static Dictionary<string, Emote> Cache = new();
|
private static Dictionary<string, Emote> Cache = new();
|
||||||
@@ -65,11 +69,18 @@ public static class EmoteCache
|
|||||||
foreach (var emote in JsonSerializer.Deserialize<Emote[]>(globalList)!)
|
foreach (var emote in JsonSerializer.Deserialize<Emote[]>(globalList)!)
|
||||||
Cache.TryAdd(emote.Code, emote);
|
Cache.TryAdd(emote.Code, emote);
|
||||||
|
|
||||||
var top = await Client.GetAsync(Top100Emotes);
|
var lastId = string.Empty;
|
||||||
var topList = await top.Content.ReadAsStringAsync();
|
for (var i = 0; i < 10; i++)
|
||||||
|
{
|
||||||
|
var top = await Client.GetAsync(lastId == string.Empty ? Top100Emotes : Top100BeforeEmotes.Format(BetterTTV, lastId));
|
||||||
|
var topList = await top.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
foreach (var emote in JsonSerializer.Deserialize<List<Top100>>(topList)!)
|
var jsonList = JsonSerializer.Deserialize<List<Top100>>(topList)!;
|
||||||
Cache.TryAdd(emote.Emote.Code, emote.Emote);
|
foreach (var emote in jsonList)
|
||||||
|
Cache.TryAdd(emote.Emote.Code, emote.Emote);
|
||||||
|
|
||||||
|
lastId = jsonList.Last().Id;
|
||||||
|
}
|
||||||
|
|
||||||
EmoteCodeArray = Cache.Keys.ToArray();
|
EmoteCodeArray = Cache.Keys.ToArray();
|
||||||
State = LoadingState.Done;
|
State = LoadingState.Done;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Numerics;
|
|||||||
using ChatTwo.Resources;
|
using ChatTwo.Resources;
|
||||||
using ChatTwo.Util;
|
using ChatTwo.Util;
|
||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Utility.Raii;
|
using Dalamud.Interface.Utility.Raii;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
|
||||||
@@ -44,26 +45,41 @@ internal sealed class Emote : ISettingsTab
|
|||||||
if (SearchSelector.SelectorPopup("WordAddPopup", out var newWord, WordPopupOptions))
|
if (SearchSelector.SelectorPopup("WordAddPopup", out var newWord, WordPopupOptions))
|
||||||
Mutable.BlockedEmotes.Add(newWord);
|
Mutable.BlockedEmotes.Add(newWord);
|
||||||
|
|
||||||
using var table = ImRaii.Table("##BlockedWords", 2, ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersInner);
|
using(var table = ImRaii.Table("##BlockedWords", 2, ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersInner))
|
||||||
if (table)
|
|
||||||
{
|
{
|
||||||
ImGui.TableSetupColumn(Language.Options_Emote_EmoteTable);
|
if (table)
|
||||||
ImGui.TableSetupColumn("##Del", 0, 0.07f);
|
|
||||||
|
|
||||||
ImGui.TableHeadersRow();
|
|
||||||
|
|
||||||
var copiedList = Mutable.BlockedEmotes.ToArray();
|
|
||||||
foreach (var word in copiedList)
|
|
||||||
{
|
{
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableSetupColumn(Language.Options_Emote_EmoteTable);
|
||||||
ImGui.TextUnformatted(word);
|
ImGui.TableSetupColumn("##Del", 0, 0.07f);
|
||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableHeadersRow();
|
||||||
if (ImGuiUtil.Button($"##{word}Del", FontAwesomeIcon.Trash, !ImGui.GetIO().KeyCtrl))
|
|
||||||
Mutable.BlockedEmotes.Remove(word);
|
var copiedList = Mutable.BlockedEmotes.ToArray();
|
||||||
|
foreach (var word in copiedList)
|
||||||
|
{
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
ImGui.TextUnformatted(word);
|
||||||
|
|
||||||
|
ImGui.TableNextColumn();
|
||||||
|
if (ImGuiUtil.Button($"##{word}Del", FontAwesomeIcon.Trash, !ImGui.GetIO().KeyCtrl))
|
||||||
|
Mutable.BlockedEmotes.Remove(word);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.Spacing();
|
||||||
|
ImGui.Separator();
|
||||||
|
ImGui.Spacing();
|
||||||
|
|
||||||
|
if (EmoteCache.State is EmoteCache.LoadingState.Done)
|
||||||
|
ImGui.TextColored(ImGuiColors.HealerGreen, "Ready");
|
||||||
|
else
|
||||||
|
ImGui.TextColored(ImGuiColors.DPSRed, "Not Ready");
|
||||||
|
|
||||||
|
ImGui.TextUnformatted($"Emotes loaded: {EmoteCache.EmoteCodeArray.Length}");
|
||||||
|
foreach (var word in EmoteCache.EmoteCodeArray)
|
||||||
|
ImGui.TextUnformatted(word);
|
||||||
|
|
||||||
ImGui.PopTextWrapPos();
|
ImGui.PopTextWrapPos();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user