use of com.glitchcog.fontificator.emoji.loader.betterttv.BttvEmote in project ChatGameFontificator by GlitchCog.
the class EmojiParser method parseBetterTtvEmoteJson.
/**
* Parse emotes loaded using the BetterTTV emote API
*
* @param emoji
* @param jsonData
* @param isGlobal
* Whether the BetterTTV emotes to be loaded are the BetterTTV global emotes
* @throws IOException
*/
private void parseBetterTtvEmoteJson(TypedEmojiMap emoji, String jsonData, boolean isGlobal) throws IOException {
JsonParser jp = new JsonParser();
JsonObject root = jp.parse(jsonData).getAsJsonObject();
if (root.get("emotes").isJsonNull()) {
logBox.log("Unable to load Better TTV global emotes");
return;
}
Gson gson = new Gson();
Type emoteType = new TypeToken<BttvEmote[]>() {
}.getType();
final String urlTemplate = "https:" + root.get("urlTemplate").getAsString().replace("{{image}}", "2x");
BttvEmote[] bttvEmotes = gson.fromJson(root.get("emotes").getAsJsonArray(), emoteType);
int bttvCount = 0;
for (BttvEmote be : bttvEmotes) {
LazyLoadEmoji lle = new LazyLoadEmoji(be.getCode(), urlTemplate.replace("{{id}}", be.getId()), isGlobal ? EmojiType.BETTER_TTV_GLOBAL : EmojiType.BETTER_TTV_CHANNEL);
lle.setAnimatedGif(AnimatedGifUtil.GIF_EXTENSION.equals(be.getImageType()));
emoji.put(be.getCode(), lle);
bttvCount++;
}
logBox.log(bttvCount + " Better TTV emote" + (bttvCount == 1 ? "" : "s") + " found");
}
Aggregations