fix: replace defines with constexpr/const and use more absolute paths for includes (#5527)

bye bye nuuls
This commit is contained in:
nerix
2024-08-03 12:00:58 +02:00
committed by GitHub
parent 5ee5abf5b2
commit aed55ac1ba
83 changed files with 386 additions and 380 deletions
+15 -6
View File
@@ -1,8 +1,18 @@
#include "ChannelPointReward.hpp"
#include "providers/twitch/ChannelPointReward.hpp"
#include "common/QLogging.hpp"
#include "messages/Image.hpp"
#include <QStringBuilder>
namespace {
QString twitchChannelPointRewardUrl(const QString &file)
{
return u"https://static-cdn.jtvnw.net/custom-reward-images/default-" % file;
}
} // namespace
namespace chatterino {
ChannelPointReward::ChannelPointReward(const QJsonObject &redemption)
@@ -94,11 +104,10 @@ ChannelPointReward::ChannelPointReward(const QJsonObject &redemption)
else
{
static const ImageSet defaultImage{
Image::fromUrl({TWITCH_CHANNEL_POINT_REWARD_URL("1.png")}, 1,
baseSize),
Image::fromUrl({TWITCH_CHANNEL_POINT_REWARD_URL("2.png")}, 0.5,
Image::fromUrl({twitchChannelPointRewardUrl("1.png")}, 1, baseSize),
Image::fromUrl({twitchChannelPointRewardUrl("2.png")}, 0.5,
baseSize * 2),
Image::fromUrl({TWITCH_CHANNEL_POINT_REWARD_URL("4.png")}, 0.25,
Image::fromUrl({twitchChannelPointRewardUrl("4.png")}, 0.25,
baseSize * 4)};
this->image = defaultImage;
}
+1 -5
View File
@@ -1,15 +1,11 @@
#pragma once
#include "common/Aliases.hpp"
#include "messages/ImageSet.hpp"
#include <QJsonObject>
#define TWITCH_CHANNEL_POINT_REWARD_URL(x) \
QString("https://static-cdn.jtvnw.net/custom-reward-images/default-%1") \
.arg(x)
namespace chatterino {
struct ChannelPointReward {
ChannelPointReward(const QJsonObject &redemption);
ChannelPointReward() = delete;
+1 -3
View File
@@ -11,9 +11,7 @@ using namespace chatterino;
Url getEmoteLink(const EmoteId &id, const QString &emoteScale)
{
return {QString(TWITCH_EMOTE_TEMPLATE)
.replace("{id}", id.string)
.replace("{scale}", emoteScale)};
return {TWITCH_EMOTE_TEMPLATE.arg(id.string, emoteScale)};
}
QSize getEmoteExpectedBaseSize(const EmoteId &id)
+6 -3
View File
@@ -10,12 +10,15 @@
#include <memory>
#include <unordered_map>
namespace chatterino {
// NB: "default" can be replaced with "static" to always get a non-animated
// variant
#define TWITCH_EMOTE_TEMPLATE \
"https://static-cdn.jtvnw.net/emoticons/v2/{id}/default/dark/{scale}"
/// %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";
namespace chatterino {
struct Emote;
using EmotePtr = std::shared_ptr<const Emote>;
+1 -3
View File
@@ -276,9 +276,7 @@ struct HelixChannelEmote {
, name(jsonObject.value("name").toString())
, type(jsonObject.value("emote_type").toString())
, setId(jsonObject.value("emote_set_id").toString())
, url(QString(TWITCH_EMOTE_TEMPLATE)
.replace("{id}", this->emoteId)
.replace("{scale}", "3.0"))
, url(TWITCH_EMOTE_TEMPLATE.arg(this->emoteId, u"3.0"))
{
}
};