From fd9732dcfa681bf5dac454d3e1bdc611e331bdc9 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 15 Oct 2020 15:59:51 +0300 Subject: [PATCH] Add slot machine support. GitOrigin-RevId: e0c3c5d9b2cff2870162f11983bd546aba101caf --- td/generate/scheme/td_api.tl | 20 +++++++++++-- td/generate/scheme/td_api.tlo | Bin 183264 -> 183624 bytes td/telegram/MessageContent.cpp | 4 +-- td/telegram/StickersManager.cpp | 50 ++++++++++++++++++++++++++------ td/telegram/StickersManager.h | 2 +- 5 files changed, 61 insertions(+), 15 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index c519e7985..5d4f40e8d 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1589,12 +1589,12 @@ messageVenue venue:venue = MessageContent; messageContact contact:contact = MessageContent; //@description A dice message. The dice value is randomly generated by the server -//@initial_state_sticker The animated sticker with the initial dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known -//@final_state_sticker The animated sticker with the final dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known +//@initial_state The animated stickers with the initial dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known +//@final_state The animated stickers with the final dice animation; may be null if unknown. updateMessageContent will be sent when the sticker became known //@emoji Emoji on which the dice throw animation is based //@value The dice value. If the value is 0, the dice don't have final state yet //@success_animation_frame_number Number of frame after which a success animation like a shower of confetti needs to be shown on updateMessageSendSucceeded -messageDice initial_state_sticker:sticker final_state_sticker:sticker emoji:string value:int32 success_animation_frame_number:int32 = MessageContent; +messageDice initial_state:DiceStickers final_state:DiceStickers emoji:string value:int32 success_animation_frame_number:int32 = MessageContent; //@description A message with a game @game The game description messageGame game:game = MessageContent; @@ -2066,6 +2066,20 @@ phoneNumberAuthenticationSettings allow_flash_call:Bool is_current_phone_number: animations animations:vector = Animations; +//@class DiceStickers @description Contains animated stickers which should be used for dice animation rendering + +//@description A regular animated sticker @sticker The animated sticker with the dice animation +diceStickersRegular sticker:sticker = DiceStickers; + +//@description Animated stickers to be combined into a slot machine +//@background The animated sticker with the slot machine background +//@lever The animated sticker with the lever animation +//@left_reel The animated sticker with the left reel +//@center_reel The animated sticker with the center reel +//@right_reel The animated sticker with the right reel +diceStickersSlotMachine background:sticker lever:sticker left_reel:sticker center_reel:sticker right_reel:sticker = DiceStickers; + + //@description Represents the result of an ImportContacts request @user_ids User identifiers of the imported contacts in the same order as they were specified in the request; 0 if the contact is not yet a registered user //@importer_count The number of users that imported the corresponding contact; 0 for already registered users or if unavailable importedContacts user_ids:vector importer_count:vector = ImportedContacts; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 15383020dd984cda9bcdc194370befceb9d37786..9bd0aed157cdd9454b2dfc4cd49d3076373aa1aa 100644 GIT binary patch delta 1425 zcmaJ=Ur19?826j5rkneto8Gy*zxtp!Xn}!A!OHaqGFs`w9t2zKx~=B2yIYhfF0j~x z4~-L@s2SJ2(3kKdo~eBbY!o5Sjb zhw9pmNBg=eq|fra_Mg^p;rv*a#up87y+Sl}nd1{EU1`axbQ3jIrrEQ9vvMzQ)=eY2-SdbTcV1H7<;+P3Ec-R1{10qIG`fRJ|&rHsIZKHdD4DcKmqlh}h#RZNpVnkEJ zN5c_GgmSOgDzR%;c#^tQT;#qM0>uJ*y}%;Jsvf7b&`O{eT4*7aLjW(zt?98_N6CN= z9E2RzfuB@M1*}@kM;u#$oZfb{_(f{bqo?{|JqSeqO%E*$)r+z4-Fw`s!*||@7;Z68 z$Mz7VQ%mfWf%aqS%Ju6ju#&e9MoG0*z)BNWBE#!;oa+XCaaW<9?mAU3+p7{CSvrFm zBPD%CX-t&a@Q|*LDTL>Z;29UUkze{j{?<|T5SK^#o3?vD*%z(RCA=c-{9y53eE||ex3L3EC1GE!j#SE=G5}i$Q z0!<%l#*#J2t5+|=Jq`UIks5WAQ8$_44QJv8a zDS}PeC2VfV4iO;WAt$(Z&n)Sr%V(T)@O%l=yTC`f1YGnu&j57bmoA#hA6J>5Z?2;m amZz1)KLMxTf_={Y4g!oEc)A9iKmP-?{q3*- delta 1212 zcmaJ>U1(Ba81}UmHnkm{=FglSe_)PIc!HoY46PaN!i%6?crnPsGCAeOQW?T*8AR>U zIJGaz3j;3-q6i7S@WN<}U39UFx(KALi0C51sEc3)9sSOCGGU&J!{_rn@ALkA?{V|K zdIzbsA0PN871CpUuH8LUIX-k_aR0f~Q&XjGSv5hZa^_efRryuUT^eYk3Up;s8AgpE zpgJny>qz-1VWL?JU zQ{eA$is`{)ZkO|JLmz3EpPD+rs7~H|*~U;&PwX0cV6oj#5j#jC_MuZ(;Y5#TVYr{? zYmx1W*RFsMc?~d)-7^N#O3?sWjG2w33cnF@7^}n**?(9`#tJp14K*KwM$>)!Yc}xi zy&6H0m9G)dZ7YOvf_mSu-y(~3>`_wO?5KpTu}W$C*9nBg{-QV_V((fUK-?zyF!99R zuh6gmg$dmD7>)`#$Osn$U=!F|28=&)kPX~&kPVE`M4O{w73)+^VB`U)&~+M?QR6#g z5$l3QEGfHy*?WRtT-_5C{@fiC3JK{BBW^OLtQ$hut>Gp`wA_%ySj^MsQ>zv|@aCcP WXY=6|II4FxAZqSJR$K2O`t2{CQiP!Z diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 1224acf25..8b3ac7d0e 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4539,9 +4539,9 @@ tl_object_ptr get_message_content_object(const MessageCo } case MessageContentType::Dice: { const MessageDice *m = static_cast(content); - auto initial_state = td->stickers_manager_->get_dice_sticker_object(m->emoji, 0); + auto initial_state = td->stickers_manager_->get_dice_stickers_object(m->emoji, 0); auto final_state = - m->dice_value == 0 ? nullptr : td->stickers_manager_->get_dice_sticker_object(m->emoji, m->dice_value); + m->dice_value == 0 ? nullptr : td->stickers_manager_->get_dice_stickers_object(m->emoji, m->dice_value); auto success_animation_frame_number = td->stickers_manager_->get_dice_success_animation_frame_number(m->emoji, m->dice_value); return make_tl_object(std::move(initial_state), std::move(final_state), m->emoji, diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 818cdb243..7b1783f94 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -1163,7 +1163,8 @@ void StickersManager::init() { animated_emoji_sticker_set.short_name_); } - dice_emojis_str_ = G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️"); + dice_emojis_str_ = + G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️\x01🎰"); dice_emojis_ = full_split(dice_emojis_str_, '\x01'); for (auto &dice_emoji : dice_emojis_) { auto &animated_dice_sticker_set = add_special_sticker_set(SpecialStickerSetType::animated_dice(dice_emoji)); @@ -1373,7 +1374,7 @@ tl_object_ptr StickersManager::get_stickers_object(const vecto return result; } -tl_object_ptr StickersManager::get_dice_sticker_object(const string &emoji, int32 value) const { +tl_object_ptr StickersManager::get_dice_stickers_object(const string &emoji, int32 value) const { if (td_->auth_manager_->is_bot()) { return nullptr; } @@ -1387,12 +1388,42 @@ tl_object_ptr StickersManager::get_dice_sticker_object(const st } auto sticker_set_id = it->second.id_; - if (sticker_set_id.is_valid()) { - auto sticker_set = get_sticker_set(sticker_set_id); - CHECK(sticker_set != nullptr); - if (sticker_set->was_loaded && value >= 0 && value < static_cast(sticker_set->sticker_ids.size())) { - return get_sticker_object(sticker_set->sticker_ids[value]); + if (!sticker_set_id.is_valid()) { + return nullptr; + } + + auto sticker_set = get_sticker_set(sticker_set_id); + CHECK(sticker_set != nullptr); + if (!sticker_set->was_loaded) { + return nullptr; + } + + auto get_sticker = [&](int32 value) { + return get_sticker_object(sticker_set->sticker_ids[value]); + }; + + if (emoji == "🎰") { + if (sticker_set->sticker_ids.size() < 21 || value < 0 || value > 64) { + return nullptr; } + + int32 background_id = value == 64 ? 1 : 0; + int32 lever_id = 2; + int32 left_reel_id = value == 64 ? 3 : 8; + int32 center_reel_id = value == 64 ? 9 : 14; + int32 right_reel_id = value == 64 ? 15 : 20; + if (value != 0 && value != 64) { + left_reel_id = 4 + (value % 4); + center_reel_id = 10 + ((value + 3) / 4 % 4); + right_reel_id = 16 + ((value + 15) / 16 % 4); + } + return td_api::make_object(get_sticker(background_id), get_sticker(lever_id), + get_sticker(left_reel_id), get_sticker(center_reel_id), + get_sticker(right_reel_id)); + } + + if (value >= 0 && value < static_cast(sticker_set->sticker_ids.size())) { + return td_api::make_object(get_sticker(value)); } return nullptr; } @@ -3447,7 +3478,8 @@ void StickersManager::on_update_dice_emojis() { return; } - auto dice_emojis_str = G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️"); + auto dice_emojis_str = + G()->shared_config().get_option_string("dice_emojis", "🎲\x01🎯\x01🏀\x01⚽\x01⚽️\x01🎰"); if (dice_emojis_str == dice_emojis_str_) { return; } @@ -3482,7 +3514,7 @@ void StickersManager::on_update_dice_success_values() { } auto dice_success_values_str = - G()->shared_config().get_option_string("dice_success_values", "0,6:62,5:110,5:110,5:110"); + G()->shared_config().get_option_string("dice_success_values", "0,6:62,5:110,5:110,5:110,64:110"); if (dice_success_values_str == dice_success_values_str_) { return; } diff --git a/td/telegram/StickersManager.h b/td/telegram/StickersManager.h index a4b42a428..fc985f6a4 100644 --- a/td/telegram/StickersManager.h +++ b/td/telegram/StickersManager.h @@ -53,7 +53,7 @@ class StickersManager : public Actor { tl_object_ptr get_stickers_object(const vector &sticker_ids) const; - tl_object_ptr get_dice_sticker_object(const string &emoji, int32 value) const; + tl_object_ptr get_dice_stickers_object(const string &emoji, int32 value) const; int32 get_dice_success_animation_frame_number(const string &emoji, int32 value) const;