mirror-chatterino2/src/providers/twitch/TwitchEmotes.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

104 lines
2.4 KiB
C++
Raw Normal View History

#pragma once
#include "common/Aliases.hpp"
#include "common/UniqueAccess.hpp"
#include "providers/twitch/TwitchUser.hpp"
#include <boost/unordered/unordered_flat_map_fwd.hpp>
2018-08-13 13:54:39 +02:00
#include <QColor>
#include <QRegularExpression>
2018-08-02 14:23:27 +02:00
#include <QString>
#include <memory>
#include <unordered_map>
namespace chatterino {
// NB: "default" can be replaced with "static" to always get a non-animated
// variant
/// %1 <-> {id}
/// %2 <-> {scale} (1.0, 2.0, 3.0)
constexpr QStringView TWITCH_EMOTE_TEMPLATE =
u"https://static-cdn.jtvnw.net/emoticons/v2/%1/default/dark/%2";
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
2018-08-13 13:54:39 +02:00
struct CheerEmote {
QColor color;
int minBits;
QRegularExpression regex;
2018-08-13 13:54:39 +02:00
EmotePtr animatedEmote;
EmotePtr staticEmote;
};
struct CheerEmoteSet {
QRegularExpression regex;
std::vector<CheerEmote> cheerEmotes;
};
struct TwitchEmoteSet {
/// @brief The owner of this set
///
/// This owner might not be resolved yet
std::shared_ptr<TwitchUser> owner;
std::vector<EmotePtr> emotes;
/// If this is a bitstier emote set
bool isBits = false;
/// @brief If this emote set is a subscriber or similar emote set
///
/// This includes sub and bit emotes
bool isSubLike = false;
/// @brief The title of this set
///
/// We generate this based on the emote set's flags & owner
QString title() const;
};
using TwitchEmoteSetMap = boost::unordered_flat_map<EmoteSetId, TwitchEmoteSet>;
struct HelixChannelEmote;
constexpr QStringView TWITCH_SUB_EMOTE_SET_PREFIX = u"x-c2-s-";
constexpr QStringView TWITCH_BIT_EMOTE_SET_PREFIX = u"x-c2-b-";
struct TwitchEmoteSetMeta {
QString setID;
/// See TwitchEmoteSet::isBits
bool isBits = false;
/// See TwitchEmoteSet::isSubLike
bool isSubLike = false;
};
TwitchEmoteSetMeta getTwitchEmoteSetMeta(const HelixChannelEmote &emote);
2022-11-05 11:04:35 +01:00
class ITwitchEmotes
{
public:
virtual ~ITwitchEmotes() = default;
virtual EmotePtr getOrCreateEmote(const EmoteId &id,
const EmoteName &name) = 0;
};
class TwitchEmotes : public ITwitchEmotes
{
public:
static QString cleanUpEmoteCode(const QString &dirtyEmoteCode);
2022-11-05 11:04:35 +01:00
TwitchEmotes() = default;
2022-11-05 11:04:35 +01:00
EmotePtr getOrCreateEmote(const EmoteId &id,
const EmoteName &name) override;
private:
2018-08-02 14:23:27 +02:00
UniqueAccess<std::unordered_map<EmoteId, std::weak_ptr<Emote>>>
twitchEmotesCache_;
};
} // namespace chatterino