mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-30 22:16:14 +00:00
Keep first game sticker frames inside the binary.
This commit is contained in:
@@ -23,6 +23,8 @@ namespace Stickers {
|
||||
const QString DicePacks::kDiceString = QString::fromUtf8("\xF0\x9F\x8E\xB2");
|
||||
const QString DicePacks::kDartString = QString::fromUtf8("\xF0\x9F\x8E\xAF");
|
||||
const QString DicePacks::kSlotString = QString::fromUtf8("\xF0\x9F\x8E\xB0");
|
||||
const QString DicePacks::kFballString = QString::fromUtf8("\xE2\x9A\xBD");
|
||||
const QString DicePacks::kBballString = QString::fromUtf8("\xF0\x9F\x8F\x80");
|
||||
|
||||
DicePack::DicePack(not_null<Main::Session*> session, const QString &emoji)
|
||||
: _session(session)
|
||||
@@ -56,15 +58,15 @@ void DicePack::load() {
|
||||
}
|
||||
|
||||
void DicePack::applySet(const MTPDmessages_stickerSet &data) {
|
||||
_map.clear();
|
||||
auto documents = base::flat_map<DocumentId, not_null<DocumentData*>>();
|
||||
const auto isSlotMachine = DicePacks::IsSlot(_emoji);
|
||||
auto index = 0;
|
||||
auto documents = base::flat_map<DocumentId, not_null<DocumentData*>>();
|
||||
for (const auto &sticker : data.vdocuments().v) {
|
||||
const auto document = _session->data().processDocument(
|
||||
sticker);
|
||||
if (document->sticker()) {
|
||||
if (isSlotMachine) {
|
||||
_map.emplace(_map.size(), document);
|
||||
_map.emplace(index++, document);
|
||||
} else {
|
||||
documents.emplace(document->id, document);
|
||||
}
|
||||
@@ -98,14 +100,25 @@ void DicePack::tryGenerateLocalZero() {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto path = (_emoji == DicePacks::kDiceString)
|
||||
? qsl(":/gui/art/dice_idle.tgs")
|
||||
: (_emoji == DicePacks::kDartString)
|
||||
? qsl(":/gui/art/dart_idle.tgs")
|
||||
: QString();
|
||||
if (path.isEmpty()) {
|
||||
return;
|
||||
if (_emoji == DicePacks::kDiceString) {
|
||||
generateLocal(0, u"dice_idle"_q);
|
||||
} else if (_emoji == DicePacks::kDartString) {
|
||||
generateLocal(0, u"dart_idle"_q);
|
||||
} else if (_emoji == DicePacks::kBballString) {
|
||||
generateLocal(0, u"bball_idle"_q);
|
||||
} else if (_emoji == DicePacks::kFballString) {
|
||||
generateLocal(0, u"fball_idle"_q);
|
||||
} else if (_emoji == DicePacks::kSlotString) {
|
||||
generateLocal(0, u"slot_back"_q);
|
||||
generateLocal(2, u"slot_pull"_q);
|
||||
generateLocal(8, u"slot_0_idle"_q);
|
||||
generateLocal(14, u"slot_1_idle"_q);
|
||||
generateLocal(20, u"slot_2_idle"_q);
|
||||
}
|
||||
}
|
||||
|
||||
void DicePack::generateLocal(int index, const QString &name) {
|
||||
const auto path = u":/gui/art/"_q + name + u".tgs"_q;
|
||||
auto task = FileLoadTask(
|
||||
_session,
|
||||
path,
|
||||
@@ -114,15 +127,15 @@ void DicePack::tryGenerateLocalZero() {
|
||||
SendMediaType::File,
|
||||
FileLoadTo(0, {}, 0),
|
||||
{});
|
||||
task.process();
|
||||
task.process({ .generateGoodThumbnail = false });
|
||||
const auto result = task.peekResult();
|
||||
Assert(result != nullptr);
|
||||
const auto document = _session->data().processDocument(
|
||||
result->document,
|
||||
Images::FromImageInMemory(result->thumb, "PNG"));
|
||||
Images::FromImageInMemory(result->thumb, "WEBP", result->thumbbytes));
|
||||
document->setLocation(Core::FileLocation(path));
|
||||
|
||||
_map.emplace(0, document);
|
||||
_map.emplace(index, document);
|
||||
|
||||
Ensures(document->sticker());
|
||||
Ensures(document->sticker()->animated);
|
||||
@@ -132,13 +145,16 @@ DicePacks::DicePacks(not_null<Main::Session*> session) : _session(session) {
|
||||
}
|
||||
|
||||
DocumentData *DicePacks::lookup(const QString &emoji, int value) {
|
||||
const auto i = _packs.find(emoji);
|
||||
const auto key = emoji.endsWith(QChar(0xFE0F))
|
||||
? emoji.mid(0, emoji.size() - 1)
|
||||
: emoji;
|
||||
const auto i = _packs.find(key);
|
||||
if (i != end(_packs)) {
|
||||
return i->second->lookup(value);
|
||||
}
|
||||
return _packs.emplace(
|
||||
emoji,
|
||||
std::make_unique<DicePack>(_session, emoji)
|
||||
key,
|
||||
std::make_unique<DicePack>(_session, key)
|
||||
).first->second->lookup(value);
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,7 @@ private:
|
||||
void load();
|
||||
void applySet(const MTPDmessages_stickerSet &data);
|
||||
void tryGenerateLocalZero();
|
||||
void generateLocal(int index, const QString &name);
|
||||
|
||||
const not_null<Main::Session*> _session;
|
||||
QString _emoji;
|
||||
@@ -42,6 +43,8 @@ public:
|
||||
static const QString kDiceString;
|
||||
static const QString kDartString;
|
||||
static const QString kSlotString;
|
||||
static const QString kFballString;
|
||||
static const QString kBballString;
|
||||
|
||||
[[nodiscard]] static bool IsSlot(const QString &emoji) {
|
||||
return (emoji == kSlotString);
|
||||
|
Reference in New Issue
Block a user