mirror-chatterino2/emotes.cpp

66 lines
1.9 KiB
C++
Raw Normal View History

2017-01-04 15:12:31 +01:00
#include "emotes.h"
2017-01-13 18:59:11 +01:00
#include "resources.h"
2017-01-04 15:12:31 +01:00
2017-01-13 18:59:11 +01:00
QString Emotes::m_twitchEmoteTemplate(
2017-01-17 00:42:32 +01:00
"https://static-cdn.jtvnw.net/emoticons/v1/{id}/{scale}.0");
2017-01-04 15:12:31 +01:00
2017-01-13 18:59:11 +01:00
ConcurrentMap<QString, TwitchEmoteValue *> Emotes::m_twitchEmotes;
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_bttvEmotes;
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_ffzEmotes;
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_chatterinoEmotes;
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_bttvChannelEmoteFromCaches;
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_ffzChannelEmoteFromCaches;
ConcurrentMap<long, LazyLoadedImage *> Emotes::m_twitchEmoteFromCache;
ConcurrentMap<QString, LazyLoadedImage *> Emotes::m_miscImageFromCache;
2017-01-05 20:49:33 +01:00
2017-01-15 16:38:30 +01:00
int Emotes::m_generation = 0;
2017-01-05 16:07:20 +01:00
Emotes::Emotes()
{
}
2017-01-04 15:12:31 +01:00
2017-01-11 18:52:09 +01:00
LazyLoadedImage *
Emotes::getTwitchEmoteById(const QString &name, long id)
2017-01-06 23:28:48 +01:00
{
2017-01-13 18:59:11 +01:00
return m_twitchEmoteFromCache.getOrAdd(id, [&name, id] {
qreal scale;
QString url = getTwitchEmoteLink(id, scale);
return new LazyLoadedImage(url, scale, name, name + "\nTwitch Emote");
});
}
QString
Emotes::getTwitchEmoteLink(long id, qreal &scale)
{
scale = .5;
return m_twitchEmoteTemplate.replace("{id}", QString::number(id))
.replace("{scale}", "2");
2017-01-06 23:28:48 +01:00
}
2017-01-11 18:52:09 +01:00
LazyLoadedImage *
Emotes::getCheerImage(long long amount, bool animated)
2017-01-05 16:07:20 +01:00
{
// TODO: fix this xD
2017-01-05 20:49:33 +01:00
return getCheerBadge(amount);
}
2017-01-04 15:12:31 +01:00
2017-01-11 18:52:09 +01:00
LazyLoadedImage *
Emotes::getCheerBadge(long long amount)
2017-01-05 20:49:33 +01:00
{
2017-01-11 18:52:09 +01:00
if (amount >= 100000) {
2017-01-13 18:59:11 +01:00
return Resources::cheerBadge100000();
2017-01-11 18:52:09 +01:00
} else if (amount >= 10000) {
2017-01-13 18:59:11 +01:00
return Resources::cheerBadge10000();
2017-01-11 18:52:09 +01:00
} else if (amount >= 5000) {
2017-01-13 18:59:11 +01:00
return Resources::cheerBadge5000();
2017-01-11 18:52:09 +01:00
} else if (amount >= 1000) {
2017-01-13 18:59:11 +01:00
return Resources::cheerBadge1000();
2017-01-11 18:52:09 +01:00
} else if (amount >= 100) {
2017-01-13 18:59:11 +01:00
return Resources::cheerBadge100();
2017-01-11 18:52:09 +01:00
} else {
2017-01-13 18:59:11 +01:00
return Resources::cheerBadge1();
2017-01-05 20:49:33 +01:00
}
2017-01-04 15:12:31 +01:00
}