use of com.glitchcog.fontificator.emoji.loader.frankerfacez.FfzEmote in project ChatGameFontificator by GlitchCog.
the class EmojiParser method parseFrankerFaceZEmoteJson.
/**
* Parse emotes loaded using the FrankerFaceZ emote API
*
* @param emoji
* @param jsonData
* @param isGlobal
* Whether the FFZ emotes to be loaded are the FFZ global emotes
* @throws IOException
*/
private void parseFrankerFaceZEmoteJson(TypedEmojiMap emoji, String jsonData, boolean isGlobal) throws IOException {
JsonParser jp = new JsonParser();
JsonObject root = jp.parse(jsonData).getAsJsonObject();
if (root.get("error") != null) {
String errorMessage = "Unable to load FrankerFaceZ emotes";
if (!root.get("message").isJsonNull()) {
errorMessage += ": " + root.get("message");
}
logBox.log(errorMessage);
return;
} else if (root.get("sets").isJsonNull() || (isGlobal && root.get("default_sets").isJsonNull())) {
logBox.log("Unable to load FrankerFaceZ global emotes");
return;
}
List<String> setsToLoad;
if (isGlobal) {
setsToLoad = new ArrayList<String>();
JsonArray defaultSetsArray = root.get("default_sets").getAsJsonArray();
for (int i = 0; i < defaultSetsArray.size(); i++) {
setsToLoad.add(defaultSetsArray.get(i).getAsString());
}
} else {
setsToLoad = null;
}
JsonObject sets = root.get("sets").getAsJsonObject();
Gson gson = new Gson();
Type emoteType = new TypeToken<FfzEmote[]>() {
}.getType();
int frankerCount = 0;
int eMultiCount = 0;
List<String> setNames = new ArrayList<String>();
for (Map.Entry<String, JsonElement> entry : sets.entrySet()) {
setNames.add(entry.getKey());
JsonElement emoteElement = entry.getValue().getAsJsonObject().get("emoticons");
FfzEmote[] jsonEmoteObjects = gson.fromJson(emoteElement, emoteType);
for (FfzEmote e : jsonEmoteObjects) {
LazyLoadEmoji lle = null;
for (String key : e.getUrls().keySet()) {
lle = new LazyLoadEmoji(e.getName(), "http:" + e.getUrls().get(key), e.getWidth(), e.getHeight(), isGlobal ? EmojiType.FRANKERFACEZ_GLOBAL : EmojiType.FRANKERFACEZ_CHANNEL);
break;
}
if (e.getUrls().size() > 1) {
eMultiCount++;
}
emoji.put(e.getName(), lle);
frankerCount++;
}
}
String allSets = "";
for (int n = 0; n < setNames.size(); n++) {
allSets += (n == 0 ? "" : ", ") + setNames.get(n);
}
logBox.log(setNames.size() + " FrankerFaceZ set" + (setNames.size() == 1 ? "" : "s") + " found: {" + allSets + "}");
logBox.log(frankerCount + " FrankerFaceZ emote" + (frankerCount == 1 ? "" : "s") + " loaded (" + eMultiCount + " multi-image emote" + (eMultiCount == 1 ? "" : "s") + ")");
}
Aggregations